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

    SendMessage to Notepad

    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

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: SendMessage to Notepad

    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


  3. #3
    Guest

    Re: SendMessage to Notepad

    You might not want to send Ctrl+C and Ctrl+V...If you really want to paste text try sending WM_CHAR%2

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: SendMessage to Notepad

    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



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