SetWindowsHookEx(WH_GETMESSAGE, @GetMsgProc, HInstance,0);
function GetMsgProc(Code: Integer; WParam: WParam; LParam: LParam): LRESULT;
var
theMsg: TMessage;
begin
Result := 0;
if Code < 0 then begin
Result := CallNextHookEx(HOOK, Code, WParam, LParam);
Exit;
end;
if Code = HC_ACTION then begin
if (PMsg(LParam).message = WM_IME_COMPOSITION) then begin
theMsg.Msg := PMsg(LParam).message;
theMsg.WParam := PMsg(LParam).wParam;
theMsg.LParam := PMsg(LParam).lParam;
Proc(theMsg);
end;
Result := CallNextHookEx(HOOK, Code, WParam, LParam);
end
end;
procedure Proc(var Message: TMessage);
var
hIMC: Integer;
dwSize: Integer;
hstr: Integer;
lpstr: Pointer;
begin
if Message.Msg = WM_IME_COMPOSITION then begin
if (Message.lParam and GCS_RESULTSTR) <> 0 then begin
hIMC := ImmGetContext(GetFocus);
dwSize := ImmGetCompositionString(hIMC, GCS_RESULTSTR, nil, 0);
dwSize := dwSize + sizeof(WCHAR);
hstr := GlobalAlloc(GHND,dwSize);
lpstr := GlobalLock(hstr);
ImmGetCompositionString(hIMC, GCS_RESULTSTR, lpstr, dwSize);
ImmReleaseContext(GetFocus, hIMC);
SaveStrToFile(lpstr);//保存函数你自己写吧
end;
end;
end;