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);
User 11254243
Posts
-
Drawing border to dialog using GDI+ -
MFC: flickering issue with GDI+I create a sample dialog application which has a circle drawn. Also on mouse move the circle will be re-drawn. I am providing my code below. Its also compilable. I tried using double buffering and erasebackground, i was not getting the flickering issue, but i observed that the drawining is not erased properly. So to erase, in OnPaint i wrote the erasing code. Again i am facing the flickering issue. CPaintDC dc(this); GetClientRect(&clientRect); circle = clientRect; circle.DeflateRect(100,100); dc.SelectStockObject(NULL_BRUSH); dc.SelectStockObject(NULL_PEN); dc.FillSolidRect(circle, ::GetSysColor(COLOR_BTNFACE)); Bitmap buffer(circle.right, circle.bottom); Graphics graphicsbuf(&buffer); Graphics graphics(dc.m_hDC); graphicsbuf.SetSmoothingMode(SmoothingModeHighQuality); SolidBrush brush(Color(255,71,71,71)); Pen bluePen(Color(255, 0, 0, 255),1); graphicsbuf.DrawEllipse(&bluePen,Rect(circle.left,circle.top,circle.Width(),circle.Height())); graphicsbuf.SetSmoothingMode(SmoothingModeHighQuality); graphics.DrawImage(&buffer, 0, 0); } void CPOCDlg::OnMouseMove(UINT nFlags, CPoint point) { m_point = point; InvalidateRect(circle,FALSE); CDialogEx::OnMouseMove(nFlags, point); } BOOL CPOCDlg::OnEraseBkgnd(CDC* pDC) { return TRUE; } Please let me know if i am doing any mistake.
-
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);
}