WM_KEYDOWN wont work correctly

This is a discussion on WM_KEYDOWN wont work correctly within the Windows Programming forums, part of the Platform Specific Boards category; Code: case WM_KEYDOWN: { switch(wParam){ case 23: MessageBox(hwnd,"You clicked daa!","daa",MB_OK | MB_ICONINFORMATION); return 0; } } I want it to ...

  1. #1
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318

    WM_KEYDOWN wont work correctly

    Code:
            case WM_KEYDOWN:
            {
            switch(wParam){
            case 23:
                 MessageBox(hwnd,"You clicked daa!","daa",MB_OK | MB_ICONINFORMATION);
                 return 0;
            }
            }
    I want it to show the messagebox when i click tab, but it doesn't work. The keycode should be right. But another thing that annoys me, is that if I have that case WM_KEYDOWN there, even if there's nothing in it, the program flashes(my edit boxes and buttons).

  2. #2
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Ok, I need to use VK_TAB for that, but wm_keydown wont catch keypresses, when focus is in my textbox. I would like to make TAB set the focus to the next textbox.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    >>I would like to make TAB set the focus to the next textbox


    Have a look at WS_TABSTOP
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    It doesn't seem to work. I tried to add it to the style list of my edit box:
    Code:
    hww=CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT(""), WS_CHILD | WS_VISIBLE | ES_NUMBER | WS_TABSTOP,
    			               1, 1, 56, 23,
    			               hwnd,(HMENU) 0xED, GetModuleHandle(NULL), NULL);
    And I tried it with the sendmessage:
    Code:
    SendMessage(hww,WS_TABSTOP,0,0);

  5. #5
    The N00b That Owns You!
    Join Date
    Jul 2005
    Location
    Canada!
    Posts
    178
    Try This ( i use this methoud for my games)

    Code:
    // Global Variables.
    bool keys[256];
    bool tabp; // check if tab is being pressed
    
    // were you have your ShowWindow() function plce this under it
    SetForegroundWindow(hWnd);	// Slightly Higher Priority
    SetFocus(hWnd);// Sets Keyboard Focus To TheWindow                                        
    
    // this goes in your LRESULT CALLBACK
    
    case WM_KEYDOWN:							// Is A Key Being Held Down?
    		{
    			keys[wParam] = TRUE;					// If So, Mark It As TRUE
    			return 0;								// Jump Back
    		}
    
    		case WM_KEYUP:								// Has A Key Been Released?
    		{
    			keys[wParam] = FALSE;					// If So, Mark It As FALSE
    			return 0;								// Jump Back
    		}
    
    // put this in winmain (probably at the top or afdter you render your window
    
    if (keys[VK_TAB] && !tabp)
    {
        // your message box goes here
    }
    if (!keys[VK_TAB])
    {
        tabp = FALSE;
    }
    you get the idea
    New Function!!!!

    glAddIdol(C+noob);

    The feeling of rusty spoons against my salad fingers is almost ORGASMIC

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    If you set the WS_TABSTOP style then your app do not have to process TAB key presses. The OS will do it for you.

    In the resource editor you can set the TAB order for non dynamic controls (those not created at run time).

    >>SendMessage(hww,WS_TABSTOP,0,0);

    This has no chance of working as WS_ are styles not messages.

    Use SetFocus() to change controls.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    I still didn't get the point, how to use it. Do I have to use "case WS_TABSTOP" in my message switch or SetFocus(WS_TABSTOP) or how then?

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    If you specify WS_TABSTOP then you should not need to process any msgs. Pressing TAB should change controls.

    If you are intercepting keydown events.
    A keydown event where the only key pressed is the TAB key (and do not use the WS_TABSTOP style) then you can change controls by using SetFocus()

    or something like.......
    Code:
    case WM_TAB:
        if(GetFocus()==GetDlgItem(hWnd,IDC_EDIT1))
        {
                 SetFocus(GetDlgItem(hWnd,IDC_EDIT2));
                 return 0;
        }
    break;
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  9. #9
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    A thing like WM_TAB doesn't exist and how and where can I specify ws_tabstop?
    MSDN:
    Specifies one of any number of controls through which the user can move by using the TAB key. The TAB key moves the user to the next control specified by the WS_TABSTOP style.

    Dumb me, I don't get the point...
    Last edited by maxorator; 10-03-2005 at 12:43 AM.

  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Are you creating the control dynamically (when the app runs) or from a resource script (in the resource editor)?

    If dynamically add WS_TABSTOP to you CreateWindow() call under the dwStyle param
    something like
    DWORD dwStyle = WS_CHILD|WS_TABSTOP|ES_MULTILINE;

    If in the resource editor change the properties to include the tab stop style. What IDE do you use?


    >>case WM_TAB:

    Opps....my bad...
    In my apps I process WM_KEYDOWN and WM_CHAR and send a app defiend (and registered) msg called WM_TAB......
    Sorry.....

    try
    Code:
    case WM_KEYDOWN:
        switch(wparam)
        { 
              case VK_TAB: //0x09
                 if(GetFocus()==GetDlgItem(hWnd,IDC_EDIT1))
                 {
                         SetFocus(GetDlgItem(hWnd,IDC_EDIT2));
                         return 0;
                 }
              break;
        .......
    also look at GetDlgCtrlID() for converting a HWND to its control ID number.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  11. #11
    Registered User
    Join Date
    Oct 2005
    Posts
    9
    Since you are looking things up under the MSDN I am going to assume that you are using the Microsoft's Visual IDE. If this is correct then your easiest way that I know of is to click on the different controls under developement, open their property box, scroll down to the TabStop element and set it to True. Now go to the TabIndex element right above and set that to a number that is one integer higher than the control you want the tab to come from. For example the ComboBox1 might have a TabIndex of 1, then you want to tab from there to the OK button so you would set it's TabIndex to 2. Now when you Tab from the Combo box it will go straight to the OK button to accept whatever you have selected in the combo box. You can also CODE this by hand, but sounds like you are confusing yourself trying to get that dynamic. after you have done this go into the code and find the definition of the Button or Box and that will show you what the code for the TabStop would look like.

    May I suggest also though that, in my experience (for what it's worth), People don't TAB anymore unless they have to. Us lazy end users would rather not touch or even KNOW where our keyboard is. That's too much like work. So in the end, I wouldn't stress over tab setups, just make sure they are correct for those people that still might use them, but I would use the SetFocus() mentioned earlier with mouse controls like OnClick() or MouseClick() events. Also if people do have to type something in, they would rather (again, in my experience), have the program move onto the next control "automatically" after the text has been entered and the 'enter' or 'return' key is pressed. remember also, that the enter key leaves a control character on the end of any text left in the message box, so you MAY have to remove that when entering that data in another control or database. Hope this helped.

    << been there

  12. #12
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    I am using Dev-C++ 4.9.9.2

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 03:48 AM
  5. Writing BMP file... doesn't work correctly
    By tin in forum Game Programming
    Replies: 3
    Last Post: 12-28-2005, 03:40 AM

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