Q140585: PRB: Resizing CPropertySheet in OnInitDialog Does Not Work

Article: Q140585
Product(s): Microsoft C Compiler
Version(s): winnt:4.0
Operating System(s): 
Keyword(s): kbcode kbMFC kbPropSheet KbUIDesign kbVC400 kbGrpDSMFCATL
Last Modified: 06-MAY-2001

-------------------------------------------------------------------------------
The information in this article applies to:

- The Microsoft Foundation Classes (MFC), used with:
   - Microsoft Visual C++, 32-bit Editions, version 4.0 
-------------------------------------------------------------------------------

SYMPTOMS
========

If you create a class derived from CPropertySheet and use ClassWizard to add a
handler for OnInitDialog(), the TODO comment will be added before the call to
CPropertySheet::OnInitDialog(). If you replace the comment with calls to
MoveWindow() or SetWindowPos() to resize the sheet, this will not work. Also,
GetWindowRect() or GetClientRect() will not return the correct information if
called before OnInitDialog().

This is the code generated by ClassWizard:

     BOOL CMySheet::OnInitDialog()
     {
        // TODO: Add your specialized code here and/or call the base class
        return CPropertySheet::OnInitDialog();
     }

CAUSE
=====

CPropertySheet::OnInitDialog causes the CPropertySheet to resize. Therefore, any
call to MoveWindow() or SetWindowPos() has no effect if it comes before
CPropertySheet::OnInitDialog().

RESOLUTION
==========

Call CPropertySheet::OnInitDialog() first, before resizing the sheet, as in the
following code.

Sample Code
-----------

  // This code shows how to resize a modeless CPropertySheet and
  // add a button.

  // CMySheet is derived from CPropertySheet
  BOOL CMySheet::OnInitDialog()
  {
            CPropertySheet::OnInitDialog();

            RECT rc;
            GetWindowRect (&rc);
            // Increase the height of the CPropertySheet by 30
            rc.bottom += 30;
            // Increase the width of CPropertySheet by 50
            rc.right +=50;
            // Resize the CPropertySheet
            MoveWindow (rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top);

            // Convert to client coordinates
            ScreenToClient (&rc);
            // m_Button is of type CButton and is a member of CMySheet
            m_Button.Create ("&MyButton", WS_CHILD | WS_VISIBLE | WS_TABSTOP,
               CRect (5, rc.bottom-30, 80, rc.bottom-5), this, IDC_MYBUTTON);
            return TRUE;
  }

STATUS
======

This behavior is by design.

Additional query words: 4.00 Windows 95

======================================================================
Keywords          : kbcode kbMFC kbPropSheet KbUIDesign kbVC400 kbGrpDSMFCATL 
Technology        : kbAudDeveloper kbMFC
Version           : winnt:4.0
Issue type        : kbprb

=============================================================================