Click to See Complete Forum and Search --> : SendMessage to Notepad


Raghavendra
May 2nd, 1999, 10:19 AM
Hi,

I want to send message "CTRl+C" to Notepad to copy its contents to Clipboard. I assume that a portion of text in notepad is already selected.

I have tried to do this but it does not seem to work.

Later, I want to fire "CTRL+V" to change the selected portion of text.

I

Paul McKenzie
May 2nd, 1999, 10:29 PM
First, sending keystrokes won't work the way you think it will, since keystroke processing is not as easy as sending a simple message. Key up, Key Down, OnChar, plus maybe other messages all have to be sent.

Try this instead:

Send the menu command using WM_COMMAND. If the function is available from the main menu, this is the way to do what you're trying to do.

For example, to send the "Copy", you would do this:

SendMessage(hwndNotepad, WM_COMMAND, Copy_Id, NULL);

This means that you need the handle to the notepad window (hwndNotepad), and the constant used to identify the "Copy" command on the main menu (Copy_Id).

To get the identifiers for the main menu, load Notepad.exe into a resource editor, and look at the main menu resource for the identifier's "copy" and "paste".

Regards,

Paul McKenzie

May 2nd, 1999, 10:53 PM
You might not want to send Ctrl+C and Ctrl+V...If you really want to paste text try sending WM_CHAR%2

Paul McKenzie
May 3rd, 1999, 03:31 AM
Try this instead:

Send the menu command using WM_COMMAND. If the function is available from the main menu, this is the easiest way to do what you're trying to do.

For example, to send the "Copy", you would do this:

SendMessage(hwndNotepad, WM_COMMAND, Copy_Id, NULL);

This means that you need the handle to the notepad window (hwndNotepad), and the constant used to identify the "Copy" command on the main menu (Copy_Id).

To get the identifiers for the main menu, load Notepad.exe into a resource editor, and look at the main menu resource for the identifier's "copy" and "paste".

Regards,

Paul McKenzie