Link to home
Start Free TrialLog in
Avatar of trovatore
trovatore

asked on

CFormView dynamic resize

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.
ASKER CERTIFIED SOLUTION
Avatar of Tommy Hui
Tommy Hui

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of trovatore
trovatore

ASKER

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?

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?

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.
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() ?

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.
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.