1.将Dialog的父窗口设为桌面.
2.得到屏幕尺寸再根据比例SetWindowPos.

解决方案 »

  1.   

    好象dialog有个方法
    不过忘了 :(
      

  2.   

    CDialog dlg
    dlg.CenterWindow();
      

  3.   

    选中DIALOG对话框属性页-》more style->Center属性即可
      

  4.   

    你也可以取得屏幕的宽高,取得你的DIALOG的宽高,再计算出DIALOG的位置,然后使用MoveWindow。
    试试看,祝你好运!
    有空到我的主页去看看。http://shadowsoft.126.com
      

  5.   

    在调用MessageBox()前,通过安装一个WH_CBT HOOK, 来监视window的create动作,通过WH_CBT HOOK中作为参数得到的HWND,进行你想要的操作. 操作完成后,卸载WH_CBT HOOK. 微软的MFC中,经常可以见到类似的用法, 比如subclass...
    以下是将调用MessageBox()产生的Dialog居中的例子,不过有些大材小用了.//Set up the CBT hook
    threadId = GetCurrentThreadId();
    hHook = SetWindowsHookEx(WH_CBT, HookProc, NULL,threadId);int bContinue = ::MessageBox(hParent,"Shutdown HTTP Service?",
    "HTTP Service",
                                         MB_YESNO|MB_ICONWARNING);
    ****************************************
    LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam)
    {
    RECT rectMsg,rectForm;
    if( nCode == HCBT_ACTIVATE )
    {
    int x,y;
    //Get the coordinates of desktop to
    //determine where the center of desktop is
    GetWindowRect( ::GetDesktopWindow(), &rectForm); GetWindowRect((HWND)wParam, &rectMsg); x = (rectForm.left + (rectForm.right - rectForm.left) / 2) -
    ((rectMsg.right - rectMsg.left) / 2);
    y = (rectForm.top + (rectForm.bottom - rectForm.top) / 2) -
    ((rectMsg.bottom - rectMsg.top) / 2); // Position the location of msgbox
    SetWindowPos( (HWND)wParam, 0, x, y, 0, 0,
                             SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);

    //Release the CBT hook
                      UnhookWindowsHookEx(hHook);
    return FALSE;
    }
    return CallNextHookEx(hHook,nCode,wParam,lParam);
    }
      

  6.   

    我觉得只要在OnInitDialog()函数中调用以下语句就可以了;
    AfxGetMainWnd()->CenterWindow();
    如果你要改变窗口的宽高则只要重载BOOL CAboutDlg::PreCreateWindow(CREATESTRUCT& cs) 函数,
    其中的cs.cx为高, cs.cy为宽
      

  7.   

    在OnInitDialog()
    中使用CenterWindow()
      

  8.   

    把Dialog的父窗口设为NULL
    或用CenterWindow
      

  9.   

    考,这么简单还需要hook
    CDialog::OnMove(int x, int y)
    {
    int cx,cy,x,y;
    CRect rtMe;
    this->GetWindowText(&rtMe);
    cx=rtMe.Width();
    cy=rtMe.Height();
    HWND hDeskWnd=::GetDesktopWindow();
    CRect rtDesk;
    ::GetClientRect(hDeskWnd,&rtDesk);
    int m_nScrW=rtDesk.Width();
    int m_nScrH=rtDesk.Height();
    x=(m_nScrW-cx)/2;
    y=(m_nScrH-cy)/2;
    this->MoveWindow(x,y,cx,cy);}
      

  10.   

    楼上的xghome(东楼) ,你的方法能将 调用 SDK API函数
    ::MessageBox(...);
    产生的弹出窗口放到desktop的任意指定位置吗?
      

  11.   

    再说一点,Dialog默认是在父窗口的中心出现,只要我们的窗口能在屏幕中心不动,以我们为父窗口的所有派生窗口只要是DoModel状态,默认都是在父窗口中心,也就是屏幕中心