October 28th, 2013, 09:22 AM
#1
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 wParam , LPARAM lParam )
{
CTabCtrl * pTabCtrl = ( CTabCtrl *) GetDlgItem ( IDC_TABCONTROL );
m_TabOne . Create ( IDD_TAB1 , pTabCtrl );
m_TabTow . Create ( IDD_TAB2 , pTabCtrl );
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 ( NULL , rcItem . left , rcItem . bottom + 1 , 0 , 0 , SWP_NOSIZE | SWP_NOZORDER );
m_TabOne . ShowWindow ( SW_SHOW );
CRect rcItem2 ;
pTabCtrl -> GetItemRect ( 1 , & rcItem2 );
m_TabTow . SetWindowPos ( NULL , rcItem2 . left , rcItem2 . bottom + 1 , 0 , 0 , SWP_NOSIZE | SWP_NOZORDER );
m_TabTow . ShowWindow ( SW_SHOW );
return 0 ;
}
The first tab display fine, but with some overlapse of the 2nd
October 28th, 2013, 11:30 AM
#2
Re: MFC Tab Control Problem
What are you trying to achieve? What are m_TabOne and m_TabTow ? Is there some reason to avoid using PropertySheet with PropertyPages? Please, use Code tags, not PHP ones while posting C++ code snippets!
Victor Nijegorodov
October 28th, 2013, 11:34 AM
#3
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.
October 28th, 2013, 11:57 AM
#4
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
October 28th, 2013, 12:03 PM
#5
Re: MFC Tab Control Problem
Originally Posted by
vcstarter
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
October 28th, 2013, 12:20 PM
#6
Re: MFC Tab Control Problem
It means that when tab1 is visible, the form in tab2 does not show like any other tab application
October 28th, 2013, 12:29 PM
#7
Re: MFC Tab Control Problem
Originally Posted by
vcstarter
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
October 28th, 2013, 12:42 PM
#8
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.
October 30th, 2013, 11:10 AM
#9
Re: MFC Tab Control Problem
Take a look of the project to see the overlapping
Attached Files
October 30th, 2013, 11:34 AM
#10
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
October 30th, 2013, 11:49 AM
#11
Re: MFC Tab Control Problem
Originally Posted by
vcstarter
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?
October 30th, 2013, 12:48 PM
#12
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
Forum Rules
Click Here to Expand Forum to Full Width