MFC:使用GDI +绘制对话框边框

时间:2015-04-12 04:47:15

标签: mfc

我将对话框修改为多边形区域对话框。然后我试图框架/绘制边框。使用设备上下文CRgn :: FrameRgn,我打包在对话框周围绘制边框。但我想用Gdi +实现这一目标。我做了如下,但边框仅出现在对话框的左侧和顶部。 有人可以帮忙解决这个问题。

CPoint vertex[4];
BOOL CPolygonDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();

    ModifyStyle(WS_CAPTION,0);
    ModifyStyle(WS_BORDER,0);

     CRect rect(400,200,900,700);
     CRect wr = rect;
    AdjustWindowRect( wr, 0, FALSE );
    MoveWindow(wr); 

    GetClientRect( rect );
    CRect csr = rect;
    ClientToScreen( csr );



    vertex[0] = CPoint(rect.left,rect.top);
    vertex[1] = CPoint(rect.right,rect.top);
    vertex[2] = CPoint(rect.right,rect.bottom);
    vertex[3] = CPoint(rect.left,rect.bottom);


     m_rgnShape.CreatePolygonRgn( vertex, 4, ALTERNATE );
    m_rgnShape.OffsetRgn( CPoint( csr.TopLeft() - wr.TopLeft() ) );
    SetWindowRgn( (HRGN)m_rgnShape.Detach(), TRUE );
    m_rgnShape.CreatePolygonRgn( vertex, 4, ALTERNATE );




    return TRUE;  // return TRUE  unless you set the focus to a control
}

void CPolygonDlg::OnPaint()
{
Graphics graphics(dc.m_hDC);
    CRect rect;
    GetClientRect(rect);
GraphicsPath gp;
    Point point[4];
    point[0] = Point(rect.left,rect.top);
    point[1] = Point(rect.right,rect.top);
    point[2] = Point(rect.right,rect.bottom);
    point[3] = Point(rect.left,rect.bottom);
    gp.AddPolygon(point,4);
    Pen pen(Color(255, 255, 0, 0));
    graphics.DrawPath(&pen, &gp);
}

由于

1 个答案:

答案 0 :(得分:0)

当您致电GetClientRect()时,它会返回窗口客户区的大小 - 您可以轻松绘制的部分,以及执行CPaintDC dc(this);时设备上下文控制的部分在您的OnPaint()方法中。

您遇到的问题是您的对话框窗口有边框,您需要处理 WM_NCPAINT 才能在边框区域上绘制。