Solved

Question for Answer2000

Posted on 1998-12-06
6
190 Views
Last Modified: 2013-11-20
Dear Sir,

I have asked you how to resize the interface components in my application before.

Your suggested solution is:

1. Add a handler for WM_SIZE messages and put the code in there.
2. Use ::IsWindow to check the controls are valid before working on them (OnSize will get called once before the controls are valid)
3. Use MoveWindow to move the controls around.  

Here is an example from one of my form view app's (CTComply derives off CFormView)

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

    if ( !::IsWindow(m_edit.m_hWnd) ) return ;
    if ( !::IsWindow(m_list.m_hWnd) ) return ;

    SizeControls() ;
}

void CTComply::SizeControls()
{
   // get client area
   CRect rcClient ;
   GetClientRect( &rcClient ) ;

   // position edit control
   CRect rcEdit ;
   m_edit.GetWindowRect( &rcEdit ) ;
   ScreenToClient( (LPPOINT)(&rcEdit.left) ) ;
   ScreenToClient( (LPPOINT)(&rcEdit.right) ) ;

   m_edit.MoveWindow( rcEdit.left, rcEdit.top, rcClient.right - rcEdit.left - 10, rcClient.bottom - rcEdit.top - 10 ) ;

    // position list control
    CRect rcList ;
    m_list.GetWindowRect( &rcList ) ;
    ScreenToClient( (LPPOINT)(&rcList.left) ) ;
    ScreenToClient( (LPPOINT)(&rcList.right) ) ;

    m_list.MoveWindow( rcList.left, rcList.top, rcClient.right - rcList.left - 10, rcList.bottom - rcList.top ) ;
}
///////////////////////////////////////////////////

But I still have a problem in re-sizing the interface components.

Eg. when the width of the window is 600
             height of the window id 400

    a edit box is placed at the window with the upper left co-ordinates is (60,40);

Now, I am resizing the window to width 500, heigth 300.
In this suitation, the edit box need to place at the window with upper-left coordinates (50,30) and the size of the edit box need to be changed also.

From your suggested solution before, I found it only resize the edit box without getting a new upper-left coordinate.

How can I get this?

Thanks!!!

0
Comment
Question by:kkuu
  • 4
  • 2
6 Comments
 
LVL 8

Expert Comment

by:Answers2000
Comment Utility
This bit gets the size of the size of the form (in pixels)
   // get client area
       CRect rcClient ;
       GetClientRect( &rcClient ) ;

This bit gets the previous coordinates of the edit control in screen units (relative to top left of screen)
  CRect rcEdit ;
       m_edit.GetWindowRect( &rcEdit ) ;

This bit converts the screen coordinates to coordinates to coordinates on the form
   ScreenToClient( (LPPOINT)(&rcEdit.left) ) ;
       ScreenToClient( (LPPOINT)(&rcEdit.right) ) ;

This bit moves/resizes the edit control
       m_edit.MoveWindow( rcEdit.left, rcEdit.top, rcClient.right - rcEdit.left - 10, rcClient.bottom - rcEdit.top - 10 ) ;

The coordinates are in client coordinates (0,0 is top left of the form)

The parameters are top left (x then y), then width, then height

In my example I leave the edit control at the same position and size it to cover the rest of the client area of the form (minus 10 pixels in each of the X and Y coordinates)

Now if you want the top left to always be at 50,30 then change these parameters in the edit control (first two).  You don't specify how you want the size changed.  

Here's an example
m_edit.MoveWindow( 50, 30, 200, 300 ) ;

This will make the top left 50,30
The width 200 and the height 300

Is this clear ?

m_list. stuff was for a 2nd control (my form also had a list on it), so you can ignore this if you don't have a 2nd (or additional controls).


0
 

Author Comment

by:kkuu
Comment Utility
Sorry Sir,

I don't know how to get the change of the size of the window......

I want to have the older size of the window, and the new size of the window...
Can I have these two data at the same time in order to specify the size of the interface component change?

Thanks!!!
0
 
LVL 8

Expert Comment

by:Answers2000
Comment Utility
I don't understand your 5:47pm comment

The old size/position is given in by the rectangle resulting from
  CRect rcEdit ;
       m_edit.GetWindowRect( &rcEdit ) ;

The new size/position is whatever you specify in the m_edit.MoveWindow( ...etc..) line

If you want to find the change in size, just subtract the difference

If you want to change the size by a certain amount use

m_editMoveWindow( rcEdit.left, rcEdit.top, rcEdit.Width() + dx, rcEdit.Height + dy ) ;

where dx and dy are the amount to change the x,y sizes by respectively (positive = increase in size, negative is a decrease in size)

Does this answer your question ?  If not you better explaining your difficulty a bit more clearly for me.


0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 8

Expert Comment

by:Answers2000
Comment Utility
Ooops to make the old size meaningful add in the 2 ScreenToClient lines after the 1st code fragment, that is to say :-

   CRect rcEdit ;
   m_edit.GetWindowRect( &rcEdit ) ;
   ScreenToClient( (LPPOINT)(&rcEdit.left) ) ;
   ScreenToClient( (LPPOINT)(&rcEdit.right) ) ;
0
 

Author Comment

by:kkuu
Comment Utility
Dear Answers2000,

Sorry for replying you late!!!

For the previous question, my problem is:

Before resizing the window, for example the size of the window is 400x400....
after resizing the window, the size of the window becomes 450x350.....

My question is how to get these two data in my program....and I want to use these two data at the same time..Can I do like this? Do you understand?

Also, I have another question in re-sizeing the edit box......
In my edit box. I have delcared a CString type variable m_edit1.I
I tried to resize the edit box by using the method you suggested but the followiing error occurs:

error C2039: 'GetWindowRect' : is not a member of 'CString'
error C2039: 'MoveWindow' : is not a member of 'CString'
Can I resize a edit box....Until now, I can reszie a button and a listctrl.

Thanks!!!
kkuu

0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 total points
Comment Utility
OK first off the CString problem.

When you create a member variable you get a choice of what type

When you go to the member variables dialog, and double clickon your edit's id, say IDC_EDIT, a little dialog pops up.  You can set either a string or window type variable.  Your problem is you picked a CString, and you should have picked a CEdit.

To fix that problem
1. Ctrl-W bring up class wiz for your dialog
2. Go to member variables
3. You should see something like, in the list box
IDC_EDIT........CString.....m_edit
4. Highlight this line
5. Click Delete Variable
6. Now make sure that line is highlighted again
7. Pick Add Variable
8. When the dialog popups up entitled "Add Member Variable", it should have fields for Member Variable Name (an edit control), Category (a combo box) and Variable Type (a combo box)

In Member Variable name, type "m_edit"  - without the quotes
In Category pick "Control"
In Variable Type pick "CEdit"

This fixes the 2 compile errors you're getting


Your code should now compile, if you look at the previous comments in
http://www.experts-exchange.com/topics/comp/os-ms-windows/programming/mfc/Q.10105791
[this question]
this explains the sizing code.

Remember the window can only one size at a time.  The reason the fix didn't work before, is it wouldn't compile, but if you re-read, I think it should make sense.

If not ask another follow up question.  

By the way, you don't need to keep opening new questions, I'll keep an eye on your progress.



0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

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…
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

10 Experts available now in Live!

Get 1:1 Help Now