Need help with tabbed windows

This is a discussion on Need help with tabbed windows within the Windows Programming forums, part of the Platform Specific Boards category; I've searched everywhere, even msdn and can't find any info at all on how to use tabbed windows. What I ...

  1. #1
    *this
    Join Date
    Mar 2005
    Posts
    498

    Exclamation Need help with tabbed windows

    I've searched everywhere, even msdn and can't find any info at all on how to use tabbed windows.

    What I want to do is when the user clicks a tab, the tab window changes the client area to a different child window.

    I just want to know how to change the area below the tabs (client area) to a child window I create separately so I can utilize the child windows default procedure.

    Someone please help me.

    Here is my code:
    Code:
    #include <windows.h>
    #include <commctrl.h>
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
    
    /* Global variables */
    const int WINSIZEX = 400;
    const int WINSIZEY = 300;
    HWND hwnd, hwndTab, hwndStatus;
    /* End global variables */
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                              PSTR szCmdLine, int iCmdShow) 
    {
        static TCHAR* szAppName = TEXT("PeaMain");
        MSG            msg;
        WNDCLASS        wndclass;
        
        // For main window named "PeaMain"
        wndclass.style                = CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc        = WndProc;
        wndclass.cbClsExtra         = 0;
        wndclass.cbWndExtra        = 0;
        wndclass.hInstance        = hInstance;
        wndclass.hIcon                = LoadIcon (NULL, IDI_APPLICATION);
        wndclass.hCursor            = LoadCursor (NULL, IDC_ARROW);
        wndclass.hbrBackground    = (HBRUSH) GetStockObject (WHITE_BRUSH);
        wndclass.lpszMenuName     = NULL;
        wndclass.lpszClassName     = szAppName;
        
        // If we can't register the class, return an error
        if (!RegisterClass (&wndclass)) 
        {
            MessageBox (NULL, TEXT("ERROR This Program Requries NT!"), 
                            szAppName, MB_ICONERROR);
            return 0;
        }
    
        // Create main window
        hwnd = CreateWindowEx (WS_EX_ACCEPTFILES,
                                      szAppName, TEXT("Pea - Encryption / Decryption"), 
                                      WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | 
                                      WS_BORDER | WS_MINIMIZEBOX,
                                      CW_USEDEFAULT, CW_USEDEFAULT, WINSIZEX, WINSIZEY,
                                      NULL, NULL, hInstance, NULL);
        
        ShowWindow (hwnd, iCmdShow);
        UpdateWindow (hwnd);
        
        while (GetMessage (&msg, NULL, 0, 0)) 
        {
            TranslateMessage (&msg);
            DispatchMessage (&msg);
        }
        
        return msg.wParam;
    }
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 
    {
        PAINTSTRUCT ps;
        TCITEM tcitem;
        RECT rect;
        HDC hdc;
        
       switch (message)
        {
            case WM_CREATE:    
                // Set up for tabbed window             
                GetClientRect (hwnd, &rect);
                InitCommonControls();             
                
                // Create tabbed window
                hwndTab = CreateWindow (WC_TABCONTROL, "",
                           WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, 
                             0, 0, rect.right + 2, rect.bottom, hwnd, NULL,
                             (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
                
                // Create the status window
                hwndStatus = CreateWindowEx (WS_EX_DLGMODALFRAME, STATUSCLASSNAME, "",
                                 WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 
                          0, 0, 0, 0, hwnd, NULL, 
                                 (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
                                 
                // Set the text on the status window                 
                SendMessage (hwndStatus, SB_SETTEXT, 0, (LPARAM) TEXT("Standby"));    
                
                // Set up tabs             
                tcitem.mask = TCIF_TEXT;
                
                // Create tabs
                tcitem.pszText = "Main"; 
                TabCtrl_InsertItem(hwndTab, 0, &tcitem); 
                tcitem.pszText = "Encrypt"; 
                TabCtrl_InsertItem(hwndTab, 1, &tcitem); 
                tcitem.pszText = "Decrypt"; 
                TabCtrl_InsertItem(hwndTab, 2, &tcitem); 
                tcitem.pszText = "About"; 
                TabCtrl_InsertItem(hwndTab, 3, &tcitem); 
                
                // Change tab font
                SendMessage (hwndTab, WM_SETFONT, 
                                 (WPARAM) GetStockObject (DEFAULT_GUI_FONT), 0);     
                return 0;
                
            case WM_CLOSE:
                PostQuitMessage (0);
                return 0;
        }
        return DefWindowProc (hwnd, message, wParam, lParam);
    }
    Last edited by JoshR; 07-30-2005 at 09:50 PM.

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Just keep an array with handles to the child windows.
    The window for the first tab is at position 0, and so on.
    When the user clicks a tab, you process the TCN_SELCHANGE message to set the active tab.

  3. #3
    *this
    Join Date
    Mar 2005
    Posts
    498
    But how would I set the active tab. I can't find the function that sets focus to a certain child window inside the tabbed client area.

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    TCM_SETCURFOCUS

  5. #5
    *this
    Join Date
    Mar 2005
    Posts
    498
    Ok now that we have the focus settled, how do I make each tabs client area use a different child window?

    I know you mentioned an array, but I still am confused about how I would get the window to be displayed inside the tabs client area.

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Set the tabctrl as the childs parent, and use ShowWindow() to show hide the correct window.

  7. #7
    *this
    Join Date
    Mar 2005
    Posts
    498
    thanks a BUNCH! your a life saver!

    Code is smoother than a babies bottom

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  2. dual boot Win XP, win 2000
    By Micko in forum Tech Board
    Replies: 6
    Last Post: 05-30-2005, 02:55 PM
  3. Tabbed Windows with MDI?
    By willc0de4food in forum Windows Programming
    Replies: 25
    Last Post: 05-19-2005, 10:58 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

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