Thread: Tabs in windows childs

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    34

    Tabs in windows childs

    Hey,

    I want to add tabbing between windows and windows I create the child window inside WM_CREATE,so all childs created are just childs of main window I want to add tabbing.So when I press tab it would go to next control,I don't know exactly what msg to process,Note that I have already added Extended style control parent and it still haven't added tabbing action.
    it would be cool if someone can shed some light on this situation.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Add WS_TABSTOP to the window styles when creating your windows

    Process IsDialogMessage in your message dispatcher.

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    34
    Quote Originally Posted by CommonTater View Post
    Add WS_TABSTOP to the window styles when creating your windows

    Process IsDialogMessage in your message dispatcher.
    oh yes,thanks I also found out more information regarding this problem in msdn after you told me.

  4. #4
    Registered User
    Join Date
    Jan 2010
    Posts
    34
    hi I seem have fixed the major problem of tabbing after adding those msgs,but the problem now that only 1 control will get tabbed ? I thought the problem maybe because dialogbox implements msging system differently in which return false in case of default handling I tried,but some thing happened only 1 control got the focus... it wouldn't jump from that control to other.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Ok... the WS_TABSTOP is to be added to each control you want to tab to... It's a style, not a message.

    Here's an example in a .rc file (used for dialog boxes)...

    Code:
      CONTROL "", 4000, "Static", SS_CENTER|SS_CENTERIMAGE, 54, 13, 93, 12, WS_EX_STATICEDGE
      CONTROL "2100", 4001, "Edit", ES_CENTER|ES_NUMBER|WS_BORDER|WS_TABSTOP, 54, 29, 28, 12, WS_EX_CLIENTEDGE
      CONTROL "", 4002, "Edit", ES_AUTOHSCROLL|ES_PASSWORD|WS_BORDER|WS_TABSTOP, 54, 45, 93, 12, WS_EX_CLIENTEDGE
      CONTROL "10", 4003, "Edit", ES_CENTER|ES_NUMBER|WS_BORDER|WS_TABSTOP, 54, 79, 28, 12
      CONTROL "30", 4004, "Edit", ES_CENTER|ES_NUMBER|ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 54, 95, 28, 12
      CONTROL "5", 4005, "Edit", ES_CENTER|ES_NUMBER|ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 54, 111, 28, 12
      CONTROL "1000", 4006, "Edit", ES_CENTER|ES_NUMBER|ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 54, 127, 28, 12
      CONTROL "Disable Add Files mode", 4008, "Button", BS_AUTOCHECKBOX|WS_TABSTOP, 173, 14, 117, 16
      CONTROL "Allow only 1 remote per program", 4009, "Button", BS_AUTOCHECKBOX|WS_TABSTOP, 173, 34, 117, 16
      CONTROL "Disable End Program command", 4010, "Button", BS_AUTOCHECKBOX|WS_TABSTOP, 173, 54, 117, 16
    Notice how WS_TABSTOP is used with every control...

    Now with direct window creation...
    Code:
        Wind[1] = CreateWindowEx(WS_EX_CLIENTEDGE,L"STATIC",L"Menu",
                      WS_CHILD | WS_VISIBLE |
                      SS_CENTER | SS_CENTERIMAGE | SS_NOTIFY,
                      1,1,300,20,Wind[0],(HMENU) 100,PgmInst,NULL);
        MsgWind = Wind[1];
        // upper toolbar
        Wind[2] = CreateWindow(TOOLBARCLASSNAME,NULL,
                          WS_CHILD | WS_VISIBLE | WS_TABSTOP |
                          TBSTYLE_FLAT | TBSTYLE_TRANSPARENT | 
                          TBSTYLE_TOOLTIPS | TBSTYLE_LIST | 
                          CCS_NODIVIDER |CCS_NOPARENTALIGN | CCS_NORESIZE,
                          10,60,300,35,Wind[0],(HMENU)101,PgmInst,NULL);
        // lower toolbar
        Wind[3] = CreateWindow(TOOLBARCLASSNAME,NULL,
                          WS_CHILD | WS_VISIBLE | WS_TABSTOP |
                          TBSTYLE_FLAT | TBSTYLE_TRANSPARENT | 
                          TBSTYLE_TOOLTIPS | TBSTYLE_LIST | 
                          CCS_NODIVIDER |CCS_NOPARENTALIGN | CCS_NORESIZE,
                          10,95,300,35,Wind[0],(HMENU)102,PgmInst,NULL);
    Again, notice how WS_TABSTOP is used with each of the child windows.

    When your dispatcher loop (or the dialog's one) calls IsDialogMessage, it will look first for tabs from the keyboard, search the child windows for the next one with the WS_TABSTOP style and move input focus to that control.

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    The MSVS designer will let you set the tab order in design mode if you don't have to layout the dialog programatically.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Bubba View Post
    The MSVS designer will let you set the tab order in design mode if you don't have to layout the dialog programatically.
    True enough, most visual designers do this more or less automatically. But that is obfuscation at a grand level where things are done without understanding... IMO it's better to understand first and be more efficient later...

  8. #8
    Registered User
    Join Date
    Jan 2010
    Posts
    34
    Quote Originally Posted by CommonTater View Post
    Ok... the WS_TABSTOP is to be added to each control you want to tab to... It's a style, not a message.

    Here's an example in a .rc file (used for dialog boxes)...

    Code:
      CONTROL "", 4000, "Static", SS_CENTER|SS_CENTERIMAGE, 54, 13, 93, 12, WS_EX_STATICEDGE
      CONTROL "2100", 4001, "Edit", ES_CENTER|ES_NUMBER|WS_BORDER|WS_TABSTOP, 54, 29, 28, 12, WS_EX_CLIENTEDGE
      CONTROL "", 4002, "Edit", ES_AUTOHSCROLL|ES_PASSWORD|WS_BORDER|WS_TABSTOP, 54, 45, 93, 12, WS_EX_CLIENTEDGE
      CONTROL "10", 4003, "Edit", ES_CENTER|ES_NUMBER|WS_BORDER|WS_TABSTOP, 54, 79, 28, 12
      CONTROL "30", 4004, "Edit", ES_CENTER|ES_NUMBER|ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 54, 95, 28, 12
      CONTROL "5", 4005, "Edit", ES_CENTER|ES_NUMBER|ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 54, 111, 28, 12
      CONTROL "1000", 4006, "Edit", ES_CENTER|ES_NUMBER|ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 54, 127, 28, 12
      CONTROL "Disable Add Files mode", 4008, "Button", BS_AUTOCHECKBOX|WS_TABSTOP, 173, 14, 117, 16
      CONTROL "Allow only 1 remote per program", 4009, "Button", BS_AUTOCHECKBOX|WS_TABSTOP, 173, 34, 117, 16
      CONTROL "Disable End Program command", 4010, "Button", BS_AUTOCHECKBOX|WS_TABSTOP, 173, 54, 117, 16
    Notice how WS_TABSTOP is used with every control...

    Now with direct window creation...
    Code:
        Wind[1] = CreateWindowEx(WS_EX_CLIENTEDGE,L"STATIC",L"Menu",
                      WS_CHILD | WS_VISIBLE |
                      SS_CENTER | SS_CENTERIMAGE | SS_NOTIFY,
                      1,1,300,20,Wind[0],(HMENU) 100,PgmInst,NULL);
        MsgWind = Wind[1];
        // upper toolbar
        Wind[2] = CreateWindow(TOOLBARCLASSNAME,NULL,
                          WS_CHILD | WS_VISIBLE | WS_TABSTOP |
                          TBSTYLE_FLAT | TBSTYLE_TRANSPARENT | 
                          TBSTYLE_TOOLTIPS | TBSTYLE_LIST | 
                          CCS_NODIVIDER |CCS_NOPARENTALIGN | CCS_NORESIZE,
                          10,60,300,35,Wind[0],(HMENU)101,PgmInst,NULL);
        // lower toolbar
        Wind[3] = CreateWindow(TOOLBARCLASSNAME,NULL,
                          WS_CHILD | WS_VISIBLE | WS_TABSTOP |
                          TBSTYLE_FLAT | TBSTYLE_TRANSPARENT | 
                          TBSTYLE_TOOLTIPS | TBSTYLE_LIST | 
                          CCS_NODIVIDER |CCS_NOPARENTALIGN | CCS_NORESIZE,
                          10,95,300,35,Wind[0],(HMENU)102,PgmInst,NULL);
    Again, notice how WS_TABSTOP is used with each of the child windows.

    When your dispatcher loop (or the dialog's one) calls IsDialogMessage, it will look first for tabs from the keyboard, search the child windows for the next one with the WS_TABSTOP style and move input focus to that control.
    hey mate I did the same thing,but I see it tabs only in 1 control when it goes at that edit box it won't tab to the others I added WB_TABSTOP to child window that wants tabbing and basically my dispatcher loop looks like this.I find more information on WB_TABSTOP except its styles on msdn.

    I create the child windows on WM_CREATE of a normal window not dialog box or anything.
    Code:
    	while(GetMessage(&Msg,hHWND,NULL,NULL) > 0){
    		if(!IsDialogMessage(hHWND,&Msg)){
    			TranslateMessage(&Msg);
    			DispatchMessage(&Msg);
    		}
    	}
    Last edited by kira_coder; 10-02-2010 at 09:59 AM.

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by kira_coder View Post
    hey mate I did the same thing,but I see it tabs only in 1 control when it goes at that edit box it won't tab to the others I added WB_TABSTOP to child window that wants tabbing and basically my dispatcher loop looks like this.I find more information on WB_TABSTOP except its styles on msdn.

    I create the child windows on WM_CREATE of a normal window not dialog box or anything.
    Code:
    	while(GetMessage(&Msg,hHWND,NULL,NULL) > 0){
    		if(!IsDialogMessage(hHWND,&Msg)){
    			TranslateMessage(&Msg);
    			DispatchMessage(&Msg);
    		}
    	}
    Ahhhh.... sounds like we're on a wavelength now.

    There are some windows controls --multiline edit boxes being one-- that don't support tab-out properly. This is because they use the tab character internally, you can tab in, but then you're stuck. Some will support CTRL-TAB others just leave you stranded.

    Work arounds for this include:

    Re-arranging your tab order (the order in which child windows are created)
    Removing WS_TABSTOP from the control.
    Subclassing the control and processing the tab key with GetNextDlgTabItem and SetFocus.
    Using a different control.

    It's rather inconsistent of them but it is what it is...

    Your dispatcher looks fine. There is another element you could add IsAccelerator which supports keyboard shortcuts from AcceleratorTables in your program's resources.
    Last edited by CommonTater; 10-02-2010 at 10:25 AM.

  10. #10
    Registered User
    Join Date
    Jan 2010
    Posts
    34
    ahh thanks mate.I thought when I add WB_TABSTOP it would remove handling for TAB WM_CHAR for edit box.
    I guess I have to just subclass them and use GetNextDlgTabItem and SetFocus manually to do it.

  11. #11
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by kira_coder View Post
    ahh thanks mate.I thought when I add WB_TABSTOP it would remove handling for TAB WM_CHAR for edit box.
    I guess I have to just subclass them and use GetNextDlgTabItem and SetFocus manually to do it.
    Yep, that's probably the best option if you don't care about tabbing in the edit box.

    You can also try responding to WM_GETDLGCODE in your subclass. In my experience this is a tad flakey, but still worth a try.

    WM_GETDLGCODE Message (Windows)
    Last edited by CommonTater; 10-02-2010 at 12:04 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Anyone using Windows 7?
    By Sharke in forum General Discussions
    Replies: 60
    Last Post: 07-12-2009, 08:05 AM
  2. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  3. dual boot Win XP, win 2000
    By Micko in forum Tech Board
    Replies: 6
    Last Post: 05-30-2005, 02:55 PM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  5. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM