Need a little help here about MFC and Tab Control stuff...

This is a discussion on Need a little help here about MFC and Tab Control stuff... within the Windows Programming forums, part of the Platform Specific Boards category; Hey, I finally figured out how to get a CTabCtrl to display different pages, with the use of an overridden ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155

    Question Need a little help here about MFC and Tab Control stuff...

    Hey,

    I finally figured out how to get a CTabCtrl to display different pages, with the use of an overridden CTabCtrl class. However, now I'm just a little confused as to how to fill and retrieve various controls on different tab pages.

    I've got all the dialogs that the tabs are going to display in a vector (vector<CDialog*> m_Dialogs. However, I got mixed up as to how I am supposed to fill these fields (I need to pass then the reference of a class, and there will be different classes for different dialogs). And then, how can I retrieve the dialog's data when the user presses "OK" on the main screen where the actual tab control is held?

    Because I've put all the dialogs in a vector of CDialog, all their member variables do not exist in the CDialog datatype, so I have no way of accessing them. How can I resolve this?

    I've been trying to look into this on google, but every tutorial I've come across only shows how to display different dialogs on a tab control, and not how to access the controls in the dialogs...

    Any help regarding this problem will be greatly appreciated.

    Thanks in advance,

    Guitarist809
    ~guitarist809~

  2. #2
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    Not sure if this is what you are looking for but an options dialog I made looks like this. It basically just hides the windows/controls as the different tabs are selected. Another way is to make a static window, and have the static window be the owner of all the objects/child windows you want and just hide or show the static window. As for getting the information you could use SendMessage to get whatever state you want, or text, or whatever. Don't know if any of this is relevant to you and what you're doing but it might help.
    Code:
    //Options dialog
    BOOL CALLBACK OptionsProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        HDC hDC, hdc, t_hDC;
        //PAINTSTRUCT Ps;
        //HBITMAP bmpMathTable;
        TCITEM tcitem;
        NMHDR *pNMHdr;
    
        int tabctrl[10];
    
        switch(message)
        {
            case WM_NOTIFY:
            {
                pNMHdr = (NMHDR *) lParam;
    
                if (pNMHdr->code == TCN_SELCHANGE)
                {
                    int tabnum = TabCtrl_GetCurSel((HWND)pNMHdr->hwndFrom);
    
                    hDC = GetDC(hwndTab);
    
                    if(tabnum == 0){
                        //Show these windows
                        ShowWindow(GetDlgItem(hwnd,SU_UPDATES),SW_SHOW);
                        ShowWindow(GetDlgItem(hwnd,SU_TEXT),SW_SHOW);
                        //Hide these windows
                        ShowWindow(GetDlgItem(hwnd,SU_BEEP),SW_HIDE);                    
                    }
                    if(tabnum == 1){
                        //Show these windows
                        ShowWindow(GetDlgItem(hwnd,SU_BEEP),SW_SHOW);
                        //Hide these windows
                        ShowWindow(GetDlgItem(hwnd,SU_UPDATES),SW_HIDE);
                        ShowWindow(GetDlgItem(hwnd,SU_TEXT),SW_HIDE);
    
                    }
                    
                    ReleaseDC(hwndTab, hDC);
                }
                break;
            }
            case WM_INITDIALOG:
            {
                //LOAD TABS
                
                RECT rect;
                OptionsHwnd = hwnd;
    
                //Get the size of the initial window space to work with
                GetClientRect(hwnd, &rect);
                InitCommonControls();
    
                //Create tabbed window
                hwndTab = CreateWindow(WC_TABCONTROL,"",WS_CHILD|WS_VISIBLE,
                    0,0,rect.right,rect.bottom,hwnd,NULL,
                    (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
    
                //Set up tabs
                tcitem.mask = TCIF_TEXT;
                tcitem.iImage = -1;
    
                //Create tabs
                tcitem.pszText = "Startup"; tabctrl[0] = TabCtrl_InsertItem(hwndTab, 0, &tcitem);
                tcitem.pszText = "Run Time"; tabctrl[1]= TabCtrl_InsertItem(hwndTab, 1, &tcitem);
    
                //Change tab font
                SendMessage (hwndTab,WM_SETFONT,(WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
    
                //Get the size of the tab window
                GetClientRect(hwndTab, &rect);
          
                //DONE LOADING TABS
                
                GetCurrentDirectory(GetCurrentDirectory(0,NULL)+1,startupiniDir);
                strcat(startupiniDir,"\\startup.ini");
    
                char* su_answer = new char[10];
    
                //See if automatic updates is on or off
                GetPrivateProfileString("startup","updateonstartup","no",su_answer,
                    sizeof(su_answer),startupiniDir);
                //Check automatic updates if needed
                if((strcmp("yes",su_answer)) == 0)
                    SendDlgItemMessage(hwnd,SU_UPDATES,BM_SETCHECK,BST_CHECKED,0);
    
                //Find out if BeepOnFile is set to true or false
                GetPrivateProfileString("startup","beeponfile","no",su_answer,
                    sizeof(su_answer),startupiniDir);
                //Check BeepOnFile if needed
                if((strcmp("yes",su_answer)) == 0)
                    SendDlgItemMessage(hwnd,SU_BEEP,BM_SETCHECK,BST_CHECKED,0);
    
                delete [] su_answer;
                
                ShowWindow(GetDlgItem(hwnd,SU_BEEP),SW_HIDE); //Hide run time options
            }
            break;
    
            case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case SU_DONE:
                {
                   //Do stuff
    
                    PostMessage(hwnd,WM_CLOSE,0,0);
                }
                break;
            }
            break;
    
            case WM_CLOSE:
                EndDialog(hwnd,0);
                break;
    
            default:                      /* for messages that we don't deal with */
                return false;
        }
    
        return 0;
    }
    
    
    OPT_DIALOG DIALOGEX 75,55,300,100
    STYLE WS_CAPTION|WS_MINIMIZEBOX
    CAPTION "Options"
    FONT 9, "MS Sans Serif"
    BEGIN
    
    //LTEXT               "These are the options you can select for each start up.\n",
                        //SU_TEXT,5,5,250,19
    
    AUTOCHECKBOX      "Automatically check for updates on each start up",
                        SU_UPDATES,5,28,225,10
    AUTOCHECKBOX      "Beep on start up",
                        SU_BEEP,5,28,100,10
    
    LTEXT               "Changes will take effect on next start up",SU_TEXT,5,85,135,10
    PUSHBUTTON          "Apply",SU_DONE,260,78,30,14
    
    END
    Last edited by scwizzo; 09-15-2008 at 11:39 PM.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155
    Thanks for the reply.

    That sort-of what I needed. I already got the part where the tabs switch the window (CDialog dialogs). I just need to figure out how to grab the values from those dialogs that are switched out upon switching the tab.
    ~guitarist809~

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Quote Originally Posted by guitarist809 View Post
    Thanks for the reply.

    That sort-of what I needed. I already got the part where the tabs switch the window (CDialog dialogs). I just need to figure out how to grab the values from those dialogs that are switched out upon switching the tab.
    Are the dialogs children of the TAB or the TABs parent?

    When the tab changes the dialogs can call GetParent() (repeatedly if required) to get back to the TAB ctrl (or higher).

    The trigger to do this is probably the OnKillFocus() msg.
    "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

  5. #5
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155
    Hey,

    Actually, I've completely changed the layout of the program. I learned about property pages and property sheets (total lifesavers). I've pretty much got everything under control as of now.

    Thanks for the help so far everyone!
    ~guitarist809~

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual C++ 2008 MFC Tab Control
    By guitarist809 in forum Windows Programming
    Replies: 2
    Last Post: 07-20-2008, 10:37 AM
  2. Changing focus in an MFC Application
    By rangalo in forum Windows Programming
    Replies: 2
    Last Post: 06-20-2005, 07:21 AM
  3. Custom Tab Control
    By PrivatePanic in forum Windows Programming
    Replies: 8
    Last Post: 07-19-2002, 02:23 PM
  4. Tab controls - MFC (revived)
    By Robert602 in forum Windows Programming
    Replies: 1
    Last Post: 01-22-2002, 12:32 PM
  5. Tab Control
    By Unregistered in forum Windows Programming
    Replies: 0
    Last Post: 11-03-2001, 07:32 PM

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