使用属性表将向导定位在屏幕 win32 应用程序的中心

Positioning wizard at the centre of the screen win32 application using propertysheet

本文关键字:win32 屏幕 应用程序 定位 属性 向导      更新时间:2023-10-16

使用属性表页在 win32 应用程序中创建了两个页面向导。向导未位于屏幕中央。为了将页面定位在中心,我为第一页编写了以下代码(假设第二页将与第一页的位置一起反映),但它不起作用。我在这里做错了什么吗?

static LRESULT WINAPI sWelcomePageDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  {
   HWND hwndOwner = NULL;
   RECT rcOwner,rcDlg,rc;
   switch (uMsg) 
    {
        case WM_INITDIALOG:
             hwndOwner = GetDesktopWindow();
             GetWindowRect(hwndOwner, &rcOwner);
             GetWindowRect(hwnd, &rcDlg);
             rc.left = (rcOwner.right - rcOwner.left)/2 - (rcDlg.right - rcDlg.left)/2;
             rc.right = rc.left + (rcDlg.right - rcDlg.left);
             rc.top = (rcOwner.bottom - rcOwner.top)/2 - (rcDlg.bottom - rcDlg.top)/2;
             rc.bottom = rc.top + (rcDlg.bottom - rcDlg.top);
             SetWindowPos (hwnd, NULL, rc.left, rc.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
             SetWindowText(GetDlgItem(hwnd, IDC_WELCOMETEXTSTATIC), Info);
             break;
       case WM_COMMAND:
            break;
       case WM_NOTIFY:
            LPNMHDR lpnm = (LPNMHDR)lParam;
            switch (lpnm->code)
            {
              case PSN_SETACTIVE:
                PropSheet_SetWizButtons(GetParent(hwnd), PSWIZB_NEXT | PSWIZB_CANCEL);
                break;
              case PSN_WIZNEXT:
                SetWindowLongPtr(hwnd, DWLP_MSGRESULT, IDD_FINISHPAGE);
                break;
            }
      break;
   }
return 0;

}

传递到窗口进程的 hwnd 是向导的句柄。有关向导本身的句柄,请调用 GetParent( hwnd)。

顺便说一句,屏幕尺寸也可以通过GetSystemMetrics(),SM_CXSCREEN/SM_CYSCREEN获得。