Tabbing through Edit Boxes (not MFC)

This is a discussion on Tabbing through Edit Boxes (not MFC) within the Windows Programming forums, part of the Platform Specific Boards category; I have 4 edit boxes on my main window created with: Code: //global declares HWND hwEB1, hwEB2, hwEB3, hwEB4; //message ...

  1. #1
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065

    Tabbing through Edit Boxes (not MFC)

    I have 4 edit boxes on my main window created with:
    Code:
     //global declares
    HWND hwEB1, hwEB2, hwEB3, hwEB4;
    
     //message handler, case WM_CREATE:
    hwEB1=CreateWindowEx(0,"Edit","Player 1",WS_CHILD | 
    WS_VISIBLE,15,90,60,15,hwnd,NULL,hInstMain,NULL);
    
    etc. etc. etc.
    I want to cycle through when the TAB button is pressed (I know how to check for keypresses and then process my actions when (wParam==VK_TAB)).

    I know that to give each one focus I would use SendMessage
    and pass that control's HWND and use WM_SETFOCUS. What I
    don't know
    is how to determine which control currently has
    the focus (so that I can cycle through to the next one).

    I was thinking of making a class that would have 3 member variables (int iEditBox, HWND hwID and bool bHasFocus) and having an array (cebEditBoxes[4]). Then cycling through the array and pass the hwID to the SendMessage(...,WM_SETFOCUS,...,...) and changing the bHasFocus variable. But if there is a "proper" way to do it I'd rather learn it.

    Thanks in advance for your help.

    Oh, yeah: I've searched the archives and the only posts that dealt with this used MFC
    Last edited by jdinger; 03-23-2002 at 10:57 PM.

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    381
    Try creating the control with the WS_TABSTOP style.

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    In addition to Shtarker's fine suggestion you should use 'IsDialogMessage' to get default dialog keyboard handling (such as TAB) unless you use a modal dialog box.

  4. #4
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Thanks, guys! That works perfectly. I had tried using WS_TABSTOP before but without using IsDialogMessage (which I thought only applied to controls on dialog boxes).

    Thanks again!

  5. #5
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    I spoke too soon. That fixes the tabbing between controls but it gave me another problem. When you type it puts in 4 of whatever letter/number you type and backspace deletes in groups of 4.

    The only thing I changed in my code was to add WS_TABSTOP to my call to CreateWindowEx and to add:
    IsDialogMessage(hWndMain,&msg);
    to my message for loop in WinMain.

    I have tried removing both changes one at a time and I only get the multi-character typing error with IsDialogMessage(...,....). Here's the code for my message loop:

    Code:
    MSG msg;
    for(;;)
    {
        if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
        {
          if(msg.message==WM_QUIT) break;
          IsDialogMessage(hWndMain,&msg);
          TranslateMessage(&msg);
          DispatchMessage(&msg);
        }
      GameLoop();
    }
    CleanUp();
    return(msg.wParam);
    Problem Solved
    I changed my message loop to:
    Code:
    MSG msg;
    for(;;)
    {
        if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
        {
          if(msg.message==WM_QUIT) break;
          if(IsDialogMessage(hWndMain,&msg))
           {
            }
          else
           {
              TranslateMessage(&msg);
              DispatchMessage(&msg);
            }
        }
      GameLoop();
    }
    CleanUp();
    return(msg.wParam);
    Last edited by jdinger; 03-24-2002 at 05:21 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WIndows programming?
    By hostensteffa in forum Windows Programming
    Replies: 7
    Last Post: 06-07-2002, 09:52 PM
  2. Limiting Characters in Edit Box :: MFC
    By kuphryn in forum Windows Programming
    Replies: 5
    Last Post: 06-02-2002, 11:21 AM
  3. Edit Boxes Question
    By Ruben in forum Windows Programming
    Replies: 2
    Last Post: 09-14-2001, 01:06 AM
  4. Edit Boxes Question
    By RubenJ in forum Windows Programming
    Replies: 1
    Last Post: 09-12-2001, 09:01 PM
  5. Password Edit Boxes
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 08-27-2001, 03:40 PM

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