Solved

Help! A Stranger Problem with FormView resizing

Posted on 2000-05-14
4
340 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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 …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now