Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CFormView dynamic resize

Posted on 1998-05-10
7
Medium Priority
?
873 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 240 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
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!

 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

604 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