Newbie question on tab controls

This is a discussion on Newbie question on tab controls within the Windows Programming forums, part of the Platform Specific Boards category; I'm developing an MDI app in MFC and I want to add tabs along the top of the child windows ...

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

    Question Newbie question on tab controls

    I'm developing an MDI app in MFC and I want to add tabs along the top of the child windows (I havent changed the child windows themselves since the AppWizard set them up). I have got as far as drawing a tab control in the resource editor, the tabs are named tab1 - tab5. When compiling the tabs arent there, there is just a big 3d box where they should be, and how do I select the tabs from within VC++6 to change what is in each one.

    I've looked through Petzold and some websites but everywhere seems to assume you can physically draw the controls in the resource editor, I cant work it out .

    Help appreciated

  2. #2
    Unregistered
    Guest
    from msdn:

    After creating the tab control (CTabCtrl), add as many tabs as you need.

    To add a tab item

    Prepare a TCITEM structure.


    Call CTabCtrl::InsertItem, passing the structure.


    Repeat steps 1 and 2 for additional tab items.
    For more information, see Creating a Tab Control in the Platform SDK.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    223

    tab controls embedded in Form

    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 );

    }

    CODE]

    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.....
    zMan

  4. #4
    Registered User
    Join Date
    Sep 2001
    Location
    England
    Posts
    121
    Thanks zMan I'm almost there, but I cant seem to attach a member variable to the static control, even after renaming it, it doesnt appear in the list of controls in the classwizard.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  2. Newbie with Very Newbie Question
    By Jedi_Mediator in forum C++ Programming
    Replies: 18
    Last Post: 07-01-2008, 08:00 AM
  3. newbie: array question :(
    By cstudent in forum C Programming
    Replies: 2
    Last Post: 04-09-2008, 06:46 AM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. Tab controls - MFC (revived)
    By Robert602 in forum Windows Programming
    Replies: 1
    Last Post: 01-22-2002, 11:32 AM

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