Solved

Help! A Stranger Problem with FormView resizing

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

719 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