dkloeck
asked on
Resize Problem
I try to put a TabCtrl in a Window, & an embedded window in each tab of the tabctrl..
this is my code of the used funktions for this:
BOOL CWinlinx2Dlg::OnInitDialog ()
{
CDialog::OnInitDialog();
// Hinzufügen des Menübefehls "Info..." zum Systemmenü.
// IDM_ABOUTBOX muss sich im Bereich der Systembefehle befinden.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(ID S_ABOUTBOX );
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SE PARATOR);
pSysMenu->AppendMenu(MF_ST RING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Symbol für dieses Dialogfeld festlegen. Wird automatisch erledigt
// wenn das Hauptfenster der Anwendung kein Dialogfeld ist
SetIcon(m_hIcon, TRUE); // Großes Symbol verwenden
SetIcon(m_hIcon, FALSE); // Kleines Symbol verwenden
ShowWindow(SW_MAXIMIZE);
// TODO: Hier zusätzliche Initialisierung einfügen
//Passt das TabCtrl an das Fenster an
CRect rect;
this->GetClientRect(&rect) ;
TabCtrl.AdjustRect(false,r ect);
TabCtrl.MoveWindow(rect.le ft,rect.to p,rect.Wid th(),rect. Height()*6 /7, true);
//Passt das TaskCtrl an das Fenster an
CRect rect3;
TabCtrl.GetWindowRect(&rec t3);
TaskCtrl.MoveWindow(rect.l eft,rect.t op+rect3.H eight()+3, rect.Width ()-2,
rect.Height()/7, true);
//Gibt die Tabs ein
TabCtrl.InsertItem(0,"Fläc henmanager ");
TabCtrl.InsertItem(1,"Pers onal");
TabCtrl.InsertItem(2,"Inve ntar");
TabCtrl.InsertItem(3,"Vert ragsmanage ment");
TabCtrl.InsertItem(4,"Fina nz Übersicht");
TabCtrl.InsertItem(5,"Gefa hrstoffe") ;
//Gibt die Titel der Spalten an
CRect rect2;
TaskCtrl.GetClientRect(&re ct2);
TaskCtrl.InsertColumn(0, _T("Beschreibung"), LVCFMT_LEFT, rect2.Width()*5/6);
TaskCtrl.InsertColumn(1, _T("Datum"), LVCFMT_LEFT, rect2.Width()/6);
// Initial extended style für TaskManager
DWORD dwStyle = TaskCtrl.GetExtendedStyle( );
dwStyle |= LVS_EX_GRIDLINES|LVS_EX_FU LLROWSELEC T|LVS_EX_C HECKBOXES;
TaskCtrl.SetExtendedStyle( dwStyle);
//Creates the dialogs
VERIFY(D1.Create(CDlg1::ID D, this));
VERIFY(D2.Create(CDlg2::ID D, this));
VERIFY(D3.Create(CDlg3::ID D, this));
VERIFY(D4.Create(CDlg4::ID D, this));
VERIFY(D5.Create(CDlg5::ID D, this));
VERIFY(D6.Create(CDlg6::ID D, this));
//Zeigt ein Dialoge
D1.ShowWindow(SW_SHOW);
D2.ShowWindow(SW_HIDE);
D3.ShowWindow(SW_HIDE);
D4.ShowWindow(SW_HIDE);
D5.ShowWindow(SW_HIDE);
D6.ShowWindow(SW_HIDE);
CRect ClientRect,TabItemRect;
TabCtrl.GetClientRect(&Cli entRect);
TabCtrl.GetItemRect(0,&Tab ItemRect);
D1.SetWindowPos(NULL,Clien tRect.left +10,Client Rect.top+
TabItemRect.Height()+10,Cl ientRect.W idth()-10,
ClientRect.Height()-TabIte mRect.Heig ht()-10,SW P_NOZORDER );
return TRUE; // Geben Sie TRUE zurück, außer ein Steuerelement soll den Fokus erhalten
}
void CWinlinx2Dlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(TabCtrl.m_hWnd == NULL)
return; // Das Fenster ist noch nicht erschaffen.
//Passt das TabCtrl an das Fenster an
CRect rect;
CWinlinx2Dlg::GetClientRec t(&rect);
TabCtrl.AdjustRect(false,r ect);
TabCtrl.MoveWindow(rect.le ft,rect.to p,rect.Wid th(),rect. Height()*6 /7, true);
//Passt das TaskCtrl an das Fenster an
CRect rect3;
TabCtrl.GetWindowRect(&rec t3);
TaskCtrl.MoveWindow(rect.l eft,rect.t op+rect3.H eight()+3, rect.Width ()-2,
rect.Height()/7, true);
//Passt die Spalten an die Fenster Größe an
CRect rect2;
TaskCtrl.GetClientRect(&re ct2);
TaskCtrl.SetColumnWidth(0, rect2.Widt h()*5/6);
TaskCtrl.SetColumnWidth(1, LVSCW_AUTO SIZE_USEHE ADER);
//D1 is not yet a window
if ( NULL == D1.m_hWnd || FALSE == ::IsWindow( D1.m_hWnd ) )
{
return;
}
//Passt die Dialoge an die TabClient window an
CRect ClientRect,TabItemRect;
TabCtrl.GetClientRect(&Cli entRect);
D1.SetWindowPos(NULL,Clien tRect.left +10,Client Rect.top+
TabItemRect.Height()+10,Cl ientRect.W idth()-10,
ClientRect.Height()-TabIte mRect.Heig ht()-10,SW P_NOZORDER );
}
The problemm is that the elements of that dialog are resizesed in a diferent way in init dialog & in onresize...
I want that the aspekt of the window in OnResize is the same as in initdialog (smaller or larger...but the same proportions). Why douesnt it make the same in OnSize as in InitDlg??
HELLP!!!
this is my code of the used funktions for this:
BOOL CWinlinx2Dlg::OnInitDialog
{
CDialog::OnInitDialog();
// Hinzufügen des Menübefehls "Info..." zum Systemmenü.
// IDM_ABOUTBOX muss sich im Bereich der Systembefehle befinden.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(ID
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SE
pSysMenu->AppendMenu(MF_ST
}
}
// Symbol für dieses Dialogfeld festlegen. Wird automatisch erledigt
// wenn das Hauptfenster der Anwendung kein Dialogfeld ist
SetIcon(m_hIcon, TRUE); // Großes Symbol verwenden
SetIcon(m_hIcon, FALSE); // Kleines Symbol verwenden
ShowWindow(SW_MAXIMIZE);
// TODO: Hier zusätzliche Initialisierung einfügen
//Passt das TabCtrl an das Fenster an
CRect rect;
this->GetClientRect(&rect)
TabCtrl.AdjustRect(false,r
TabCtrl.MoveWindow(rect.le
//Passt das TaskCtrl an das Fenster an
CRect rect3;
TabCtrl.GetWindowRect(&rec
TaskCtrl.MoveWindow(rect.l
rect.Height()/7, true);
//Gibt die Tabs ein
TabCtrl.InsertItem(0,"Fläc
TabCtrl.InsertItem(1,"Pers
TabCtrl.InsertItem(2,"Inve
TabCtrl.InsertItem(3,"Vert
TabCtrl.InsertItem(4,"Fina
TabCtrl.InsertItem(5,"Gefa
//Gibt die Titel der Spalten an
CRect rect2;
TaskCtrl.GetClientRect(&re
TaskCtrl.InsertColumn(0, _T("Beschreibung"), LVCFMT_LEFT, rect2.Width()*5/6);
TaskCtrl.InsertColumn(1, _T("Datum"), LVCFMT_LEFT, rect2.Width()/6);
// Initial extended style für TaskManager
DWORD dwStyle = TaskCtrl.GetExtendedStyle(
dwStyle |= LVS_EX_GRIDLINES|LVS_EX_FU
TaskCtrl.SetExtendedStyle(
//Creates the dialogs
VERIFY(D1.Create(CDlg1::ID
VERIFY(D2.Create(CDlg2::ID
VERIFY(D3.Create(CDlg3::ID
VERIFY(D4.Create(CDlg4::ID
VERIFY(D5.Create(CDlg5::ID
VERIFY(D6.Create(CDlg6::ID
//Zeigt ein Dialoge
D1.ShowWindow(SW_SHOW);
D2.ShowWindow(SW_HIDE);
D3.ShowWindow(SW_HIDE);
D4.ShowWindow(SW_HIDE);
D5.ShowWindow(SW_HIDE);
D6.ShowWindow(SW_HIDE);
CRect ClientRect,TabItemRect;
TabCtrl.GetClientRect(&Cli
TabCtrl.GetItemRect(0,&Tab
D1.SetWindowPos(NULL,Clien
TabItemRect.Height()+10,Cl
ClientRect.Height()-TabIte
return TRUE; // Geben Sie TRUE zurück, außer ein Steuerelement soll den Fokus erhalten
}
void CWinlinx2Dlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(TabCtrl.m_hWnd == NULL)
return; // Das Fenster ist noch nicht erschaffen.
//Passt das TabCtrl an das Fenster an
CRect rect;
CWinlinx2Dlg::GetClientRec
TabCtrl.AdjustRect(false,r
TabCtrl.MoveWindow(rect.le
//Passt das TaskCtrl an das Fenster an
CRect rect3;
TabCtrl.GetWindowRect(&rec
TaskCtrl.MoveWindow(rect.l
rect.Height()/7, true);
//Passt die Spalten an die Fenster Größe an
CRect rect2;
TaskCtrl.GetClientRect(&re
TaskCtrl.SetColumnWidth(0,
TaskCtrl.SetColumnWidth(1,
//D1 is not yet a window
if ( NULL == D1.m_hWnd || FALSE == ::IsWindow( D1.m_hWnd ) )
{
return;
}
//Passt die Dialoge an die TabClient window an
CRect ClientRect,TabItemRect;
TabCtrl.GetClientRect(&Cli
D1.SetWindowPos(NULL,Clien
TabItemRect.Height()+10,Cl
ClientRect.Height()-TabIte
}
The problemm is that the elements of that dialog are resizesed in a diferent way in init dialog & in onresize...
I want that the aspekt of the window in OnResize is the same as in initdialog (smaller or larger...but the same proportions). Why douesnt it make the same in OnSize as in InitDlg??
HELLP!!!
ASKER
But why with this code:
void CWinlinx2Dlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(TabCtrl.m_hWnd == NULL)
return; // Das Fenster ist noch nicht erschaffen.
//Passt das TabCtrl an das Fenster an
CRect rect;
CWinlinx2Dlg::GetClientRec t(&rect);
TabCtrl.AdjustRect(false,r ect);
TabCtrl.MoveWindow(rect.le ft,rect.to p,rect.Wid th(),rect. Height()*6 /7, true);
}
the TabCtrl dont have the same look as in OnInitDlg, what is wrong?
void CWinlinx2Dlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(TabCtrl.m_hWnd == NULL)
return; // Das Fenster ist noch nicht erschaffen.
//Passt das TabCtrl an das Fenster an
CRect rect;
CWinlinx2Dlg::GetClientRec
TabCtrl.AdjustRect(false,r
TabCtrl.MoveWindow(rect.le
}
the TabCtrl dont have the same look as in OnInitDlg, what is wrong?
Try
TabCtrl.AdjustRect(FALSE, &rect);
// Move the tab control to the new position and size.
TabCtrl.MoveWindow(&rect, TRUE);
TabCtrl.AdjustRect(FALSE, &rect);
// Move the tab control to the new position and size.
TabCtrl.MoveWindow(&rect, TRUE);
ASKER
nop,
btw...i need the
TabCtrl.MoveWindow(rect.le ft,rect.to p,rect.Wid th(),rect. Height()*6 /7, TRUE);
format..because of the 6/7 of height
btw...i need the
TabCtrl.MoveWindow(rect.le
format..because of the 6/7 of height
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
One way to ensure the resizing procuedure is the same is to call one routine in both OnInitDialog and OnSize.
I would suggest you have a function such as
CWinlinx2Dlg::HandleConten t()
{
CRect rect;
GetClientRect(&rect);
... resize your controls
}
I would suggest you have a function such as
CWinlinx2Dlg::HandleConten
{
CRect rect;
GetClientRect(&rect);
... resize your controls
}
?? What was the comment that gave the answer dkloeck, or did you figure out this yourself ?
So, everytime you resize the window, you need to compare the new size with what it was, figure out the ratio and then resize accordingly. I would do it like this:
// In OnInitDialog or similar get the client area of the dialog in x and y and store this in two member variables, say m_x and m_y
OnSize()...
{
// Get the new client area from cx and cy
// figure out the ratio increase by comparing cx to m_x and cy to m_y
// Resize and move all elements by the ratio amount
// reset m_x and m_y with cx and cy *after* all sizing has been done
}
So, if your window was first 200 * 400 pixels, and the resize made it 400 * 1200, the resize ratio in the X dimension is 2, and in the y it is 3. So adjust all x and y co-ordinate values in your elements by these values.
(In practice you would not get an increase as big as this since many OnSize messages would be fired, but you get the idea)
HTH :)