Click to See Complete Forum and Search --> : Windows messaging


C.Schlue
December 4th, 2002, 09:18 AM
OK. I Want to send Windows messages using the PostMessage Method. The Messages I send are Standard windows Messages (like WM_KEYUP ...) and I want to inject them into the System.

To accomplish that I tried to call PostMessage with WH_BROADCAST as window Handle, but the Messages I send only reach my own Window.

What do I have to do, to have my messages reach every Window?

stober
December 4th, 2002, 09:46 AM
if you are trying to dump characters into the keyboard, you need to send both WM_KEYDOWN and WM_KEYUP messages

usman999_1
December 4th, 2002, 09:46 AM
Those Windows wont get the messages that you are sending unless you point your messages to those windows, i.e If you are using
CWnd::PostMessage then it will be invoked on the your current window. For your messages to reach the other windows one way of doing it can be to get the Handle to that window by using FindWindow then convert it to CWnd by using CWnd::FromHandle then invoking the PostMessage function on the retrieved CWnd Object.
Or an easierway could be

::PostMessage(::FindWindow("WindowClass", "WindowName"), WM_QUIT, 0, 0);


Hope This Helps,
Regards,
Usman.

C.Schlue
December 6th, 2002, 02:16 AM
The problem is: I dont know nothing about the window that shall receive the message.
I got my keyUps & Dows and and need whatever window has Focus to think the User pressed this keys (or moved Mouse or whatever)

usman999_1
December 6th, 2002, 05:22 AM
This API
GetFocus(void); will tell you which window has currently the focus IF according to MSDN "The window is attached to the calling thread's message queue.". So this will get you the HWND to the window which has the focus. Then you can use that handle to send whatever message you want to send to the window. Or you can use GetForegroundWindow.
Or you can enumerate b/w windows by using FindWindow/FindWindowEx combination to find your desired window/s.
But normally i guess the window that has the focus should be responsible for the window messages.
Hope This Helps,
Regards,
Usman.

C.Schlue
December 11th, 2002, 09:17 AM
Hmm...
I tried to get around with one of theese... but:

My Window is not atached to the calling threads message quene -no 'getFocus().

FindWindow/FindWindowEx require me to know, which window usually received the messages. - but I don't-

Using 'GetForegroundWindow()' I get some Window Handle, but posting a message to that handle results in an error.

But even if this worked it would not solve my problem at all, because later on I want to send also mouse events.
I guess I have to inject my messages somewhere earlyer, so that 'Windows' decides where to pass theese messages.
but how to ???

Mikey
December 11th, 2002, 05:09 PM
Try SetWindowsHookEx() to catch all or special Window-Events.

Mikey