Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

KeyHook and Word 2003 problem

3 views
Skip to first unread message

Luka

unread,
Feb 24, 2008, 6:48:34 PM2/24/08
to
I've compiled a keyhook applicaton. DLL sends keys pressed to APP
using:
//DLL
...
LRESULT CALLBACK KeyHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode<0 || (lParam & 0x80000000) || (lParam & 0x40000000) )
return CallNextHookEx(KeyHook, nCode, wParam, lParam);

PostMessage(HWND_BROADCAST, MY_CUSTOM_MESSAGE, wParam, lParam);

return CallNextHookEx(KeyHook, nCode, wParam, lParam);
}
...

This is how I get the posted message:

//APP
....
_fastcall TForm2::TForm2(TComponent* Owner) : TForm(Owner)
{
MY_CUSTOM_MESSAGE = NULL;
FCustomMessage = "MyMessage";
MY_CUSTOM_MESSAGE
= ::RegisterWindowMessage( FCustomMessage.c_str() );
Application->OnMessage = AppMessage;
}

void __fastcall TForm2::AppMessage( TMsg &Msg, bool &Handled )
{
if( (Msg.message == MY_CUSTOM_MESSAGE) && (MY_CUSTOM_MESSAGE != 0) )
{
Handled = true;
Label1->Caption = "wParam: " + IntToStr(Msg.wParam);
Label2->Caption = "lParam: " + IntToStr(Msg.lParam);
Form2->Show();
}
}
....


Everything works fine when my APP is hidden or Form is not in focus,
but
when i try to press a key on my form, in edit box or anywhere, the
APP
freezes. Another example is Microsoft Word 2003. When I try to type it
freezes up like when I try to type on my form (obviously Word reads
HWND_BROADCAST messages). If I try to press a key in any windows that
reads HWND_BROADCAST messages everything freezes up. What is wrong
with the code?

Thanks,
Luka!

0 new messages