本帖最后由 tubaba 于 2023-10-18 14:23 编辑
注册一个窗口处理程序来处理发生的指定消息
#include
#include
#include
#include
#include
#region ### start koda gui section ### form=
$form1 = guicreate("form1", 357, 167)
$label1 = guictrlcreatelabel("mousehover test", 112, 72, 112, 17)
global $hlabel_callback = dllcallbackregister("_label_callbackfunc", "int", "hwnd;uint;wparam;lparam")
global $hoform_label_callback = _winapi_setwindowlong(guictrlgethandle($label1), 0xfffffffc, dllcallbackgetptr($hlabel_callback))
guisetstate(@sw_show)
#endregion ### end koda gui section ###
while 1
$nmsg = guigetmsg()
switch $nmsg
case $gui_event_close
exit
endswitch
wend
func _label_callbackfunc($hwnd, $imsg, $iwparam, $ilparam)
#forceref $hwnd, $imsg, $iwparam, $ilparam
local $ictrl = _winapi_getdlgctrlid($hwnd)
local const $tme_hover = 0x00000001
local const $tme_leave = 0x00000002
switch $ictrl
case $label1
switch $imsg
case $wm_mousehover ;鼠标悬停
case $wm_mouseleave ;鼠标离开
case $wm_mousemove ;鼠标移动
__trackmouseevent($hwnd, bitor($tme_hover, $tme_leave), 1) ;//mouseleave|mousehover消息由此函数触发
local static $n
$n =1
consolewrite('@@ debug(' & @scriptlinenumber & ') : $n = ' & $n & @crlf & '>error code: ' & @error & ' extended code: ' & @extended & ' (0x' & hex(@extended) & ') systemtime: ' & @hour & ':' & @min & ':' & @sec & @crlf) ;### debug console
case $wm_setcursor ;设置光标
guictrlsetcursor($ictrl, 0)
case $wm_lbuttondown
endswitch
return _winapi_callwindowproc($hoform_label_callback, $hwnd, $imsg, $iwparam, $ilparam)
endswitch
endfunc ;==>_label_callbackfunc
func __trackmouseevent($hwnd, $iflags, $itime = -1)
local $ttme = dllstructcreate('dword;dword;hwnd;dword')
dllstructsetdata($ttme, 1, dllstructgetsize($ttme))
dllstructsetdata($ttme, 2, $iflags)
dllstructsetdata($ttme, 3, $hwnd)
dllstructsetdata($ttme, 4, $itime)
local $aret = dllcall('user32.dll', 'bool', 'trackmouseevent', 'struct*', $ttme)
if @error then return seterror(@error, @extended, 0)
return $aret[0]
endfunc ;==>__trackmouseevent
|