15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Sizing a CFormView

Mats Mеnhav -- manhav@connectum.skurup.se
Wednesday, January 24, 1996

-- [ From: Mats Mеnhav * EMC.Ver #2.5.02 ] --

MSVC 4.00 Win NT 3.51 SP3 w. Newshell

I want to resize a CFormView in MDI to fit the dialog resource.
I found a note in the FAQ about this telling how to do it.
It said that I in my OnInitialUpdate should do the following:
             CFormView::OnInitialUpdate();
             ResizeParentToFit(/*FALSE*/); // default argument is TRUE

Now this makes things different than it was without it, however not what I
wanted.
What will happen is that the horizontal sixe is not changed at all by this,
and the vertical size  is set to almost zero ('almost' because the Win
95/NewShell makes the formview with borders, and these are visible, but the
'real' cliet window is not).
Has anyone out there encountered the same problem and found a good
workaround ?

Regards
Mats
--
==========================================================================
Mats Mеnhav (Mats Manhav for 7-bit people)
email:manhav@connectum.skurup.se   WWW: http://connectum.skurup.se/~manhav
FAX:  (int) 46 (0) 414 243 05      Phone: (int) 46 (0) 414 243 05         
==========================================================================




Dale Wilson -- dale@dra.com
Tuesday, January 30, 1996


> -- [ From: Mats Menhav * EMC.Ver #2.5.02 ] --
> I want to resize a CFormView in MDI to fit the dialog resource.

By the time you get to OnInitialUpdate, things are grunged.
After a GREAT DEAL OF ANGUISH (are you listening, MFC developers (grin)) I 
came up with...

void MyFormView::OnSize(UINT Type, int cx, int cy)
{
    // If we have valid coordinates
    if(Type != SIZE_MINIMIZED && cx != 0 && cy != 0)
    {
        // Save previous screen size
        m_PrevX = m_cx;
        m_PrevY = m_cy;

        m_cx = cx;
        m_cy = cy;

        // If we've been here before
        if( m_PrevX != 0 && m_PrevY != 0)
        {
            // and if anything has changed
            if( m_cx != m_PrevX || m_cy != m_PrevY)
            {
                // Do some stuff
            }
        }
        else
        {
     //First Time
     // At this point, the size of the window is based on the size of the 
dialog.
     // That's what we want.
     // Unfortunately the frame has a different size and if nothing is done, 
it will
     // resize us to fit its preferences, so we capture our size now, before 
the frame
     // does it's deed.

               CRect InitRect;
               GetWindowRect(InitRect);
     TRACERESIZE(_T(" Initial Rectangle: %d, %d, %d, %d)\n\r"),
                  InitRect.left, InitRect.top, InitRect.right, 
InitRect.bottom);

               CFrameWnd *pParent = GetParentFrame();
               if(pParent != NULL)
               {
                    pParent->CalcWindowRect(InitRect);
                    TRACERESIZE(_T(" Parent Window desired: %d, %d, %d, 
%d)\n\r"),
                         InitRect.left, InitRect.top, InitRect.right, 
InitRect.bottom);
                    CWnd* pAncestor = pParent->GetParent();
                    if(pAncestor != NULL)
                    {
                              pAncestor->ScreenToClient(InitRect);
                    }
                    pParent->MoveWindow(InitRect.left, InitRect.top, 
InitRect.Width(), InitRect.Height());
               }
        }
    }
    CFormView::OnSize(Type, cx, cy);
}

Cheers,
Dale Wilson
dale@dra.com



Dale Wilson -- dale@dra.com
Thursday, February 01, 1996


> Hi Dale,
>
> Yes, It is true that the Window is already being grunged when I get to the
> OnInitialUpdate. I was just going to insert your code when I noticed that 
I
> had a SetScrollSizes in my CFormView derived class. (I have that because I
> don't
> want to have any scrollbars in the dialog, I resize the controls during 
the
> OnSize instead).
> Since OnSize is called before OnInitialUpdate it is quite obvious that the
> code doesn't work.
>
> If I make sure I don't call SetScrollSizes until the OnInitialUpdate() is
> called the resizing works alright.
>
> Mats
Thanks for the reply, Mats.  I don't have a SetScrollSizes in my code, but I 
do have a SetScaleToFitSize in my OnInitialUpdate which serves a similar 
purpose.  The problem I was seeing shows up in the following trace output in 
which I disabled the MoveWindow in my code

DRAFormView::OnCreate (size(0,0,0,0))
DRAFormView::OnSize(0, 370, 186)
   Initial Rectangle: 60, 151, 430, 337)
   Parent Window desired: 54, 126, 436, 343)
DRAFormView::OnSize(0, 0, 0)
DRAFormView::OnSize(0, 604, 275)
DRAFormView::OnInitialUpdate

The first size (370x186) matches the resource dialog.  Without any help from 
me, MFC has resized it to 604x275 based, apparently on the default size of 
the Frame.

When I turn the MoveWindow back on, I get...

DRAFormView::OnCreate (size(0,0,0,0))
DRAFormView::OnSize(0, 370, 186)
   Initial Rectangle: 104, 199, 474, 385)
   Parent Window desired: 98, 174, 480, 391)
DRAFormView::OnSize(0, 0, 0)
DRAFormView::OnSize(0, 366, 182)
DRAFormView::OnSize(0, 366, 166)
DRAFormView::OnSize(0, 350, 166)
DRAFormView::OnInitialUpdate

I'm still losing  20x20 pixels before the OnInitialUpdate, but that's 
acceptable in my application.  If I DON'T capture the initial size in the 
first meaningful OnSize, then I end up completely lost.

Could your technique be working because you are resizing your controls in 
OnSize even before the OnInitialUpdate?  In my case, I don't know what needs 
to be done until OnInitialUpdate.  In any case, glad you got it working...

dale@dra.com




| Вернуться в корень Архива |