Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Resize dynamically the size of the CFormView

913 views
Skip to first unread message

przemysl...@gazeta.pl

unread,
Sep 20, 2007, 11:59:45 AM9/20/07
to
Hello,

I have a view which derives directly from the CFormView and then I
display a child dialog on it at runtime.
Visual Studio creates automatically resource entry for my view class.

The dialog can be resied dynamically by the user by pressing the
button and I would like the view to always fit the size of the dialog.
At the moment when I press a button and the dialog dimensions change I
cannot resize the view and a scrollbar is created, which looks really
ugly.

Could someone help me with this problem? How can I automatically
resize the view so that it always fits the dialog window?

Everything is happening in the MDI world.

Thanks for help,

Pshemek

przemysl...@gazeta.pl

unread,
Sep 20, 2007, 11:59:49 AM9/20/07
to

AliR (VC++ MVP)

unread,
Sep 20, 2007, 12:18:25 PM9/20/07
to
Call ResizeParentToFit from within the View.

AliR.


<przemysl...@gazeta.pl> wrote in message
news:1190303985.1...@g4g2000hsf.googlegroups.com...

AliR (VC++ MVP)

unread,
Sep 20, 2007, 12:22:48 PM9/20/07
to
Scratch that:
Do this instead:

CRect Rect;

GetWindowRect(&Rect);

SetWindowPos(NULL,0,0,Rect.Width()+50,Rect.Height()+50,SWP_NOMOVE|SWP_NOZORDER);

GetParentFrame()->GetWindowRect(&Rect);

GetParentFrame()->SetWindowPos(NULL,0,0,Rect.Width()+50,Rect.Height()+50,SWP_NOMOVE|SWP_NOZORDER);


AliR.

"AliR (VC++ MVP)" <Al...@online.nospam> wrote in message
news:l3xIi.8167$JD....@newssvr21.news.prodigy.net...

przemysl...@gazeta.pl

unread,
Sep 20, 2007, 4:20:59 PM9/20/07
to
On Sep 20, 5:22 pm, "AliR \(VC++ MVP\)" <A...@online.nospam> wrote:
> Scratch that:
> Do this instead:
>
> CRect Rect;
>
> GetWindowRect(&Rect);
>
> SetWindowPos(NULL,0,0,Rect.Width()+50,Rect.Height()+50,SWP_NOMOVE|SWP_NOZOR­DER);
>
> GetParentFrame()->GetWindowRect(&Rect);
>
> GetParentFrame()->SetWindowPos(NULL,0,0,Rect.Width()+50,Rect.Height()+50,SW­P_NOMOVE|SWP_NOZORDER);
>
> AliR.
>
> "AliR (VC++ MVP)" <A...@online.nospam> wrote in messagenews:l3xIi.8167$JD....@newssvr21.news.prodigy.net...

>
> > Call ResizeParentToFit from within the View.
>
> > AliR.
>
> > <przemyslaw.sl...@gazeta.pl> wrote in message

> >news:1190303985.1...@g4g2000hsf.googlegroups.com...
> >> Hello,
>
> >> I have a view which derives directly from the CFormView and then I
> >> display a child dialog on it at runtime.
> >> Visual Studio creates automatically resource entry for my view class.
>
> >> The dialog can be resied dynamically by the user by pressing the
> >> button and I would like the view to always fit the size of the dialog.
> >> At the moment when I press a button and the dialog dimensions change I
> >> cannot resize the view and a scrollbar is created, which looks really
> >> ugly.
>
> >> Could someone help me with this problem? How can I automatically
> >> resize the view so that it always fits the dialog window?
>
> >> Everything is happening in the MDI world.
>
> >> Thanks for help,
>
> >> Pshemek

Should I include this in OnInitialUpdate() or perhaps in OnInitDialog
in the child dialog??

Cheers

Joseph M. Newcomer

unread,
Sep 20, 2007, 8:44:02 PM9/20/07
to
How did you get the "+50" derived?
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

AliR (VC++ MVP)

unread,
Sep 20, 2007, 8:59:37 PM9/20/07
to
Pulled it out my you know what.

AliR.


"Joseph M. Newcomer" <newc...@flounder.com> wrote in message
news:4u46f3tvanltfjqkt...@4ax.com...

