时间: 2021-07-31 作者:daque
固然form有activate与deactivate的events,然而这两个events只对form的focus是在 同一个process各别form之间的切换灵验,即使咱们在form1,而click其余的process, 则form1并不会爆发deactivate的events,沟通的,由其余的process 回到form1时,也 不会爆发activate的events。独一能得悉的便是透过wm_activate,其lowword of wparam 有以次叁个值: wa_active activated by some method other than a mouse click wa_clickactive activated by a mouse click. wa_inactive deactivated 透过subclassing的本领便可来处置这个题目 '以次在.bas option explicit declare function setwindowlong lib "user32" alias "setwindowlonga" _ (byval hwnd as long, byval nindex as long, byval dwnewlong as long) as long declare function getwindowlong lib "user32" alias "getwindowlonga" _ (byval hwnd as long, byval nindex as long) as long declare function callwindowproc lib "user32" alias "callwindowproca" _ (byval lpprevwndfunc as long, byval hwnd as long, byval msg as long, _ byval wparam as long, byval lparam as long) as long public const gwl_wndproc = (-4) public const wm_activate = &h6 public const wa_active = 1 public const wa_clickactive = 2 public const wa_inactive = 0 public prewinproc as long public function wndproc(byval hwnd as long, byval msg as long, _ byval wparam as long, byval lparam as long) as long dim factive as integer if msg = wm_activate then '博得wparam的lowword factive = cint(wparam and &hffff) if factive = wa_inactive then debug.print "inactive " else debug.print "active" end if end if '将之送往从来的window procedure wndproc = callwindowproc(prewinproc, hwnd, msg, wparam, lparam) end function '以次在form option explicit private sub form_activate() debug.print "event activate" end sub private sub form_deactivate() debug.print "event deactivate" end sub private sub form_load() dim ret as long '记载本来的window procedure的位址 prewinproc = getwindowlong(me.hwnd, gwl_wndproc) '设定combo1的window procedure到wndproc ret = setwindowlong(me.hwnd, gwl_wndproc, addressof wndproc) end sub private sub form_unload(cancel as integer) dim ret as long '废除message的截取,而使之又只送往从来的window procedure ret = setwindowlong(me.hwnd, gwl_wndproc, prewinproc) end sub