BOOL CDemoDlg::OnInitDialog()
{
        ...
int ScreenWidth = GetSystemMetrics( SM_CXSCREEN );
int ScreenHeight = GetSystemMetrics( SM_CYSCREEN ); MoveWindow( 0, 0, ScreenWidth, ScreenHeight - 32 ); GetDlgItem( IDC_FOLDER_TREE )->MoveWindow( 10, 10, 100, 100 );
        ......
}LRESULT CDemoDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
// TODO: Add your specialized code here and/or call the base class
if( message == WM_DISPLAYCHANGE )
{
int ScreenWidth = GetSystemMetrics( SM_CXSCREEN );
int ScreenHeight = GetSystemMetrics( SM_CYSCREEN ); MoveWindow( 0, 0, ScreenWidth, ScreenHeight - 32 ); GetDlgItem( IDC_FOLDER_TREE )->MoveWindow( 10, 10, 100, 100 );
                ...
        }
return CDialog::WindowProc(message, wParam, lParam);}问题:在OnInitDialog中对话框和控件的大小都可以改变,但是在WM_DISPLAYCHANGE时对话框大小没变,控件大小变了,我要怎么才能使对话框大小改变?

解决方案 »

  1.   

    BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
    {
    if( !CFrameWnd::PreCreateWindow(cs) )
    return FALSE;
    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs
    cs.cx = 600;
    cs.cy = 400; return TRUE;
    }
    PreCreateWindow——在这个里面
      

  2.   

    你调试看看 WM_DISPLAYCHANGE 中ScreenWidth和ScreenHeight前后是否有变化
    或者可能MoveWindow用如下格式:
    BOOL MoveWindow(          
        HWND hWnd,  //带上对话框句柄
        int X,
        int Y,
        int nWidth,
        int nHeight,
        BOOL bRepaint
    );
      

  3.   

    调试过了,ScreenWidth和ScreenHeight变了
    带句柄也不行
    SetWindowPos两种方法也一样
      

  4.   

    我把对话框的Border模式改成Resizing的话,从1024×768改成800×600时可以,但是从800×600改成1024×768时大小又不变了,而且我最好不要Resizing模式。
      

  5.   

    解决了
    void CDemoDlg::OnSize(UINT nType, int cx, int cy) 
    {
            CDialog::OnSize(nType, cx, cy);

            // TODO: Add your message handler code here
            int ScreenWidth = GetSystemMetrics( SM_CXSCREEN );
            int ScreenHeight = GetSystemMetrics( SM_CYSCREEN );        MoveWindow( 0, 0, ScreenWidth, ScreenHeight - 32, TRUE );

            GetDlgItem( IDC_FOLDER_TREE )-> MoveWindow( 10, 10, 100, 100 ); 
            ... 
    }
      

  6.   


    .h
    afx_msg void OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI);.cpp
    void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) 
    {
    .....
    }添加上面的响应
    设置最大尺寸
      

  7.   


    .h
    afx_msg void OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI);.cpp
    ...
    ON_WM_GETMINMAXINFO()
    ....
    void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) 
    {
    lpMMI->ptMaxSize = CPoint(nX, nY);
    lpMMI->ptMaxPosition = CPoint(left, top);

    lpMMI->ptMinTrackSize = CPoint(nX, nY);
    lpMMI->ptMaxTrackSize = CPoint(nX, nY);
    }
    添加上面的响应 
    设置最大尺寸 
      

  8.   

    MoveWindow最后一个参数还真没用过
      

  9.   

    跟那个参数没关系,主要是代码要放在OnSize里面