SendMessage

This is a discussion on SendMessage within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I am trying to use the SendMessage function to send CTRL+S to notepad, what I have figured out so ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    8

    SendMessage

    Hello, I am trying to use the SendMessage function to send CTRL+S to notepad, what I have figured out so far is that I need both the parent "Notepad" and child handle "Edit" for notepad using FindWindow. I can already send plain text to notepad, but I'm having problems with stimulating hot-keys, I tried this following code segment for CTRL+V and it works, but why dosnt the ascii for CTRL+S work? and is there an ascii code for ALT+#?
    Lets for example say ALT+F to drop down File in notepad.

    SendMessage(hwnd,WM_CHAR, 0x16, 1); // Sends a CTRL+V which works perfectly

    Now this line...

    SendMessage(hwnd,WM_CHAR, 0x13, 1); // Sends a CTRL+S but nothing happens.

    Thank you.

  2. #2
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    308
    I think you need to try WM_KEYDOWN -_-
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    8
    I tried to replace it with WM_KEYDOWN, then I tried it followed by a WM_KEYUP.
    I have read that WM_KEYDOWN and WM_KEYUP are notification messages, that tell you something happend, sending messages with them will not work. Could someone please elaborate on this? :O thanks.

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544

  5. #5
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357
    well if you want to actually simulate the keypress use keybd_event, this really does simulate a keypress so you will first have to give notepad the focus.

  6. #6
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Sorry but this is a little bit off topic, but I need to send a message with the LOWORD and HIWORD of LPARAM defined. How would I do this in a SendMessage function like the following one?
    Code:
    SendMessage(hwnd,WM_LBUTTONDOWN,(WPARAM)0,(LPARAM));
    I tried a couple different ways like "(LOWORD(LPARAM)=134)(HIWORD(LPARAM)=195))" How would I do this because that comes up with errors? Thought this would go in here because the thread is named SendMessage. Thanks. (Sorry for going off topic)
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  7. #7
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357
    not sure this belongs in this thread... but create a variable, set the low word to whatever and the high word to whatever (use bitwise operators, shifts, or set it in one move), then pass the LOWORD() and the HIWORD() with the macros.
    you could actually set the whole thing at once with a single move.
    Code:
    int hat = 0x008600c3 ; // hi word is 134 low word is 195

  8. #8
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Alright I think I got it thanks. This is what I did:
    Code:
    WORD hival,loval;
    hival=HIWORD(195);
    loval=LOWORD(134);
    SendMessage(hwnd,WM_LBUTTONDOWN,(WPARAM)0,(LPARAM)loval|hival);
    Thanks.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  9. #9
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357
    that wouldn't work because hival is only a word so it has no hiword.
    If you wanted to do it like that you would set hival like this:
    Code:
    DWORD hival = (195 << 16) ;
    Also loval only has a single word so there is no need for LOWORD()

    If you have more questions about this, you should create a separate thread.

  10. #10
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Thanks, it works.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  11. #11
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    ...LOWORD and HIWORD of LPARAM defined...
    MAKELPARAM.
    MAKEWPARAM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  12. #12
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357
    wow, you learn something new every day

  13. #13
    Registered User
    Join Date
    Jul 2005
    Posts
    8
    I'm not sure if its called stimulating a hot-key or what not, but what I want to do is send CTRL+S so notepad recognizes that as the Hotkey and then opens up the "Save As..." dialog.
    I can use keybd_event, but it requires to give notepad focus, is there any other way to actually send a CTRL+S to notepad without having focus? Using some sort of DDE function or something of that sort?
    or is SendMessage still out of the question for this purpose?

    Thanks.
    Last edited by reefa; 07-18-2005 at 02:24 PM.

  14. #14
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357
    a wm_keydown and wm_keyup pair should work, have you tried sending a down and then an up?
    VK_CONTROL, WM_KEYDOWN
    's', WM_KEYDOWN
    WM_KEYUP
    WM_KEYUP

    spy++ says:
    WM_KEYDOWN nVirtKey:VK_CONTROL cRepeat:1 ScanCode:1D fExtended:0 fAltDown:0 fRepeat:0 fUp:0
    WM_KEYDOWN nVirtKey:'S' cRepeat:1 ScanCode:1F fExtended:0 fAltDown:0 fRepeat:0 fUp:0
    WM_CHAR chCharCode:'0013' cRepeat:1 ScanCode:1F fExtended:0 fAltDown:0 fRepeat:0 fUp:0
    Last edited by valis; 07-18-2005 at 02:58 PM.

  15. #15
    Registered User
    Join Date
    Jul 2005
    Posts
    8
    Hello there, I tried using WM_KEYDOWN and WM_KEYUP with this following code segment:

    Code:
    SetForegroundWindow(hwnd);
    SendMessage(hwnd,WM_KEYDOWN, 0x00000011, 0x001D0001); // CTRL keydown
    SendMessage(hwnd,WM_KEYDOWN, 0x00000053, 0x001F0001); // S keydown
    SendMessage(hwnd,WM_KEYUP, 0x00000053, 0xC01F0001); // S keyup
    SendMessage(hwnd,WM_KEYUP, 0x00000011, 0xC01D0001); // CTRL keyup
    Still nothing happend, but then I decided to run Spy++ and monitor some of the activity, and this is what I got.

    * This is what I logged when I ran my VC++ programming with the SendMessage code segment from above
    Code:
    <00001> 00EF01DE S WM_KEYDOWN nVirtKey:VK_CONTROL cRepeat:1 ScanCode:1D fExtended:0 fAltDown:0 fRepeat:0 fUp:0
    <00002> 00EF01DE R WM_KEYDOWN
    <00003> 00EF01DE S WM_KEYDOWN nVirtKey:'S' cRepeat:1 ScanCode:1F fExtended:0 fAltDown:0 fRepeat:0 fUp:0
    <00004> 00EF01DE R WM_KEYDOWN
    <00005> 00EF01DE S WM_KEYUP nVirtKey:VK_CONTROL cRepeat:1 ScanCode:1D fExtended:0 fAltDown:0 fRepeat:1 fUp:1
    <00006> 00EF01DE R WM_KEYUP
    <00007> 00EF01DE S WM_KEYUP nVirtKey:'S' cRepeat:1 ScanCode:1F fExtended:0 fAltDown:0 fRepeat:1 fUp:1
    <00008> 00EF01DE R WM_KEYUP
    <00009> 00EF01DE S WM_CHAR chCharCode:'
    <00010> 00EF01DE R WM_CHAR
    *This is what I logged when I manually pushed CTRL+S in notepad

    Code:
    <00011> 00EF01DE P WM_KEYDOWN nVirtKey:VK_CONTROL cRepeat:1 ScanCode:1D fExtended:0 fAltDown:0 fRepeat:0 fUp:0
    <00012> 00EF01DE P WM_KEYDOWN nVirtKey:'S' cRepeat:1 ScanCode:1F fExtended:0 fAltDown:0 fRepeat:0 fUp:0
    <00013> 004006E0 P WM_KEYUP nVirtKey:'S' cRepeat:1 ScanCode:1F fExtended:0 fAltDown:0 fRepeat:1 fUp:1
    <00014> 004006E0 P WM_KEYUP nVirtKey:VK_CONTROL cRepeat:1 ScanCode:1D fExtended:0 fAltDown:0 fRepeat:1 fUp:1
    As you can see from my SendMessage code above I mimicked the manual push of CTRL+S to notepad, but apparently nothing happend. The message type that is picked up by Spy++ when I do a SendMessage is listed as "Sent" and "Recieved", but the message type of a manual key press is listed as "Posted", when I do a keybd_event to stimulate CTRL+S, the message type gets listed as "Posted" and works like a charm. Is there a way to change the message type of SendMessage to be converted to a "Posted"?

    I appreciate all the help, thanks!

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-19-2009, 03:15 AM
  2. SendMessage to 16bit program
    By khdani in forum Windows Programming
    Replies: 2
    Last Post: 09-02-2008, 03:37 AM
  3. Combobox problem
    By gargamel in forum Windows Programming
    Replies: 2
    Last Post: 05-06-2005, 02:37 PM
  4. Sendmessage
    By knutso in forum C++ Programming
    Replies: 2
    Last Post: 09-30-2002, 06:34 AM
  5. WM_KEYDOWN and SendMessage
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 07-13-2002, 06:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21