这里给出的方法是在 WM_INITDIALOG 事件里实现居中处理。
下面是对话框窗口过程以及主函数:
// EncryptMain.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
BOOL CALLBACK MainDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_MAIN), NULL, MainDialogProc);
return 0;
}
BOOL CALLBACK MainDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
{
HWND hwndOwner = NULL;
RECT rcOwner, rcDlg, rc;
// Get the owner window and dialog box rectangles.
if ((hwndOwner = GetParent(hDlg)) == NULL)
{
hwndOwner = GetDesktopWindow();
}
GetWindowRect(hwndOwner, &rcOwner);
GetWindowRect(hDlg, &rcDlg);
CopyRect(&rc, &rcOwner);
WIN32对话框居中实现

本文介绍如何在WM_INITDIALOG事件中处理,使对话框在启动时自动居中。提供了对话框窗口过程和主函数的代码示例。
最低0.47元/天 解锁文章
1106

被折叠的 条评论
为什么被折叠?



