Solved

CFormView dynamic resize

Posted on 1998-05-10
7
846 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 15

Expert Comment

by:Tommy Hui
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Turn a spreadsheet into a vba executable. 2 66
maven archtype selection in eclipse 1 51
bigDiff challenge 17 74
wordcount challenge 11 72
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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

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