在显示一个对话框时如何设置对话框在屏幕上的的位置!!!!!!!
如:我想将一个基于对话框的应用程序在运行后,对话框显示在屏幕的左边,而不是系统默认的中间。

解决方案 »

  1.   

    BOOL SetWindowPos( const CWnd* pWndInsertAfter, int x, int y, int cx, int cy, UINT nFlags );
    or
    void MoveWindow( int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE );
      

  2.   

    creat()后就可以用上面2个函数就能实现
      

  3.   

    写了个函数,在你的对话框创建后调用,参数为对话框的m_hWnd,当然你改成对话框的成员函数也可以.
    void SetWindowLeft(HWND hDlg)
    {
    int srcWidth, srcHeight;
    int frmWidth, frmHeight;
    int left, top;
    RECT rect;
    GetWindowRect(hDlg, &rect);
    srcWidth = GetSystemMetrics(SM_CXSCREEN);
    srcHeight = GetSystemMetrics(SM_CYSCREEN);
    frmWidth = rect.right - rect.left;
    frmHeight = rect.bottom - rect.top; 
    left = 0;
    top = (srcHeight - frmHeight)/2;
    MoveWindow(hDlg, left, top, frmWidth, frmHeight, TRUE); 
    }