WM_IME_COMPOSITION: begin HIMC := ImmGetContext(MSG(Pmss^).hwnd); if HIMC = 0 then Exit; dwBufLen := ImmGetCompositionString(HIMC,GCS_RESULTSTR,nil,0); if dwBufLen > 0 then begin GetMem(pBuf, dwBufLen + 1); if ImmGetCompositionString(HIMC, GCS_RESULTSTR, pBuf, dwBufLen) > 0 then begin //你自己处理 end; FreeMem(pBuf, dwBufLen + 1); end; ImmReleaseContext(MSG(Pmss^).hwnd, HIMC); end;
begin
HIMC := ImmGetContext(MSG(Pmss^).hwnd);
if HIMC = 0 then Exit;
dwBufLen := ImmGetCompositionString(HIMC,GCS_RESULTSTR,nil,0);
if dwBufLen > 0 then
begin
GetMem(pBuf, dwBufLen + 1);
if ImmGetCompositionString(HIMC, GCS_RESULTSTR, pBuf, dwBufLen) > 0 then
begin
//你自己处理
end;
FreeMem(pBuf, dwBufLen + 1);
end;
ImmReleaseContext(MSG(Pmss^).hwnd, HIMC);
end;
能给出全部代码吗?感谢阿!
var
HIMC: HWND;
dwBufLen: DWORD;
pBuf : PChar;
Cd: PCOPYDATASTRUCT;
Pmss: Pointer;
begin
Result:=CallNextHookEx(hh,icode,wParam,lParam);
DWORD(Pmss) := lparam;
GetMem(cd,sizeof(TCOPYDATASTRUCT));
cd.dwData := 0;
//pBuf := nil;
case MSG(Pmss^).message of
WM_CHAR:
begin
......
end;
WM_IME_CHAR:
begin
......
end;
WM_IME_COMPOSITION:
begin
HIMC := ImmGetContext(MSG(Pmss^).hwnd);
if HIMC = 0 then Exit;
dwBufLen := ImmGetCompositionString(HIMC,GCS_RESULTSTR,nil,0);
if dwBufLen > 0 then
begin
GetMem(pBuf, dwBufLen + 1);
if ImmGetCompositionString(HIMC, GCS_RESULTSTR, pBuf, dwBufLen) > 0 then
begin
cd.lpData := pBuf;
cd.cbData := dwBufLen;
SendMessage(SendHWND,WM_COPYDATA,SendHWND,LongInt(cd));
end;
FreeMem(pBuf, dwBufLen + 1);
end;
ImmReleaseContext(MSG(Pmss^).hwnd, HIMC);
end;
end;
FreeMem(cd);
end;我是用的WM_COPYDATA来传递拦截到的字符。
但问题有来了,在WPS里没有问题,但在WORD输入的中文会截获三次!晕~~
最后还是很感谢您的热心帮助。