Wm_char

This is a discussion on Wm_char within the Windows Programming forums, part of the Platform Specific Boards category; I am on the chapter "Keyboard" of petzold and I'm just a little foggy with the WM_CHAR message. I think ...

  1. #1
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584

    Wm_char

    I am on the chapter "Keyboard" of petzold and I'm just a little foggy with the WM_CHAR message. I think that it is a different and separate message from WM_KEYDOWN, but then why does it send a WM_KEYDOWN message to the WndProc?

    And, to get the char that the user pressed, you just do this:
    Code:
    /* CODE SNIPPET */
    TCHAR newchar;
    
    /*** SOME CODE DOWN ***/
    
    switch (message)
    {
        case: WM_CHAR
        {
            newchar = (TCHAR) wParam;
        }
    /*** ETC... ***/
    Do I pretty much have the right idea? I didn't write out the whole WndProc, but I wanted to make sure that I'm understanding:

    >> newchar = (TCHAR) wParam;

    Is this right? Thanks.

    --Garfield
    1978 Silver Anniversary Corvette

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    when a key is pressed your winproc recieves either a WM_KEYDOWN or a WM_SYSKEYDOWN. when the key is released the corresponding WM_KEYUP or WM_SYSKEYUP is sent. in these messages WPARAM contains the virtual keycode and LPARAM contains some other info such as repeat count and scan code and several flags. msdn will give more info.

    now remember your messaging loop has this...

    GetMessage(.....)
    TranslateMessage(.....)

    Ever wondered what TranslateMessage does?
    This function actually translates the keystroke message into a character message and places the WM_CHAR into the message queue.

    You can learn about the order the messages come in by running a program on the disc that comes with the book. Play around.Press some keys and see which messages are sent to your windproc.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Okay, I think I understand now. Say I press 'a', a WM_KEYDOWN and a WM_CHAR message will both be sent to my WndProc in that order, right? And then I can use a switch on the wParam to take the right actions for the char that was received for WM_CHAR. I understand, thanks!

    --Garfield
    1978 Silver Anniversary Corvette

  4. #4
    Registered User canine's Avatar
    Join Date
    Sep 2001
    Posts
    125

    Smile

    Remember that a WM_CHAR message will be sent only for numbers and characters when WM_KEYDOWN will be sent for all characters and things like Crtl and the arrow keys.
    In a perfect world every dog would have a home and every home would have a dog.
    Visit My Web Site, Canine Programming
    I use Win32 API

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    acturaly you would get WM_SYSKEYDOWN . You only get WM_KEYDOWN for letters, numbers, punction(sp?), and other signs but not System keys like shift, Alt, Cntrl, and the other system keys.

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    164
    You get WM_KEYDOWN messages for all keys except 'Alt'. Even 'Alt Gr'.
    // Gliptic

Popular pages Recent additions subscribe to a feed

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