我做了一个可以横向伸缩的对话框,想在程序运行时,即对话框第一次显示时只显示收缩的大小,
请问怎么设置?
我是按照孙鑫老师讲的方法做的
部分代码如下
void CShensuoDlg::OnButton1() 
{
// TODO: Add your control notification handler code here
CString str;
if (GetDlgItemText(IDC_BUTTON1,str),str=="收缩<<")
{
        SetDlgItemText(IDC_BUTTON1,"扩展>>");
m_bIsShousuo = TRUE;
}
else
{
        SetDlgItemText(IDC_BUTTON1,"收缩<<");
m_bIsShousuo = FALSE;
}

static CRect rectLarge;
static CRect rectSmall;
if (rectLarge.IsRectNull())
{
CRect rectSeparator;
GetWindowRect(&rectLarge);
GetDlgItem(IDC_STATIC1)->GetWindowRect(&rectSeparator);
        rectSmall.left = rectLarge.left;
rectSmall.bottom = rectLarge.bottom;
rectSmall.top = rectLarge.top;
rectSmall.right = rectSeparator.right;
}
if (!m_bIsShousuo)
{
SetWindowPos(NULL,0,0,rectSmall.Width(),rectSmall.Height(),SWP_NOMOVE|SWP_NOZORDER);
}
else
{
        SetWindowPos(NULL,0,0,rectLarge.Width(),rectLarge.Height(),SWP_NOMOVE|SWP_NOZORDER);
}}
我在OnInitDialog()试过,但是只能显示收缩后的大小,但是却不能扩展了,不能显示对话框的实际大小了
大侠们帮帮忙

解决方案 »

  1.   

    static CRect rectLarge; 
    static CRect rectSmall; 
    ...............这一段代码是在button1中,你把它放到OnInitDialog()中当然不能正常工作了要不,你就把这两个变量声明为这个类的全局变量就行了,在OnInitDialog()中初始化,其它地方的初始化全部去掉
      

  2.   

    楼上的方法不行,
    我的代码在一个button的控制下是可以实现收缩和扩展的就像颜色对话框那样,
    就是在对话框第一次显示的时候不能像颜色对话框那样只显示收缩后的部分,
    大家给想个办法