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

Resizing Modal CDialog in OnInitDialog not working

361 views
Skip to first unread message

Suzanne Gagnon

unread,
Nov 14, 2002, 11:23:57 AM11/14/02
to
Greetings.
I have CDialog that is based on a dialog resource created
as a popup and using resizing borders.
The dialog contains a CListCtrl, a few buttons, and I'm
adding a PropertySheet on the fly in the OnInitDialog.

Since the Prop sheet does fine at sizing itself to the
sizes of the pages it contains, I have decided to let it
do that, size the CDialog dynamically around
that, and then position/size the other controls
dynamically as well.
( Pls tell me if you think that isn't smart. )

The CDialog is Modal.

After creating it (& adding pages), I get the size of the
PropertySheet by calling pSheet->GetClientRect().

Then I get the size of the CDialog by calling
GetClientRect.

I modify the height of the dialog by calling SetWindowPos.

If I next call GetClientRect on the CDialog, the CDialog
has size has changed, but not to the dimensions I
assigned.

Here is the code:

BOOL CStaCfgDlg::OnInitDialog()
{
CDialog::OnInitDialog();

if (!m_pSheet)
{
m_pSheet = new CDevCfgSheet("testsheet", m_pDoc,
this);
}

if (!m_pSheet->Create(this, WS_CHILD | WS_VISIBLE))
{
return FALSE;
}

RECT cr, bcr, scr;
GetClientRect( &cr );
m_BtnApply.GetClientRect( &bcr );
m_pSheet->GetClientRect( &scr );

//here cr.right = 573 cr.bottom = 348

// size the dlg vertically
cr.bottom = scr.bottom + SCD_MID_MARGIN + bcr.bottom +
SCD_BOTTOM_MARGIN;

// now cr.bottom = 350 I know, I know, big diff!

SetWindowPos( NULL, 0, 0, cr.right, cr.bottom,
SWP_NOMOVE|SWP_NOZORDER );
GetClientRect( &cr );

// now cr.right = 565, cr.bottom = 316 !!!
// how did this happen??

return TRUE;
}

I have also tried using the MoveWindow() method, with the
same result:

CRect myCRect;
GetClientRect(&myCRect);

myCRect.bottom = scr.bottom + SCD_MID_MARGIN +
bcr.bottom + SCD_BOTTOM_MARGIN;
ClientToScreen(myCRect);

MoveWindow(myCRect.left, myCRect.top, myCRect.Width(),
myCRect.Height());

What in the world am I doing wrong?

Thanks.
Suz.


David Lowndes

unread,
Nov 14, 2002, 12:29:15 PM11/14/02
to
>After creating it (& adding pages), I get the size of the
>PropertySheet by calling pSheet->GetClientRect().
>
>Then I get the size of the CDialog by calling
>GetClientRect.
>
>I modify the height of the dialog by calling SetWindowPos.
>
>If I next call GetClientRect on the CDialog, the CDialog
>has size has changed, but not to the dimensions I
>assigned.

GetClientRect doesn't include the borders and caption bar space of the
dialog. Try reworking your code to use GetWindowRect instead.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq

Suzanne Gagnon

unread,
Nov 14, 2002, 4:14:23 PM11/14/02
to
Problem solved!
Thank you very much for your help.
Suz.

>.
>

0 new messages