对话框里控件的位置,已开始比如居中,然后点击最大化,如何使其仍然居中?

解决方案 »

  1.   

    先获得对话框的大小,计算后设置控件的位置
    void GetWindowRect( LPRECT lpRect ) const;
    void MoveWindow( int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE );
      

  2.   

    响应OnSize函数,然后利用MoveWindow
      

  3.   

    响应OnSize函数
    控件.MoveWindow(--)
      

  4.   

    截获最大话消息,然后使用MoveWindow
      

  5.   

    void CDlg3Dlg::OnSize(UINT nType, int cx, int cy)
    {
    CDialog::OnSize(nType, cx, cy); // TODO: Add your message handler code here
    CRect lpRect;
    GetWindowRect(&lpRect);
    CSize szMWD = lpRect.Size();
    int a = szMWD.cx;
    int b = szMWD.cy;
    GetDlgItem(IDC_LIST1)->MoveWindow( (1024 - a)/2, (768 - b)/2,a , b ,TRUE);

    }出错,有没有什么好的方法把ListBox重新放在对话框中间?
      

  6.   

    我在对话框的属性中添加了OnSize消息函数,可是在OnSize()里使用MoveWindow()就出错,
    但是,同样的代码放到OnInitDialog()就能成功,为什么呢?
      

  7.   

    你得这样写?
    在OnInitDialog()里写
    m_hInit = true;//这个变量作为对话框的成员变量,并且在对话框构造函数里负初值false然后在OnSize()里写
    void CDlg3Dlg::OnSize(UINT nType, int cx, int cy)
    {
    CDialog::OnSize(nType, cx, cy);
           if(m_hInit){
    // TODO: Add your message handler code here
    CRect lpRect;
    GetWindowRect(&lpRect);
    CSize szMWD = lpRect.Size();
    int a = szMWD.cx;
    int b = szMWD.cy;
    GetDlgItem(IDC_LIST1)->MoveWindow( (1024 - a)/2, (768 - b)/2,a , b ,TRUE);
           }
    }
      

  8.   

    void CDlg3Dlg::OnSize(UINT nType, int cx, int cy)
    {
    CDialog::OnSize(nType, cx, cy);         if (IsWindow(GetDlgItem(IDC_LIST1))) {
        CRect lpRect;
        GetWindowRect(&lpRect);
        CSize szMWD = lpRect.Size();
        int a = szMWD.cx;
        int b = szMWD.cy;         
        GetDlgItem(IDC_LIST1)->MoveWindow( (1024 - a)/2, (768 - b)/2,a , b ,TRUE);
    }
    }