Solved

Resize Problem

Posted on 2004-04-24
7
435 Views
Last Modified: 2013-11-20
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(IDS_ABOUTBOX);
            if (!strAboutMenu.IsEmpty())
            {
                  pSysMenu->AppendMenu(MF_SEPARATOR);
                  pSysMenu->AppendMenu(MF_STRING, 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,rect);
      TabCtrl.MoveWindow(rect.left,rect.top,rect.Width(),rect.Height()*6/7, true);

      //Passt das TaskCtrl an das Fenster an
      CRect rect3;
      TabCtrl.GetWindowRect(&rect3);            
      TaskCtrl.MoveWindow(rect.left,rect.top+rect3.Height()+3,rect.Width()-2,
            rect.Height()/7, true);

      //Gibt die Tabs ein
      TabCtrl.InsertItem(0,"Flächenmanager");
      TabCtrl.InsertItem(1,"Personal");
      TabCtrl.InsertItem(2,"Inventar");
      TabCtrl.InsertItem(3,"Vertragsmanagement");
      TabCtrl.InsertItem(4,"Finanz Übersicht");
      TabCtrl.InsertItem(5,"Gefahrstoffe");

      //Gibt die Titel der Spalten an
      CRect rect2;
      TaskCtrl.GetClientRect(&rect2);
      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_FULLROWSELECT|LVS_EX_CHECKBOXES;
      TaskCtrl.SetExtendedStyle(dwStyle);      

      //Creates the dialogs
      VERIFY(D1.Create(CDlg1::IDD, this));
      VERIFY(D2.Create(CDlg2::IDD, this));
      VERIFY(D3.Create(CDlg3::IDD, this));
      VERIFY(D4.Create(CDlg4::IDD, this));
      VERIFY(D5.Create(CDlg5::IDD, this));
      VERIFY(D6.Create(CDlg6::IDD, 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(&ClientRect);
      TabCtrl.GetItemRect(0,&TabItemRect);
      D1.SetWindowPos(NULL,ClientRect.left+10,ClientRect.top+            
            TabItemRect.Height()+10,ClientRect.Width()-10,
            ClientRect.Height()-TabItemRect.Height()-10,SWP_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::GetClientRect(&rect);
      TabCtrl.AdjustRect(false,rect);
      TabCtrl.MoveWindow(rect.left,rect.top,rect.Width(),rect.Height()*6/7, true);

      //Passt das TaskCtrl an das Fenster an
      CRect rect3;
      TabCtrl.GetWindowRect(&rect3);
      TaskCtrl.MoveWindow(rect.left,rect.top+rect3.Height()+3,rect.Width()-2,
            rect.Height()/7, true);

      //Passt die Spalten an die Fenster Größe an
      CRect rect2;
      TaskCtrl.GetClientRect(&rect2);
      TaskCtrl.SetColumnWidth(0,rect2.Width()*5/6);
      TaskCtrl.SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER);

      
      //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(&ClientRect);
      
      D1.SetWindowPos(NULL,ClientRect.left+10,ClientRect.top+
            TabItemRect.Height()+10,ClientRect.Width()-10,
            ClientRect.Height()-TabItemRect.Height()-10,SWP_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!!!
0
Comment
Question by:dkloeck
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 19

Expert Comment

by:mrwad99
ID: 10908887
What you should be doing is resizing the elements in the window according to the increase in window size.  The window increase is given by cx and cy in the parameter list.

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 :)
0
 
LVL 10

Author Comment

by:dkloeck
ID: 10908932
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::GetClientRect(&rect);
      TabCtrl.AdjustRect(false,rect);
      TabCtrl.MoveWindow(rect.left,rect.top,rect.Width(),rect.Height()*6/7, true);
}

the TabCtrl dont have the same look as in OnInitDlg, what is wrong?
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 10909032
Try

TabCtrl.AdjustRect(FALSE, &rect);
// Move the tab control to the new position and size.
TabCtrl.MoveWindow(&rect, TRUE);  
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Author Comment

by:dkloeck
ID: 10909075
nop,
btw...i need the
TabCtrl.MoveWindow(rect.left,rect.top,rect.Width(),rect.Height()*6/7, TRUE);
format..because of the 6/7 of height
0
 
LVL 19

Accepted Solution

by:
mrwad99 earned 100 total points
ID: 10912096
If you can post a link to your (zipped) source code.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 10916248
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::HandleContent()
{
CRect rect;
GetClientRect(&rect);

... resize your controls
}
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 10921000
?? What was the comment that gave the answer dkloeck, or did you figure out this yourself ?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 97
Detect file exist or not 3 215
Thin secure Windows 10 5 115
ERP and the other system process verification 5 22
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question