'module1
option explicit
public declare function setwindowlong lib "user32" alias "setwindowlonga" (byval hwnd as long, byval nindex as long, byval dwnewlong as long) as long
public declare function callwindowproc lib "user32" alias "callwindowproca" (byval lpprevwndfunc as long, byval hwnd as long, byval umsg as long, byval wparam as long, byval lparam as long) as long
public declare function getprop lib "user32" alias "getpropa" (byval hwnd as long, byval lpstring as string) as long
public declare function setprop lib "user32" alias "setpropa" (byval hwnd as long, byval lpstring as string, byval hdata as long) as long
public declare function removeprop lib "user32" alias "removepropa" (byval hwnd as long, byval lpstring as string) as long
public const gwl_wndproc = (-4&)
public const wm_windowposchanging = &h46&
public type windowpos
hwnd as long
hwndinsertafter as long
x as long
y as long
cx as long
cy as long
flags as long
end type
public const hwnd_bottom = &h1&
public declare sub copymemory lib "kernel32" alias "rtlmovememory" (destination as any, source as any, byval length as long)
public function winpropbag_procaddress(byval hwnd as long, byval fstorevalue as boolean, optional byval lprocaddress as long = 0, optional byval fremoveprop as boolean = false) as long
if fstorevalue then
'保存属性
setprop hwnd, "my_winprop_procaddress", lprocaddress
else
'取出属性
winpropbag_procaddress = getprop(hwnd, "my_winprop_procaddress")
if fremoveprop then
'删除属性
removeprop hwnd, "my_winprop_procaddress"
end if
end if
end function
public sub subclassing(byval hwndtarget as long, optional byval funsubclassing as boolean = false)
if funsubclassing then
winpropbag_procaddress hwndtarget, true, setwindowlong(hwndtarget, gwl_wndproc, addressof mywindowproc)
else
setwindowlong hwndtarget, gwl_wndproc, winpropbag_procaddress(hwnd:=hwndtarget, fstorevalue:=false, fremoveprop:=true)
end if
end sub
public function mywindowproc(byval hwnd as long, byval umsg as long, byval wparam as long, byval lparam as long) as long
if umsg = wm_windowposchanging then
'可以这样写
dim ut as windowpos
copymemory ut, byval lparam, len(ut)
ut.hwndinsertafter = hwnd_bottom
copymemory byval lparam, ut, len(ut)
'也可以这接这样写
'copymemory byval lparam + 4, hwnd_bottom, 4
end if
mywindowproc = callwindowproc(winpropbag_procaddress(hwnd, false), hwnd, umsg, wparam, lparam)
end function
'form1
private sub form_load()
subclassing me.hwnd, true
end sub
private sub form_unload(cancel as integer)
subclassing me.hwnd, false
end sub
注册会员,创建你的web开发资料库,