Click to See Complete Forum and Search --> : Resizing CTabCtrl in a CFormView


joacim
August 3rd, 1999, 08:58 AM
Hi!

I have a CTabCtrl in a CFormView. When user resizes the view I want to resize CTabCtrl to fit in view.

How can I do this?

Regards
Joacim

ChrisD
August 3rd, 1999, 09:20 AM
Add a handler in your formview for WM_SIZE, when WM_SIZE is called the window has been sized and you can adjust your tacctrl accordingly.

ex:
void ExplorerView::OnSize(UINT nType, int cx, int cy)
{
OLIFormView::OnSize(nType, cx, cy);
if (tabCtrl.GetSafeHwnd()) // On size can be called before your tabCtrl is subclassed
{

tabCtrl.MoveWindow(5,5, cx - 10, cy - 10);
}

joacim
August 3rd, 1999, 10:14 AM
Hi!
My question was a little missleading......

I use the ResourceEditor to place tabctrl in the form and have some space above tabctrl. When I use your code it takes all the screen.
How can I keep the upper-left corner fixed and change position of lower-right corner?

Thanks anyway for your code!

Regards
Joacim

ChrisD
August 3rd, 1999, 12:03 PM
void ExplorerView::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
CRect rc;
tabCtrl.GetWindowRect(rc); // Position in Screnn units
ScreenToClient(rc); // convert to client units
if (tabCtrl.GetSafeHwnd()) // On size can be called before your tabCtrl is subclassed
{

// this holds upper left to a specific pos if you need to keep right side
// save original window rect (both tabCtrl & dialog) in OnInitDialog
// & then compare right/bottom margin gap & set set gap here
tabCtrl.MoveWindow(rc.left,rc.top, cx - 10, cy - 10);
}

HTH,
Chris

August 3rd, 1999, 12:07 PM
void CFormTestView::OnSize(UINT nType,int cx,int cy)
{
CFormView::OnSize(nType,cx,cy);

CWnd* pWnd=GetDlgItem(IDC_TAB1) // get tab control
if (pWnd) // make sure the tab control has already been created (possible it hasn't)
{
CRect rect;
pWnd->GetWindowRect(rect); // get position of tab control relative to the upper left corner of the screen
ScreenToClient(rect); // translate tab position relative to the upper left corner of the view
rect.right=cx-(rect.left*2); // make right hand margin betwee the tab and frame the same size as the left hand margin.
// leave the vertical and left hand placement alone. You can perform what ever calculations
// to determine new position here.
pWnd->MoveWindow(rect); // Move the tab control to it's new position
}
}

joacim
August 4th, 1999, 05:47 AM
Thanks, it work fine after some small changes.
I did this changes:
[ccode]
rect.right = cx-rect.left;
rect.bottom = cy-10;
[ccode]

Regards
Joacim