Solved

Help! A Stranger Problem with FormView resizing

Posted on 2000-05-14
4
350 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
[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
  • 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

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
WinWaitActive parameters 12 31
fizzArray2 challenge 1 109
has77  challenge 9 104
MaxSpan challenge 9 137
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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…

736 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