一个基于对话框的工程
界面上有一个属性页CPropertySheet m_sheet
另外设计了3个CPropertyPage m_Page1, m_Page2, m_Page3
然后在Dlg的InitDialog里面加入如下的代码,试图显示成属性页的样子,
         m_sheet.AddPage (&m_Page1);
m_sheet.AddPage (&m_Page2);
m_sheet.AddPage (&m_Page3);
m_sheet.Create(this, WS_CHILD | WS_VISIBLE, WS_EX_CONTROLPARENT);
RECT rect;
GetWindowRect(&rect);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
m_sheet.SetWindowPos(NULL, 0, 0, width, height, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);的确是成功了,但是m_sheet在dlg的界面上显示的太小了,最后一句话似乎没有让m_sheet尽量撑满dlg的界面,请问高手,
该怎么写才能控制m_sheet的大小呢?

解决方案 »

  1.   

    从CPropertyPage 派生自己的CMyPropertyPage类
    在初始化的时候使用MoveWindow或者SetWindowPos
      

  2.   

    慢了……CPropertySheet的大小实际上是依赖于激活的CPropertyPage 的大小的
      

  3.   

    vccleaner
    从CPropertyPage 派生自己的CMyPropertyPage类
    在初始化的时候使用MoveWindow或者SetWindowPos
    你说的我听不懂啊,我的m_Page1,m_Page2,3都是从CPropertyPage派生来的,
    怎么给它们写movewindow或者setwindowpos啊?
    我尝试在它们的wm_initdialog消息里加入movewindow,可是没成功啊
    能否给我一个完整的代码示例啊?
      

  4.   

    CPropertyPage设置的越大,越是有可能突出CPropertySheet的框框的,所以你说的不对,pomelowu
      

  5.   

    怪我没说清楚。
    CPropertySheet中不设置大小,而是通过CPropertyPage派生类来处理设置大小的事务,重载OnShowWindow:
    void CMyProp::OnShowWindow(BOOL bShow, UINT nStatus) 
    {
    CPropertyPage::OnShowWindow(bShow, nStatus);

    int nWidth = ///;
    int nHeight = ///; if(bShow)
    {
    GetParent()->ShowWindow(SW_HIDE);
    GetParent()->SetWindowPos(NULL,0,0,nWidth,nHeight,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);
    GetParent()->ShowWindow(SW_SHOW);
    }
    }
      

  6.   

    对于Sheet,
    GetTabControl()->MoveWindow();
    对于Page,可以在OnInitDialog中MoveWindow
      

  7.   

    不行啊 pomelowu
    你说的代码我试过了,这回不是m_sheet小了
    而是太大了,显示的边框都没有,只有左边界和上边界,而下边和右边都消失了,界面里的按钮也是不能完全显示,半个半个的。
      

  8.   

    把你的CPropertyPage的大小调节一下,然后再调整CPropertySheet的大小
      

  9.   

    果然是啊pomelowu,你说的对,我调整了sheet和page的大小就可以了,谢谢了。
    下面的全部代码:
    在dlg的那oninitdialog函数里
    m_sheet.AddPage(&m_page1);
    m_sheet.AddPage(&m_page2);
    m_sheet.Create(this, WS_CHILD | WS_VISIBLE, WS_EX_CONTROLPARENT);
    在page的onshowwindow函数里
    CPropertyPage::OnShowWindow(bShow, nStatus);
    // TODO: Add your message handler code here
    RECT rect;
    GetParent()->GetWindowRect(&rect);
    int nWidth =rect.right-rect.left;
    int nHeight =rect.bottom-rect.top;
    if(bShow)
    {
    GetParent()->ShowWindow(SW_HIDE);
    GetParent()->SetWindowPos   (NULL,0,0,nWidth,nHeight,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);
    GetParent()->ShowWindow(SW_SHOW);
    }
    现在结贴。谢谢。