Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Drawing border to dialog using GDI+

Drawing border to dialog using GDI+

Scheduled Pinned Locked Moved C / C++ / MFC
graphicswinformshelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 11254243
    wrote on last edited by
    #1

    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);
    }

    L 1 Reply Last reply
    0
    • U User 11254243

      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);
      }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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[^].

      U 1 Reply Last reply
      0
      • L Lost User

        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[^].

        U Offline
        U Offline
        User 11254243
        wrote on last edited by
        #3

        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);

        L 1 Reply Last reply
        0
        • U User 11254243

          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);

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          It's a peculiarity of the way that closed shape points are defined. The right and bottom are actually outside the shape. If you check the MSDN documentation it is described there.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups