MFC questions
-
Hi, 1. I have put a TabControl inside a formview in the MFC-SDI application. If I resize the window I want the tab control to always fit in the window (that means if I make the window bigger the control inside will become bigger and if I make the window smaller I want the control to get smaller). Please advise how I can do that? 2. How can I make a SDI application non-resizable? Thanks,
-
Hi, 1. I have put a TabControl inside a formview in the MFC-SDI application. If I resize the window I want the tab control to always fit in the window (that means if I make the window bigger the control inside will become bigger and if I make the window smaller I want the control to get smaller). Please advise how I can do that? 2. How can I make a SDI application non-resizable? Thanks,
Add a
WM_SIZE
handler in your view class. In it, do the following:CRect rectView;
GetClientRect (&rectView);
m_tabCtrl.MoveWindow (&rectView);This will cause the tab control to fill the view's client area. /ravi My new year resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com
-
Add a
WM_SIZE
handler in your view class. In it, do the following:CRect rectView;
GetClientRect (&rectView);
m_tabCtrl.MoveWindow (&rectView);This will cause the tab control to fill the view's client area. /ravi My new year resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com
-
I used following code Onsize but I'm getting asserting error at line 279 of winocc.cpp CFormView::OnSize(nType, cx, cy); CRect rectView; GetClientRect (&rectView); m_TabCtrl.MoveWindow (&rectView);
Perhaps you haven't linked
m_tabCtrl
to the tab control in the dialog template? Put this line before the call toMoveWindow()
:ASSERT (m_tabCtrl.GetSafeHwnd() != NULL);
to ensure that
m_tabCtrl
has been properly created before you try to resize it. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com -
Perhaps you haven't linked
m_tabCtrl
to the tab control in the dialog template? Put this line before the call toMoveWindow()
:ASSERT (m_tabCtrl.GetSafeHwnd() != NULL);
to ensure that
m_tabCtrl
has been properly created before you try to resize it. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.comIt worked. Thanks.... I have another similar question :-) I have two tree controls attached to the tabs in the tab control. To fit the tree control in the tab control what should I do? 'cause I can't write the wm_size handler for the tabcontrol as I'm adding the tree controls in the formview, not in the tabcontrol class.
-
It worked. Thanks.... I have another similar question :-) I have two tree controls attached to the tabs in the tab control. To fit the tree control in the tab control what should I do? 'cause I can't write the wm_size handler for the tabcontrol as I'm adding the tree controls in the formview, not in the tabcontrol class.
I think you might be confusing a
CTabCtrl
with aCPropertySheet
. ACTabCtrl
doesn't "contain" child dialogs or controls - all it does is allow the user to select a tab. A tab control's parent receives notifications when the current tab selection changes. That being said, what you probably want to do (to mimic the behavior of aCPropertySheet
) is to create a bunch of child controls/dialogs (whose common parent is your view), one of which is displayed in response to the change in the currently selected tab. You'll also need to check the "Transparent" attribute of the tab control so that it doesn't hide the child controls/dialogs. The appropriate control/dialog is displayed in response to a change in the currently selected tab in the following manner:// First hide all controls
CWnd* pDisplayedWnd = NULL;
m_treeCtrl_1.ShowWindow (SW_HIDE);
m_treeCtrl_2.ShowWindow (SW_HIDE);// Next, determine which one should be shown
int nCurTab = m_tabCtrl.GetCurSel();
switch (nCurTab) {
case 0:
pDisplayedWnd = &m_treeCtrl_1;
break;
case 1:
pDisplayedWnd = &m_treeCtrl_2;
break;
default:
// Did you forget to support a tab?
ASSERT (FALSE);
break;
}
ASSERT (pDisplayedWnd != NULL);// Display the control
pDisplayedWnd->BringWindowToTop();
pDisplayedWnd->ShowWindow (SW_SHOW);
pDisplayedWnd->Invalidate();
pDisplayedWnd->UpdateWindow();
pDisplayedWnd->BringWindowToTop();
pDisplayedWnd->SetFocus();If this is too much work, you might want to consider using a
CPropertySheet
. See the examples at CP if you need help. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com -
It worked. Thanks.... I have another similar question :-) I have two tree controls attached to the tabs in the tab control. To fit the tree control in the tab control what should I do? 'cause I can't write the wm_size handler for the tabcontrol as I'm adding the tree controls in the formview, not in the tabcontrol class.
Don't forget to call
SetScaleToFitSize(cx, cy)
at he end of your OnSize() procedure otherwise you will get scroll bars shown if the client rectangle size is smaller than the size of the dialog template used to create the form view from. Roger Allen - Sonork 100.10016 Roger Wright: Remember to buckle up, please, and encourage your friends to do the same. It's not just about saving your life, but saving the quality of life for those you may leave behind... -
Don't forget to call
SetScaleToFitSize(cx, cy)
at he end of your OnSize() procedure otherwise you will get scroll bars shown if the client rectangle size is smaller than the size of the dialog template used to create the form view from. Roger Allen - Sonork 100.10016 Roger Wright: Remember to buckle up, please, and encourage your friends to do the same. It's not just about saving your life, but saving the quality of life for those you may leave behind... -
Don't forget to call
SetScaleToFitSize(cx, cy)
at he end of your OnSize() procedure otherwise you will get scroll bars shown if the client rectangle size is smaller than the size of the dialog template used to create the form view from. Roger Allen - Sonork 100.10016 Roger Wright: Remember to buckle up, please, and encourage your friends to do the same. It's not just about saving your life, but saving the quality of life for those you may leave behind...