Drawing border to dialog using GDI+
-
I modified my dialog to a polygon region dialog. Then i am trying to frame/draw the border.Using device context the CRgn::FrameRgn, i am bale to draw the border around the dialog. But i want to achieve this using Gdi+. I did as below, but the border is appearing only on left and top of the dialog. Can someone please help on this.
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);
} -
I modified my dialog to a polygon region dialog. Then i am trying to frame/draw the border.Using device context the CRgn::FrameRgn, i am bale to draw the border around the dialog. But i want to achieve this using Gdi+. I did as below, but the border is appearing only on left and top of the dialog. Can someone please help on this.
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);
} -
I think you should send the array of points (and you have omitted the last one) to the
AddLines
function, as described in https://msdn.microsoft.com/en-us/library/windows/desktop/ms535599(v=vs.85).aspx[^].Hi, Thanks for your solution. I used AddLine and the same vertex. Still it was not working. Then i decreased 1 from right and bottom, now its working. Is it something like i need to use offset or something. I dont want to hardcode. GraphicsPath gp; Point point[5]; point[0] = Point(vertex[0].x,vertex[0].y); point[1] = Point(vertex[1].x-1,vertex[1].y); point[2] = Point(vertex[2].x-1,vertex[2].y-1); point[3] = Point(vertex[3].x,vertex[3].y-1); point[4] = Point(vertex[0].x,vertex[0].y); gp.AddLines(point,5); Pen pen(Color(255, 255, 0, 0)); graphics.DrawPath(&pen, &gp);
-
Hi, Thanks for your solution. I used AddLine and the same vertex. Still it was not working. Then i decreased 1 from right and bottom, now its working. Is it something like i need to use offset or something. I dont want to hardcode. GraphicsPath gp; Point point[5]; point[0] = Point(vertex[0].x,vertex[0].y); point[1] = Point(vertex[1].x-1,vertex[1].y); point[2] = Point(vertex[2].x-1,vertex[2].y-1); point[3] = Point(vertex[3].x,vertex[3].y-1); point[4] = Point(vertex[0].x,vertex[0].y); gp.AddLines(point,5); Pen pen(Color(255, 255, 0, 0)); graphics.DrawPath(&pen, &gp);