L
LokanathNayak
Guest
Hi,
I created a dialog of polygon region, and trying to draw the frame around the dialog. I am able to achieve it using CDC::FrameRgn.
But if i want to achieve the same using GDI+, i am not able to do it. I used DrawPolygonPath, but i am seeing the border only in left and top of the dialog. I have attached the my code below. Please help me how to frame the dialog using 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
}
#define USING_CDC
void CPolygonDlg::OnPaint()
{
CPaintDC dc(this);
#ifdef USING_CDC
CBrush *pBrush = new CBrush(RGB(255,0,0));
dc.FrameRgn(&m_rgnShape,pBrush,1,1);
#else
Graphics graphics(dc.m_hDC);
GraphicsPath gp;
Point point[4];
point[0] = Point(vertex[0].x,vertex[0].y);
point[1] = Point(vertex[1].x,vertex[1].y);
point[2] = Point(vertex[2].x,vertex[2].y);
point[3] = Point(vertex[3].x,vertex[3].y);
gp.AddPolygon(point,4);
Pen pen(Color(255, 255, 0, 0));
graphics.DrawPath(&pen, &gp);
#endif
}
Thanks
Continue reading...
I created a dialog of polygon region, and trying to draw the frame around the dialog. I am able to achieve it using CDC::FrameRgn.
But if i want to achieve the same using GDI+, i am not able to do it. I used DrawPolygonPath, but i am seeing the border only in left and top of the dialog. I have attached the my code below. Please help me how to frame the dialog using 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
}
#define USING_CDC
void CPolygonDlg::OnPaint()
{
CPaintDC dc(this);
#ifdef USING_CDC
CBrush *pBrush = new CBrush(RGB(255,0,0));
dc.FrameRgn(&m_rgnShape,pBrush,1,1);
#else
Graphics graphics(dc.m_hDC);
GraphicsPath gp;
Point point[4];
point[0] = Point(vertex[0].x,vertex[0].y);
point[1] = Point(vertex[1].x,vertex[1].y);
point[2] = Point(vertex[2].x,vertex[2].y);
point[3] = Point(vertex[3].x,vertex[3].y);
gp.AddPolygon(point,4);
Pen pen(Color(255, 255, 0, 0));
graphics.DrawPath(&pen, &gp);
#endif
}
Thanks
Continue reading...