Solved

CFormView dynamic resize

Posted on 1998-05-10
7
852 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
  • 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand LInux Boot partition remotly 3 90
ShiftLeft challenge 21 81
zeroMAx challenge 20 100
x-bar in Google Sheets 2 53
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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