CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2002
    Location
    Germany
    Posts
    162

    Windows messaging

    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?

  2. #2
    Join Date
    Jun 2002
    Posts
    1,417
    if you are trying to dump characters into the keyboard, you need to send both WM_KEYDOWN and WM_KEYUP messages

  3. #3
    Join Date
    Aug 2001
    Location
    Germany
    Posts
    1,384
    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
    Code:
    ::PostMessage(::FindWindow("WindowClass", "WindowName"), WM_QUIT,  0, 0);
    Hope This Helps,
    Regards,
    Usman.
    Last edited by usman999_1; December 4th, 2002 at 10:48 AM.

  4. #4
    Join Date
    Dec 2002
    Location
    Germany
    Posts
    162

    Unhappy

    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)

  5. #5
    Join Date
    Aug 2001
    Location
    Germany
    Posts
    1,384
    This API
    Code:
    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
    Code:
    GetForegroundWindow
    .
    Or you can enumerate b/w windows by using
    Code:
    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.

  6. #6
    Join Date
    Dec 2002
    Location
    Germany
    Posts
    162
    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 ???

  7. #7
    Join Date
    Aug 2001
    Location
    Germany
    Posts
    166
    Try SetWindowsHookEx() to catch all or special Window-Events.

    Mikey

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured