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
——————————————————————————–
例子一:任何一個(gè)控件(只要有窗口,這是我們的前提,下同),你可以在運(yùn)行時(shí)隨便更改它的大小。 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;設(shè)置第二個(gè)參數(shù)為false取消這種設(shè)置,下同
——————————————————————————–
例子二:任何一個(gè)控件,我們都可以控制其顯示風(fēng)格為對(duì)話框的風(fēng)格。
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
——————————————————————————–
例子三:任何一個(gè)控件,我們都可以控制其顯示風(fēng)格為模式對(duì)話框的風(fēng)格
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
——————————————————————————–
例子四:任何一個(gè)控件,我們都可以給它加上標(biāo)題欄,通過(guò)拖動(dòng)標(biāo)題欄,可以實(shí)現(xiàn)控件的運(yùn)行時(shí)移動(dòng)。
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
——————————————————————————–
例子五:任何一個(gè)控件,我們都可以給它加上controlbox(所謂controlbox,就是窗體的圖標(biāo)+最小化+最大化+關(guān)閉按鈕)。
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
用法:controlcaption picture1,true:controlsysmenu picture1,true