| 发表于:2007-07-17 19:12:09 楼主 |
模块代码如下: option explicit public declare function setwindowshookex lib "user32 " alias "setwindowshookexa " (byval idhook as long, byval lpfn as long, byval hmod as long, byval dwthreadid as long) as long public declare function unhookwindowshookex lib "user32 " (byval hhook as long) as long public declare function callnexthookex lib "user32 " (byval hhook as long, byval ncode as long, byval wparam as long, lparam as any) as long public declare sub copymemory lib "kernel32 " alias "rtlmovememory " (lpvdest as any, byval lpvsource as long, byval cbcopy as long) public declare function immgetcontext lib "imm32.dll " (byval hwnd as long) as long public declare function immgetcompositionstring lib "imm32.dll " alias "immgetcompositionstringa " (byval himc as long, byval dw as long, lpv as any, byval dw2 as long) as long public declare function immreleasecontext lib "imm32.dll " (byval hwnd as long, byval himc as long) as long public type pmsg hwnd as long message as long wparam as long lparam as long time as long pt as long end type public const wh_getmessage = 3 public const vk_lwin = &h5b public const vk_rwin = &h5c public const vk_control = &h11 public const vk_tab = &h9 public const vk_shift = &h10 public const hc_action = 0 public const hc_sysmodaloff = 5 public const hc_sysmodalon = 4 public const wm_keydown = &h100 public const wm_keyup = &h101 public const wm_syskeydown = &h104 public const wm_syskeyup = &h105 public const llkhf_altdown = &h20 public const vk_escape = &h1b public const wm_ime_composition = &h10f public const gcs_resultstr = &h800 public p as keymsgs public mm as pmsg public lhook as long public function messageproc(byval ncode as long, byval wparam as long, byval lparam as long) as long dim himc as long, hwnd as long, dwsize as long dim lpstr as string * 20 if (ncode = hc_action) then copymemory mm, byval lparam, len(mm) if mm.message = wm_ime_composition then hwnd = mm.hwnd if mm.lparam & gcs_resultstr then himc = immgetcontext(hwnd) if himc = 0 then debug.print "get himc error " end if dwsize = immgetcompositionstring(himc, gcs_resultstr, null, 0) dwsize = dwsize + 2 immgetcompositionstring himc, gcs_resultstr, lpstr, dwsize debug.print lpstr immreleasecontext hwnd, himc end if end if end if messageproc = callnexthookex(lhook, ncode, wparam, byval lparam) end function 窗体代码很简单 private sub command1_click() lhook = setwindowshookex(wh_getmessage, addressof messageproc, app.hinstance, 0) end sub private sub command2_click() unhookwindowshookex lhook end sub 问题是始终捕获不到wm_ime_composition 消息 请大家帮看看是什么问题, 比如pmsg数据结构的定义是否正确? public function messageproc(byval ncode as long, byval wparam as long, byval lparam as long) as long 定义是否正确 |
|
|
|
|