void CenterWindow(HWND hWnd)
{
HWND hParentOrOwner;
RECT rc, rc2;
int x,y;
if((hParentOrOwner=GetParent(hWnd))==NULL)
{
SystemParametersInfo(SPI_GETWORKAREA,0,&rc,0);
}
else
{
GetClientRect(hParentOrOwner, &rc);
}
GetWindowRect(hWnd, &rc2);
x = ((rc.right-rc.left) - (rc2.right-rc2.left)) / 2 +rc.left;
y = ((rc.bottom-rc.top) - (rc2.bottom-rc2.top)) / 2 +rc.top;
SetWindowPos(hWnd,HWND_TOP,x, y,0, 0,SWP_NOSIZE);
}
|