Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help! A Stranger Problem with FormView resizing

Posted on 2000-05-14
4
Medium Priority
?
353 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 150 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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

610 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