您的位置:首页 > 其它

MFC中CenterWindow()函数的模拟

2009-11-02 18:28 162 查看
 
 
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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mfc null