现在的位置: 首页 > 综合 > 正文

MFC中CenterWindow()函数的模拟

2013年06月08日 ⁄ 综合 ⁄ 共 427字 ⁄ 字号 评论关闭
 

 

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);
}

抱歉!评论已关闭.