使用Propertysheetpage在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;
}
答案 0 :(得分:0)
传递到窗口proc的hwnd是向导页面的句柄。对于向导本身的句柄,请调用GetParent(hwnd)。
顺便说一下,屏幕尺寸也可以通过GetSystemMetrics(),SM_CXSCREEN / SM_CYSCREEN获得。