przemysl...@gazeta.pl

unread,
Sep 21, 2007, 3:39:52 AM9/21/07
to
On Sep 21, 1:59 am, "AliR \(VC++ MVP\)" <A...@online.nospam> wrote:
> Pulled it out my you know what.
>
> AliR.
>
> "Joseph M. Newcomer" <newco...@flounder.com> wrote in messagenews:4u46f3tvanltfjqkt...@4ax.com...

>
> > How did you get the "+50" derived?
> > joe
>
> > On Thu, 20 Sep 2007 16:22:48 GMT, "AliR \(VC++ MVP\)" <A...@online.nospam>

> > wrote:
>
> >>Scratch that:
> >>Do this instead:
>
> >>CRect Rect;
>
> >>GetWindowRect(&Rect);
>
> >>SetWindowPos(NULL,0,0,Rect.Width()+50,Rect.Height()+50,SWP_NOMOVE|SWP_NOZ­ORDER);
>
> >>GetParentFrame()->GetWindowRect(&Rect);
>
> >>GetParentFrame()->SetWindowPos(NULL,0,0,Rect.Width()+50,Rect.Height()+50,­SWP_NOMOVE|SWP_NOZORDER);
>
> >>AliR.
>
> >>"AliR (VC++ MVP)" <A...@online.nospam> wrote in message

> >>news:l3xIi.8167$JD....@newssvr21.news.prodigy.net...
> >>> Call ResizeParentToFit from within the View.
>
> >>> AliR.
>
> >>> <przemyslaw.sl...@gazeta.pl> wrote in message

> >>>news:1190303985.1...@g4g2000hsf.googlegroups.com...
> >>>> Hello,
>
> >>>> I have a view which derives directly from the CFormView and then I
> >>>> display a child dialog on it at runtime.
> >>>> Visual Studio creates automatically resource entry for my view class.
>
> >>>> The dialog can be resied dynamically by the user by pressing the
> >>>> button and I would like the view to always fit the size of the dialog.
> >>>> At the moment when I press a button and the dialog dimensions change I
> >>>> cannot resize the view and a scrollbar is created, which looks really
> >>>> ugly.
>
> >>>> Could someone help me with this problem? How can I automatically
> >>>> resize the view so that it always fits the dialog window?
>
> >>>> Everything is happening in the MDI world.
>
> >>>> Thanks for help,
>
> >>>> Pshemek
>
> > Joseph M. Newcomer [MVP]
> > email: newco...@flounder.com

Well,

This does not work, the frame is much bigger than the dialog itself.
Any other ideas?

Thanks for help

Message has been deleted

hank freeware

unread,
Nov 19, 2010, 4:49:42 PM11/19/10
to

((CFormView*)GetActiveView())->SetScaleToFitSize(((CFormView*)GetActiveView())->GetTotalSize());

((CMainFrame*)AfxGetMainWnd())->RecalcLayout();

((CFormView*)GetActiveView())->ResizeParentToFit(FALSE);


>> On Thursday, September 20, 2007 12:18 PM AliR \(VC++ MVP\) wrote:

>> Call ResizeParentToFit from within the View.
>>
>> AliR.


>>> On Thursday, September 20, 2007 12:22 PM AliR \(VC++ MVP\) wrote:

>>> Scratch that:
>>> Do this instead:
>>>
>>> CRect Rect;
>>>
>>> GetWindowRect(&Rect);
>>>

>>> SetWindowPos(NULL,0,0,Rect.Width()+50,Rect.Height()+50,SWP_NOMOVE|SWP_NOZORDER);
>>>
>>> GetParentFrame()->GetWindowRect(&Rect);
>>>
>>> GetParentFrame()->SetWindowPos(NULL,0,0,Rect.Width()+50,Rect.Height()+50,SWP_NOMOVE|SWP_NOZORDER);
>>>
>>>
>>> AliR.
>>>
>>> "AliR (VC++ MVP)" <Al...@online.nospam> wrote in message
>>> news:l3xIi.8167$JD....@newssvr21.news.prodigy.net...


>>>> On Thursday, September 20, 2007 4:20 PM przemyslaw.sliw wrote:

