对话框解决控制策略秘密
时间:2023-10-21 20:03:42 静子
api申报和变量定义可能需要在例子中使用,变量声明private declare function getwindowlong lib “user32″ alias “getwindowlonga” (
api申报和变量定义可能需要在例子中使用,变量声明
private declare function getwindowlong lib “user32″ alias “getwindowlonga” (byval hwnd as long, byval nindex as long) as long
private declare function setwindowlong lib “user32″ alias “setwindowlonga” (byval hwnd as long, byval nindex as long, byval dwnewlong as long) as long
private declare function setwindowpos lib “user32″ (byval hwnd as long, byval hwndinsertafter as long, byval x as long, byval y as long, byval cx as long, byval cy as long, byval wflags as long) as long
private const swp_nosize = &h1
private const swp_nozorder = &h4
private const swp_nomove = &h2
private const swp_drawframe = &h20
private const gwl_style = (-16)
private const ws_thickframe = &h40000
private const ws_dlgframe = &h400000
private const ws_popup = &h80000000
private const ws_caption = &hc00000
private const ws_sysmenu = &h80000
private const ws_minimizebox = &h20000
private const ws_maximizebox = &h10000
private const ws_minimize = &h20000000
private const ws_maximize = &h1000000
——————————————————————————–
例1:任何控制(只要有对话框,这是我们的先决条件,相同),您可以在操作过程中随意更改其尺寸。 private sub controlsize(controlname as control, settrue as boolean)
dim dwstyle as long
dwstyle = getwindowlong(controlname.hwnd, gwl_style)
if settrue then
dwstyle = dwstyle or ws_thickframe
else
dwstyle = dwstyle – ws_thickframe
end if
dwstyle = setwindowlong(controlname.hwnd, gwl_style, dwstyle)
setwindowpos controlname.hwnd, controlname.parent.hwnd, 0, 0, 0, 0, swp_nozorder or swp_nosize or swp_nomove or swp_drawframe
end sub
使用方法:controlsize picture1,true;将第二个主要参数设置为false撤销,相同
——————————————————————————–
例2:任何控制,我们都可以控制其表示设计风格为提示框的设计风格。
private sub controldialog(controlname as control, settrue as boolean)
dim dwstyle as long
dwstyle = getwindowlong(controlname.hwnd, gwl_style)
if settrue then
dwstyle = dwstyle or ws_dlgframe
else
dwstyle = dwstyle – ws_dlgframe
end if
dwstyle = setwindowlong(controlname.hwnd, gwl_style, dwstyle)
setwindowpos controlname.hwnd, controlname.parent.hwnd, 0, 0, 0, 0, swp_nozorder or swp_nosize or swp_nomove or swp_drawframe
end sub
使用方法:controlsize picture1,true
——————————————————————————–
例3:任何控制,我们都可以控制其表示设计风格作为方式提示框的设计风格
private sub controlmodal(controlname as control, settrue as boolean)
dim dwstyle as long
dwstyle = getwindowlong(controlname.hwnd, gwl_style)
if settrue then
dwstyle = dwstyle or ws_popup
else
dwstyle = dwstyle – ws_popup
end if
dwstyle = setwindowlong(controlname.hwnd, gwl_style, dwstyle)
setwindowpos controlname.hwnd, controlname.parent.hwnd, 0, 0, 0, 0, swp_nozorder or swp_nosize or swp_nomove or swp_drawframe
end sub
使用方法:controlmodal picture1,true
——————————————————————————–
例四:任何一种控制,每个人都可以给它添加一个菜单栏,根据拖动菜单栏,可以实现控制运行中的移动。
private sub controlcaption(controlname as control, settrue as boolean) dim dwstyle as long
dwstyle = getwindowlong(controlname.hwnd, gwl_style)
if settrue then
dwstyle = dwstyle or ws_caption
else
dwstyle = dwstyle – ws_caption
end if
dwstyle = setwindowlong(controlname.hwnd, gwl_style, dwstyle)
setwindowpos controlname.hwnd, controlname.parent.hwnd, 0, 0, 0, 0, swp_nozorder or swp_nosize or swp_nomove or swp_drawframe
end sub
使用方法:controlcaption picture1,true
——————————————————————————–
例5:每个人都可以在任何控制中添加controlbox(controlbox是文本框的图标+降到最低+更大化+关闭按钮)。
private sub controlsysmenu(controlname as control, settrue as boolean)
dim dwstyle as long
dwstyle = getwindowlong(controlname.hwnd, gwl_style)
if settrue then
dwstyle = dwstyle or ws_sysmenu
else
dwstyle = dwstyle – ws_sysmenu
end if
dwstyle = setwindowlong(controlname.hwnd, gwl_style, dwstyle)
setwindowpos controlname.hwnd, controlname.parent.hwnd, 0, 0, 0, 0, swp_nozorder or swp_nosize or swp_nomove or swp_drawframe
end sub
private declare function getwindowlong lib “user32″ alias “getwindowlonga” (byval hwnd as long, byval nindex as long) as long
private declare function setwindowlong lib “user32″ alias “setwindowlonga” (byval hwnd as long, byval nindex as long, byval dwnewlong as long) as long
private declare function setwindowpos lib “user32″ (byval hwnd as long, byval hwndinsertafter as long, byval x as long, byval y as long, byval cx as long, byval cy as long, byval wflags as long) as long
private const swp_nosize = &h1
private const swp_nozorder = &h4
private const swp_nomove = &h2
private const swp_drawframe = &h20
private const gwl_style = (-16)
private const ws_thickframe = &h40000
private const ws_dlgframe = &h400000
private const ws_popup = &h80000000
private const ws_caption = &hc00000
private const ws_sysmenu = &h80000
private const ws_minimizebox = &h20000
private const ws_maximizebox = &h10000
private const ws_minimize = &h20000000
private const ws_maximize = &h1000000
——————————————————————————–
例1:任何控制(只要有对话框,这是我们的先决条件,相同),您可以在操作过程中随意更改其尺寸。 private sub controlsize(controlname as control, settrue as boolean)
dim dwstyle as long
dwstyle = getwindowlong(controlname.hwnd, gwl_style)
if settrue then
dwstyle = dwstyle or ws_thickframe
else
dwstyle = dwstyle – ws_thickframe
end if
dwstyle = setwindowlong(controlname.hwnd, gwl_style, dwstyle)
setwindowpos controlname.hwnd, controlname.parent.hwnd, 0, 0, 0, 0, swp_nozorder or swp_nosize or swp_nomove or swp_drawframe
end sub
使用方法:controlsize picture1,true;将第二个主要参数设置为false撤销,相同
——————————————————————————–
例2:任何控制,我们都可以控制其表示设计风格为提示框的设计风格。
private sub controldialog(controlname as control, settrue as boolean)
dim dwstyle as long
dwstyle = getwindowlong(controlname.hwnd, gwl_style)
if settrue then
dwstyle = dwstyle or ws_dlgframe
else
dwstyle = dwstyle – ws_dlgframe
end if
dwstyle = setwindowlong(controlname.hwnd, gwl_style, dwstyle)
setwindowpos controlname.hwnd, controlname.parent.hwnd, 0, 0, 0, 0, swp_nozorder or swp_nosize or swp_nomove or swp_drawframe
end sub
使用方法:controlsize picture1,true
——————————————————————————–
例3:任何控制,我们都可以控制其表示设计风格作为方式提示框的设计风格
private sub controlmodal(controlname as control, settrue as boolean)
dim dwstyle as long
dwstyle = getwindowlong(controlname.hwnd, gwl_style)
if settrue then
dwstyle = dwstyle or ws_popup
else
dwstyle = dwstyle – ws_popup
end if
dwstyle = setwindowlong(controlname.hwnd, gwl_style, dwstyle)
setwindowpos controlname.hwnd, controlname.parent.hwnd, 0, 0, 0, 0, swp_nozorder or swp_nosize or swp_nomove or swp_drawframe
end sub
使用方法:controlmodal picture1,true
——————————————————————————–
例四:任何一种控制,每个人都可以给它添加一个菜单栏,根据拖动菜单栏,可以实现控制运行中的移动。
private sub controlcaption(controlname as control, settrue as boolean) dim dwstyle as long
dwstyle = getwindowlong(controlname.hwnd, gwl_style)
if settrue then
dwstyle = dwstyle or ws_caption
else
dwstyle = dwstyle – ws_caption
end if
dwstyle = setwindowlong(controlname.hwnd, gwl_style, dwstyle)
setwindowpos controlname.hwnd, controlname.parent.hwnd, 0, 0, 0, 0, swp_nozorder or swp_nosize or swp_nomove or swp_drawframe
end sub
使用方法:controlcaption picture1,true
——————————————————————————–
例5:每个人都可以在任何控制中添加controlbox(controlbox是文本框的图标+降到最低+更大化+关闭按钮)。
private sub controlsysmenu(controlname as control, settrue as boolean)
dim dwstyle as long
dwstyle = getwindowlong(controlname.hwnd, gwl_style)
if settrue then
dwstyle = dwstyle or ws_sysmenu
else
dwstyle = dwstyle – ws_sysmenu
end if
dwstyle = setwindowlong(controlname.hwnd, gwl_style, dwstyle)
setwindowpos controlname.hwnd, controlname.parent.hwnd, 0, 0, 0, 0, swp_nozorder or swp_nosize or swp_nomove or swp_drawframe
end sub