MFC-SetRect设置指定矩形的坐标

发布时间 2023-04-15 07:46:58作者: 天子骄龙

 

    HDC hdc = ::GetDC(m_hWnd);
    RECT rect = { 10,10,50,100 };
    HBRUSH hbr;
    hbr = CreateSolidBrush(RGB(255, 0, 0));
    SelectObject(hdc, hbr);

    int f = FrameRect(hdc, &rect, hbr);//绘制矩形边框
    BOOL bb=SetRect(&rect, 100, 10, 150, 100);//设置指定矩形的坐标
    /*
    参数1:LPRECT lprc  指向RECT 结构的指针
    参数2:int xLeft    指定矩形左上角的X坐标
    参数3:int yTop     指定矩形左上角的Y坐标
    参数4:int xRight   指定矩形右下角的X坐标
    参数5:int yBottom  指定矩形右下角的Y坐标
    返回值:如果函数成功,返回非零值;否则返回零值
    
    */

    f = FrameRect(hdc, &rect, hbr);

    DeleteObject(hbr);
    ::ReleaseDC(m_hWnd, hdc);