Tab controls - MFC (revived)

This is a discussion on Tab controls - MFC (revived) within the Windows Programming forums, part of the Platform Specific Boards category; My thread was deleted on this topic for some unknown reason so here we go again: I need to know ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Location
    England
    Posts
    121

    Tab controls - MFC (revived)

    My thread was deleted on this topic for some unknown reason so here we go again:

    I need to know how to use tab controls on the document forms of my MDI MFC app. I was getting quite close from zMan's reply, which was:
    I found the tab control quite confusing so this is what I did instead. I created separate dialog templates...one for each tab in my control. Then I created them from the OnInitialUpdate() virtual function of CMyFormView... the code goes something like this...


    in the MyFormView.h header declare the variables

    CMyPage1 m_Page1;
    CMyPage2 m_Page2;;
    CMyPage3 m_Page3;
    CPropertySheet* pSheet;


    Code:
     
    void CMyFormView::OnInitialUpdate() 
    { 
    
    
    ...this call should really be made from the OnCreate message handler 
    .... 
    CreateTabControl(); 
    
    } 
    
    void CMyFormView::CreateTabControl() 
    { 
    
    
    pPropertySheet = new CPropertySheet( "My Tab", this, 0); 
    
    pPropertySheet->AddPage( &m_Page1 ); 
    pPropertySheet->AddPage( &m_Page2 ); 
    pPropertySheet->AddPage( &m_Page3 ); 
    
    pPropertySheet->Create( this, WS_CHILD | WS_VISIBLE ); 
    
    
    //** Create a static text with the resource editor where you 
    //** would like to position your control and bind a CStatic 
    //** member to it... you must change the default idd from 
    //** IDC_STATIC to IDC_STATIC1 or something more meaningfull 
    
    CRect r; 
    m_staticPlaceHolder.GetWindowRect( &r ); 
    ScreenToClient( &r ); 
    
    
    //** reposition the window where you want it..... 
    pPropertySheet->SetWindowPos( pPropertySheet, 
    NULL, r.top, r.left, 0, 0, SWP_NOSIZE | SWP_NOZORDER ); 
    
    }

    Remember that the page members must be your own classes derived from the CPropertyPage class... to create them with the correct property settings from the resource editor insert new resource ... select DIALOG... then IDD_PROPERTYPAGE_MEDIUM.. you can always resize it... then from the class wizard create the class as you normally would for a dialog but remember to change the base class to CPropertyPage instead of CDialog.... this will add all the necessary code to get you started... and a very important point to remember is that you cannot access the property pages except for the one selected by default until they have been selected by the user or you have set the focus on the through the property sheet member SetActivePage(...)

    I hope this helps... I found this much easier to implement than the tab control.....
    My problem was that I couldnt assign a member variable to the static text control, even after renaming it to IDC_STATIC1 or IDC_TABLOC. The control didnt appear in the list of controls in the member variables section of the classwizard. Is there a way to assign a variable to a control using the parent's dialog class (CMyDialog)?

    Thanks for any help

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    223
    Here is the code that the class wizard adds when you map a static type member to a dialog member......


    add your variable inside these blocks....

    Visual C++ should show you the IDC_STATIC1 ... unless it is acting screwy or you don't have the right class selected in the ClassWizard dialog class: combo box...



    Code:
    class CMyDlg : CDialog
    {
    ....
    // Dialog Data
    	//{{AFX_DATA(CMyDlg)
    	enum { IDD = IDD_UPLOAD_DLG };
    	CStatic	m_s1;
                    
    
    	//}}AFX_DATA
    
    }
    
    
    
    void CDialog::DoDataExchange(CDataExchange* pDX)
    {
    	CDialog::DoDataExchange(pDX);
    	//{{AFX_DATA_MAP(CUploadDlg)
    	DDX_Control(pDX, IDC_STATIC1, m_s1);
    	//}}AFX_DATA_MAP
    }
    
    
    //You can also access the static control this way
    // without assigning any member variables to the control...
    ....
    CWnd* pWnd = GetDlgItem( IDC_STATIC1 );
    
    CRect r;
    pWnd->GetWindowRect( &r );
    
    ....so on so forth....
    
    or
    CRect r;
    GetDlgItem( IDC_STATIC1 )->GetWindowRect( &r );
    .....so on so forth
    I hope this helps....
    zMan

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need a little help here about MFC and Tab Control stuff...
    By guitarist809 in forum Windows Programming
    Replies: 4
    Last Post: 09-19-2008, 11:36 AM
  2. Tab Ordering of GUI Controls
    By cloudy in forum Windows Programming
    Replies: 2
    Last Post: 04-22-2006, 10:13 AM
  3. Using the VS.NET form designer with tab controls
    By bennyandthejets in forum Windows Programming
    Replies: 1
    Last Post: 07-06-2004, 01:49 AM
  4. MFC Controls and Thread Safety :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 12-06-2002, 11:36 AM
  5. WIndows programming?
    By hostensteffa in forum Windows Programming
    Replies: 7
    Last Post: 06-07-2002, 09:52 PM

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