Click to See Complete Forum and Search --> : PostMessage() Inquiry


Troy T
April 30th, 1999, 01:14 AM
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

shridhar
April 30th, 1999, 01:36 AM
CWnd *pWnd = CWnd::GetActiveWindow();
pWnd->PostMessage(WM_PASTE,(WPARAM)0,(LPARAM)0);

let me know if you find problems with that.

Troy T
April 30th, 1999, 01:46 AM
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

shridhar
April 30th, 1999, 02:01 AM
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.

Troy T
April 30th, 1999, 02:06 AM
Thanks for the information, I'll try that and see what I come up with! :)



- Troy

Troy T
May 1st, 1999, 11:50 PM
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