本篇文章属于《518抽奖软件开发日志》系列文章的一部分。
我在开发《518抽奖软件》(www.518cj.net)的时候,需要对话框居中的功能。对话框默认是居中的,但是要移动对话框到第二屏并居中,所以要自己实现代码。通过关键函数SystemParametersInfo~SPI_GETWORKAREA获得屏幕除任务栏外的区域。具体代码如下。
void Tfuns::center_box(HWND hDlg)
{
RECT desk = { 0 };
SystemParametersInfo(SPI_GETWORKAREA, 0, &desk, 0);
int cx = desk.right - desk.left;
int cy = desk.bottom - desk.top;
RECT rc = { 0 };
GetWindowRect(hDlg, &rc);
int wnd_w = rc.right - rc.left;
int wnd_h = rc.bottom - rc.top;
int x = (cx - wnd_w) / 2 + desk.left;
if (x < 0) x = 0;
int y = (cy - wnd_h) / 2 + desk.top;
if (y < 0) y = 0;
SetWindowPos(hDlg, NULL, x, y, 0, 0, SWP_NOSIZE);
}
本文介绍了在开发518抽奖软件时,如何通过SystemParametersInfo和相关函数获取屏幕工作区信息,然后调整对话框的位置,使其在第二屏幕居中显示。
663

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