>>>> OR=ADDER);
>>>> SW=ADP_NOMOVE|SWP_NOZORDER);
>>>> .104@newssvr21.news.prodigy.net...


>>>>
>>>> Should I include this in OnInitialUpdate() or perhaps in OnInitDialog
>>>> in the child dialog??
>>>>
>>>> Cheers


>>>>> On Thursday, September 20, 2007 8:44 PM Joseph M. Newcomer wrote:

>>>>> How did you get the "+50" derived?
>>>>> joe
>>>>>
>>>>>

>>>>> Joseph M. Newcomer [MVP]
>>>>> email: newc...@flounder.com


>>>>>> On Thursday, September 20, 2007 8:59 PM AliR \(VC++ MVP\) wrote:

>>>>>> Pulled it out my you know what.
>>>>>>
>>>>>> AliR.


>>>>>>> On Friday, September 21, 2007 3:39 AM przemyslaw.sliw wrote:

>>>>>>> On Sep 21, 1:59 am, "AliR \(VC++ MVP\)" <A...@online.nospam> wrote:

>>>>>>> vanltfjqktrqk...@4ax.com...
>>>>>>> am>
>>>>>>> OZ=ADORDER);
>>>>>>> 0,=ADSWP_NOMOVE|SWP_NOZORDER);
>>>>>>> g=2E
>>>>>>> I


>>>>>>>
>>>>>>> Well,
>>>>>>>
>>>>>>> This does not work, the frame is much bigger than the dialog itself.
>>>>>>> Any other ideas?
>>>>>>>
>>>>>>> Thanks for help


>>>>>>>> On Friday, September 21, 2007 9:52 AM Joseph M. Newcomer wrote:

>>>>>>>> See below...
>>>>>>>> On Fri, 21 Sep 2007 00:39:52 -0700, przemysl...@gazeta.pl wrote:
>>>>>>>>
>>>>>>>> ****
>>>>>>>> Try this:
>>>>>>>> CRect r;
>>>>>>>> GetWindowRect(&r);
>>>>>>>> CRect parent;
>>>>>>>> GetParentFrame()->ScreenToClient(&r);
>>>>>>>> GetParentFrame()->CalcWindowRect(&r);
>>>>>>>> GetParentFrame()->SetWindowPos(NULL, 0, 0, r.Width(), r.Height(), SWP_NOMOVE |
>>>>>>>> SWP_NOZORDER);
>>>>>>>>
>>>>>>>> this should get something tighter. Normally, I just call ResizeParentToFit().
>>>>>>>> joe
>>>>>>>> ****
>>>>>>>> Joseph M. Newcomer [MVP]
>>>>>>>> email: newc...@flounder.com


>>>>>>>> Submitted via EggHeadCafe
>>>>>>>> Using DataList to List Category/Subcategory with expand - collapse facility via javascript
>>>>>>>> http://www.eggheadcafe.com/tutorials/aspnet/6b6d6022-60f6-4d05-beaf-7737a1f26987/using-datalist-to-list-categorysubcategory-with-expand--collapse-facility-via-javascript.aspx

Joseph M. Newcomer

unread,
Nov 19, 2010, 11:34:51 PM11/19/10
to
See below...
On Fri, 19 Nov 2010 21:49:42 GMT, hank freeware <ha...@psl.bc.ca> wrote:

>
>((CFormView*)GetActiveView())->SetScaleToFitSize(((CFormView*)GetActiveView())->GetTotalSize());
****
There's something incredibly suspect about any computation that has this many casts. I've
done resized CFormViews without ever writing anything this convoluted.

It also has long-term risks in that it assumes that the active view is a CFormView (and
when the client says, "By the way, we want a graphical view as well", your code had better
keep working, and the above code will fail horribly).

In some cases, I want the view to resize and I want the controls to dynamically resize to
match; in other cases, I really want the scrollbars. But in neither case did I end up
writing something that involved either GetActiveView() or a cast. I consider the
combination of GetActiveView and explicit casting to be extremely hazardous. I rarely
even consider GetActiveView to be even meaningful.

You can check out a number of examples on my MVP Tips site that have dynamically resized
CFormViews.
joe

****

0 new messages