| 发表于:2007-01-08 10:12:324楼 得分:0 |
注册热键的函数,放在模块中: 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 declare function registerhotkey lib "user32 " (byval hwnd as long, byval id as long, byval fsmodifiers as long, byval vk as long) as long declare function unregisterhotkey lib "user32 " (byval hwnd as long, byval id as long) as long public const wm_hotkey = &h312 public const mod_alt = &h1 public const mod_control = &h2 public const mod_shift = &h4 public const gwl_wndproc = (-4) public prewinproc as long public modifiers as long, uvirtkey as long, idhotkey as long private type talong ll as long end type private type t2int lword as integer hword as integer end type public function wndproc(byval hwnd as long, byval msg as long, byval wparam as long, byval lparam as long) as long if msg = wm_hotkey then if wparam = idhotkey then dim lp as talong, i2 as t2int lp.ll = lparam lset i2 = lp if (i2.lword = modifiers) and i2.hword = uvirtkey then shell "notepad ", vbnormalfocus end if end if end if '如果不是热键信息则调用原来的程序 wndproc = callwindowproc(prewinproc, hwnd, msg, wparam, lparam) end function 使用,放在窗体中: option explicit private sub form_load() dim ret as long '记录原来的window程序地址 prewinproc = getwindowlong(me.hwnd, gwl_wndproc) '用自定义程序代替原来的window程序 ret = setwindowlong(me.hwnd, gwl_wndproc, addressof wndproc) idhotkey = 1 modifiers = mod_alt + mod_control 'alt+ctrl 键 uvirtkey = vbkeyg 'g键 ret = registerhotkey(me.hwnd, idhotkey, modifiers, uvirtkey) end sub private sub form_unload(cancel as integer) dim ret as long '取消message的截取,使之送往原来的windows程序 ret = setwindowlong(me.hwnd, gwl_wndproc, prewinproc) call unregisterhotkey(me.hwnd, uvirtkey) end sub | | |
|