CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Jun 2002
    Posts
    936

    MFC Tab Control Problem

    I tried to display a tab, but it looks like I make some mistake in the initialization; see the code below

    PHP Code:
    afx_msg LRESULT CDisplayData::OnInitdialog(WPARAM wParamLPARAM lParam)
    {
        
    CTabCtrl *pTabCtrl = (CTabCtrl*)GetDlgItem(IDC_TABCONTROL);
        
    m_TabOne.Create(IDD_TAB1pTabCtrl);
        
    m_TabTow.Create(IDD_TAB2pTabCtrl);

        
    TCITEM item1;
        
    TCITEM item2;
        
    item1.mask TCIF_TEXT TCIF_PARAM;
        
    item1.lParam = (LPARAM)& m_TabOne;
        
    item2.lParam = (LPARAM)& m_TabTow;
        
    item1.pszText _T("Tab1 Page 1");
        
    item2.pszText _T("Tab2 Page 2");
        
    pTabCtrl->InsertItem(0, &item1);
        
    pTabCtrl->InsertItem(1, &item2);

        
    CRect rcItem;
        
    pTabCtrl->GetItemRect(0, &rcItem);
        
    m_TabOne.SetWindowPos(NULLrcItem.leftrcItem.bottom 100SWP_NOSIZE SWP_NOZORDER);
        
    m_TabOne.ShowWindow(SW_SHOW);

        
    CRect rcItem2;
        
    pTabCtrl->GetItemRect(1, &rcItem2);
        
    m_TabTow.SetWindowPos(NULLrcItem2.leftrcItem2.bottom 100SWP_NOSIZE SWP_NOZORDER);
        
    m_TabTow.ShowWindow(SW_SHOW);

        return 
    0;

    The first tab display fine, but with some overlapse of the 2nd

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: MFC Tab Control Problem

    1. What are you trying to achieve?
    2. What are m_TabOne and m_TabTow?
    3. Is there some reason to avoid using PropertySheet with PropertyPages?
    4. Please, use Code tags, not PHP ones while posting C++ code snippets!
    Victor Nijegorodov

  3. #3
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,721

    Re: MFC Tab Control Problem

    Also, why are you showing both dialogs ? Should only one be visible (SW_SHOW) ?
    And then when the tab selection changes ... get the current tab, show/hide the appropriate
    dialogs.

  4. #4
    Join Date
    Jun 2002
    Posts
    936

    Re: MFC Tab Control Problem

    I tried to show one at a time. The idea is to show one tab at a time similar to C# winform

    m_TabOne member variable first table

    m_TabTow member variable second tab

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: MFC Tab Control Problem

    Quote Originally Posted by vcstarter View Post
    I tried to show one at a time. The idea is to show one tab at a time similar to C# winform
    I have no idea what "similar to C# winform" means...
    Victor Nijegorodov

  6. #6
    Join Date
    Jun 2002
    Posts
    936

    Re: MFC Tab Control Problem

    It means that when tab1 is visible, the form in tab2 does not show like any other tab application

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: MFC Tab Control Problem

    Quote Originally Posted by vcstarter View Post
    It means that when tab1 is visible, the form in tab2 does not show like any other tab application
    Then why are you trying to show both m_TabOne and m_TabTow dialogs simultaneously?
    And how does this behavior differ from the standard PropertySheet/PropertyPage ones?
    So, again: Is there some reason to avoid using PropertySheet with PropertyPages?
    Victor Nijegorodov

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: MFC Tab Control Problem

    There's a couple of options when dealing with tabs and it boils down to convenience of the layout of the controls on each tab.

    If you only have a couple of controls on each tab 'page', then you can use a tab control and put all the controls on the dialog. The tab control is then used to hide/show the appropriate controls when each tab is selected. Now keep in mind using this approach all the controls for every tab is on the same dialog and there aren't any tab 'pages' so dialog editor layout is a pain when there are many controls.

    So if you have more than a couple of controls per tab, a better approach is to use a property sheet/pages. Here, each tab is a separate prop page which is a child dialog and you manage the layout of the controls on each page with the dialog editor.

    Btw, as an aside, the GetDlgItem(...) approach is kind of dated. Instead create a control variable for each control you need to track.

  9. #9
    Join Date
    Jun 2002
    Posts
    936

    Re: MFC Tab Control Problem

    Take a look of the project to see the overlapping
    Attached Files Attached Files

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: MFC Tab Control Problem

    1. Please, fix the following problems with the solution you have posted:
    Code:
      TestRibbonView.cpp
    c:\documents and settings\victor\my documents\visual studio 2010\projects\testribbon\testribbon\displaydata.h(3): warning C4067: unexpected tokens following preprocessor directive - expected a newline
    c:\documents and settings\victor\my documents\visual studio 2010\projects\testribbon\testribbon\displaydata.h(4): warning C4067: unexpected tokens following preprocessor directive - expected a newline
    c:\documents and settings\victor\my documents\visual studio 2010\projects\testribbon\testribbon\testribbonview.cpp(43): error C2065: 'ID_BUTTON2' : undeclared identifier
    c:\documents and settings\victor\my documents\visual studio 2010\projects\testribbon\testribbon\testribbonview.cpp(43): error C2065: 'ID_BUTTON2' : undeclared identifier
      ...
      TestRibbon.cpp
    c:\documents and settings\victor\my documents\visual studio 2010\projects\testribbon\testribbon\testribbon.cpp(198): error C2065: 'ID_CHECK2' : undeclared identifier
    c:\documents and settings\victor\my documents\visual studio 2010\projects\testribbon\testribbon\testribbon.cpp(198): error C2065: 'ID_CHECK2' : undeclared identifier
      ...
      DisplayData.cpp
    c:\documents and settings\victor\my documents\visual studio 2010\projects\testribbon\testribbon\displaydata.h(3): warning C4067: unexpected tokens following preprocessor directive - expected a newline
    c:\documents and settings\victor\my documents\visual studio 2010\projects\testribbon\testribbon\displaydata.h(4): warning C4067: unexpected tokens following preprocessor directive - expected a newline
    2. Please, remove .aps file from your .zip
    Victor Nijegorodov

  11. #11
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: MFC Tab Control Problem

    Quote Originally Posted by vcstarter View Post
    Take a look of the project to see the overlapping
    What overlapping? What are we looking at? I see several dialog resources named dialog and tab and the hard way of trying to make a property sheet with pages. What are you trying to do?

  12. #12
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: MFC Tab Control Problem

    This is what it should look like:
    Code:
    LRESULT CDisplayData::OnInitdialog(WPARAM wParam, LPARAM lParam)
    {
    	CTabCtrl *pTabCtrl = (CTabCtrl*)GetDlgItem(IDC_TABCONTROL);
    	m_TabOne.Create(IDD_TAB1, this);
    	m_TabTow.Create(IDD_TAB2, this);
    
    	TCITEM item1;
    	TCITEM item2;
    	item1.mask = item2.mask = TCIF_TEXT | TCIF_PARAM;
    	item1.lParam = (LPARAM)& m_TabOne;
    	item2.lParam = (LPARAM)& m_TabTow;
    	item1.pszText = _T("Tab1 Page 1");
    	item2.pszText = _T("Tab2 Page 2");
    	pTabCtrl->InsertItem(0, &item1);
    	pTabCtrl->InsertItem(1, &item2);
    
    	CRect rcItem, rcClient;
    	pTabCtrl->GetClientRect(rcClient);
    	pTabCtrl->GetItemRect(0, rcItem);
    	rcClient.top += rcItem.Height();
    	rcClient.DeflateRect(3, 4);
    	pTabCtrl->MapWindowPoints(this, rcClient);
    	m_TabOne.SetWindowPos(pTabCtrl, rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), 0);
    	m_TabOne.ShowWindow(SW_SHOW);
    
    	m_TabTow.SetWindowPos(pTabCtrl, rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), 0);
    	m_TabTow.ShowWindow(SW_HIDE);
    
    	return TRUE;
    }
    
    
    void CDisplayData::OnTcnSelchangeTabcontrol(NMHDR *pNMHDR, LRESULT *pResult)
    {
    	CTabCtrl *pTabCtrl = (CTabCtrl*)GetDlgItem(IDC_TABCONTROL);
    	int count = pTabCtrl->GetItemCount();
    	int sel   = pTabCtrl->GetCurSel();
    	for (int idx = 0; idx < count; idx++)
    	{
    		TCITEM item;
    		pTabCtrl->GetItem(idx, &item);
    		((CWnd*)item.lParam)->ShowWindow(idx == sel ? SW_SHOW : SW_HIDE);
    	}
    
    	*pResult = 0;
    }
    Last edited by Igor Vartanov; October 30th, 2013 at 05:27 PM.
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured