Solved

Help! A Stranger Problem with FormView resizing

Posted on 2000-05-14
4
349 Views
Last Modified: 2013-11-20
Hi, all:

I have a problem of resizing controls  in a FormView for both width and height with a MDI application.

For example, if Y direction resizing works fine  then X-direction resizing won't work. Or , if X direction resizing works fine  then Y-direction resizing won't work.  But if the form’s height is decreased to a small value, the controls in the form will be X-direction resizable then it is Y-direction in-resizable. That is, the controls’ width will change with the change of the form width. BUT in this case, controls’ height can not be changed any more until the form width is changed to a small enough value!

What I did is as below:

void  CMyFormView:OnInitialUpdate( void )
{
   CRect       rctMaxForm( 0, 0, 0, 0 );  // Form max rectangle to initialize the form

   // Get Parent frame rectangle to determine max the form size
   this->GetParentFrame()->GetClientRect( rctMaxForm );

   // Store the form original size with an attribute before it is changed
   this->GetWindowRect(  m_rctOriForm ); // m_rctOriForm is a data member of the class
   ScreenToClient( m_rctOriForm );

   // Initialize the form position with the max size for resizing controls later
   this->SetWindowPos(  NULL  // pWndInsertAfter
                      , 0     // left
                      , 0     // top
                      , rctMaxForm.Width()
                      , rctMaxForm.Height()
                      , SWP_NOMOVE | SWP_SHOWWINDOW
                      );
}

void CMyFormView::OnSize( UINT nType, int cx, int cy )
{
   CFormView::OnSize( nType, cx, cy );

     // Get a pointer to the control
     CEdit*  pCtrl = ( CEdit* )GetDlgItem( IDC_EDIT );
   
    if( cx > m_rctOriForm.Width() )
    {
      CRect rctEdit;
      pCtrl->GetWindowRect( rctEdit );
      rctEdit.right += (cx - m_rctOriFoem );
      // Update th edit control dimensions
     pCtrl->MoveWindow(rctEdit );
   }

    if( cy > m_rctOriForm.Height() )
    {
      CRect rctEdit;
      pCtrl->GetWindowRect( rctEdit );
      rctEdit.bottom += (cy - m_rctOriFoem );
      // Update th edit control dimensions
     pCtrl->MoveWindow( rctEdit );
   }

}

When I tested these functions, I found that either X or Y direction resizing works fine. However, I can not get the CEdit object resized with both X and Y direction at the same time.

I am wandering why it happens and how to solve the problem. I guess that the problem may come from the m_OriForm's value.

Could anybody give me an idea?

Thanks in advance!

JAY
0
Comment
Question by:jayLi
  • 2
4 Comments
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 2808897
how about

void CMyFormView::OnSize( UINT nType, int cx, int cy )
{
   CFormView::OnSize( nType, cx, cy );

     // Get a pointer to the control
     CEdit*  pCtrl = ( CEdit* )GetDlgItem( IDC_EDIT );
   
    CRect rctEdit;
    pCtrl->GetWindowRect( rctEdit );
    bool bChanged=false;
    if( cx > m_rctOriForm.Width() )
    {
      rctEdit.right += (cx - m_rctOriFoem );
      bChanged=true;
   }

    if( cy > m_rctOriForm.Height() )
    {
      rctEdit.bottom += (cy - m_rctOriFoem );
      bChanged=true;
   }

   if (bchanged==true)
     pCtrl->MoveWindow(rctEdit );

}


0
 
LVL 9

Accepted Solution

by:
ShaunWilde earned 50 total points
ID: 2808900
also are the following right

      rctEdit.right += (cx - m_rctOriFoem );
     
should it be

      rctEdit.right += (cx - m_rctOriFoem.Width() );
     
also

should

      rctEdit.bottom += (cy - m_rctOriFoem );
     
be

      rctEdit.bottom += (cy - m_rctOriFoem.Height() );
     

0
 
LVL 12

Expert Comment

by:migel
ID: 2809929
Hi!
// IMHO there is error:
CRect rctEdit;
>>pCtrl->GetWindowRect( rctEdit );
rctEdit.right += (cx - m_rctOriFoem );      // Update th edit control dimensions
>>pCtrl->MoveWindow(rctEdit );
call ScreenToClient to convert coordinates:
CRect rctEdit;
pCtrl->GetWindowRect( rctEdit );
ScreenToClient(rctEdit);
rctEdt.right = cx - 2*rctEdt.left; // left border around control
// Update th edit control dimensions
pCtrl->MoveWindow(rctEdit );
0
 

Author Comment

by:jayLi
ID: 2825365
The problem is solved with your idea.

Thank you, ShaunWilde! And thank you Migel for your idea too.

JAY
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Is it possible to combine several text files into one big one? (redhat v5 enterprise) 4 103
zeroMAx challenge 20 114
Problem to App 4 99
Authenticate using sesu from script 7 60
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 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