Solved

CFormView dynamic resize

Posted on 1998-05-10
7
858 Views
Last Modified: 2013-11-20
I have a CFormView containing a control that is supposed to occupy the
entire view, but whose size (or at least the visually relevant part of
it is not known at design time.  I don't like seeing the underlying
dialog box sticking off the edges; worse, the view is one pane of a
splitter window and the dialog makes the scroll bars appear when they
shouldn't.

What I would like is a way to resize the underlying dialog at
the time of the call to OnInitialUpdate() so that the dialog
is the same size as the control.  Actually I may need to resize
the control at the same time so it's the same size as the part
that I want to see.

BTW I already tried using SetWindowRgn().  I don't understand
the behavior I see, but it isn't what I want.
0
Comment
Question by:trovatore
[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
  • 4
  • 3
7 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 80 total points
ID: 1309141
What you should do is catch WM_SIZE at the CFormView level. In the handler there, determine the size of the form and resize the dialog to whatever size you want:

  CMyFormView::OnSize()
  {
    CRect r;
    GetClientRect(r);

    // adjust r as necessary
    //
    m_Dialog.MoveWindow(r, TRUE);
  }
0
 

Author Comment

by:trovatore
ID: 1309142
I am not clear on whether this answer applies to the size of the control,
the size of the dialog, or both.  I think I need both.  Would you explain which
rectangle applies to which?

0
 

Author Comment

by:trovatore
ID: 1309143
OK, my first comment didn't make an awful lot of sense.  I haven't figured out the
exact relationship between GetWindowRect and GetClientRect;
the simple and obvious things don't appear
to be true.

However it seems to me that the following code ought to have no observed effect,
except for slowing things down:

void CMyFormView::OnSize(UINT nType, int cx, int cy)
    {
    CFormView::OnSize(nType,cx,cy);
    CRect rect;
    GetWindowRect(rect);
    MoveWindow(rect,TRUE);
    }

Unfortunately that isn't true.  What happens is that my control stops responding to
the mouse (it still responds to the keyboard), and it stops repainting itself.  Any
idea why?

0
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!

 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1309144
Yes, because you're calling MoveWindow on the same window. The MoveWindow() call in my code sets the size of the child of the view and not the view itself, which is what you're doing. Hence the infinite loop.
0
 

Author Comment

by:trovatore
ID: 1309145
Oh, I see.  I tried what I did because CFormView has no m_Dialog; I guess
I was being too literalistic.  I suppose I should get it from ChildWindowFromPoint(),
or is there a better way?

And why exactly can't I do this just once in OnInitInstance() ?

0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1309146
The form view will have some children in there. You will need to iterate through them using GetWindow() and for each one move and resize them as appropriate.

You can't do this once because when the form changes size, you will need to change the controls too.
0
 

Author Comment

by:trovatore
ID: 1309147
I still haven't been able to come up with the handle
for the underlying dialog object.  GetWindow(GW_CHILD)
called from CMyFormView gives me the control, which
is not what I want.  It has one sibling, whose runtime
class is just CWnd and which doesn't have the handle I
saw in the debugger that I *think* might be the handle
of the dialog.

0

Featured Post

Independent Software Vendors: 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
VBA "SendKeys" Syntax for Multiple Keystrokes 7 125
countEvens challenge 2 113
changeXy challenge 13 93
Bartender label printing - switch on and off graphics 3 71
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…
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…
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…

763 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