CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 1999
    Location
    WA
    Posts
    65

    PostMessage() Inquiry

    Hello-

    I have a unique problem that I need to solve in the application I'm developing. The problem is a Hot Key type problem. The scenario is as follows:

    I have a global hot key setup for my application that is user-definable. When the user presses this hot key, it sends a message to the application, and in that function I place text into the clipboard. Then I need to find the active window and actually do a "PostMessage" to the active window with the CTRL + V combination (to paste the clipboard contents to the active window).

    Can someone help me formulate a PostMessage function call do accomplish the above? After many attempts, there is just something not quite right about the way I am approaching this.

    Thanks!

    - Troy

  2. #2
    Join Date
    Apr 1999
    Location
    Bangalore India.
    Posts
    7

    Re: PostMessage() Inquiry

    CWnd *pWnd = CWnd::GetActiveWindow();
    pWnd->PostMessage(WM_PASTE,(WPARAM)0,(LPARAM)0);

    let me know if you find problems with that.


  3. #3
    Join Date
    May 1999
    Location
    WA
    Posts
    65

    Re: PostMessage() Inquiry

    The PostMessage() that you filled out for me helps me greatly. However, I still have a problem. The active window at the time that the hotkey is pressed is my application, so I need to somehow know (or get a handle) to the window (say notepad for example) and then paste the statistics so that when the user pressed the hotkey in my application, it will insert the text into the clipboard, and then send a PASTE message to the notepad window for example..

    Does that explain things a little better? Do you have any other thoughts?

    Thanks!

    - Troy

  4. #4
    Join Date
    Apr 1999
    Location
    Bangalore India.
    Posts
    7

    Re: PostMessage() Inquiry

    If the process of your application is
    different from the process of target window,
    then you need to set a systemwide hook
    for keyboard messages.

    The hook function is called before a keyboard
    message is sent to target application.
    You can modify the message in the hook
    procedure if the message is meant to the
    application that you are looking for.

    Then the modified message goes to the
    appropriate application.

    I dont remember the exact syntax offhand,but
    you need to do something like this :

    1. Write a keyboard hook function
    Refer Win32 API documentation for the
    exact function signature.
    Systemwide hook procedure must
    reside in a DLL.

    2. Set the systemwide hook by calling
    SetWindowsHookEx() call.
    Use KEYBOARD hook.

    Let me know if it works for you.

    shridhar.



  5. #5
    Join Date
    May 1999
    Location
    WA
    Posts
    65

    Re: PostMessage() Inquiry

    Thanks for the information, I'll try that and see what I come up with!



    - Troy

  6. #6
    Join Date
    May 1999
    Location
    WA
    Posts
    65

    Re: PostMessage() Inquiry

    Actually, I found a quite clever way to handle this. Instead of using a system wide keyboard hook, I posted a WM_KEYDOWN message using the keyboard input buffer. That accomplished what I wanted exactly, without the extra DLL to worry about!

    - Troy

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