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. Erase Window

Erase Window

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structures
2 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.
  • S Offline
    S Offline
    sidkraft
    wrote on last edited by
    #1

    // MainFrame.cpp #include "MainFrame.h" #include // for __min() "2 underscores" #define ID_SB 210 // All child windows require an // identifier. Not used here. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) // message calls this function ON_WM_PAINT() // void OnPaint() ON_WM_LBUTTONDOWN() // void OnLButtonDown(...) ON_WM_RBUTTONDOWN() //Left Button Down Add************ ON_WM_SIZE() // void OnSize(...) ON_WM_CHAR() // void OnChar(...) END_MESSAGE_MAP() CMainFrame::CMainFrame() // Constructor { // Step 1: Register a window class if wish // Step 2: Create the window Create(NULL, "Ex06a_StatusBar & Shapes", WS_OVERLAPPEDWINDOW, CRect(0,0,360,250)); // Step 3: Create a status bar myStatusBar.Create (WS_CHILD | WS_VISIBLE, CRect(1,2, 1,2), this, ID_SB); int rtEdges[] = {45,140,250}; // Right edge of panes myStatusBar.SetParts (3,rtEdges); // Step 4: Create Pens, Brushes, Fonts, etc penReg.CreatePen (PS_SOLID, 10, RGB(0,0,255)); // Step 5: Initialize application variables nPts = 0; ShapeKind = 'L'; CenterWindow(); }; void CMainFrame::OnPaint() { CPaintDC dc (this); dc.TextOut (1,1,"Click left button repeatedly. Press L, B, P"); CString s; s.Format("# pts:%d", nPts); myStatusBar.SetText (s,0,0); s.Format ("Shape(L,B,P): %c", ShapeKind); myStatusBar.SetText(s,2,SBT_POPOUT); if (nPts <= 1) return; dc.SelectObject (&penReg); switch (ShapeKind) { case 'L': dc.Polyline (ShapePts, nPts); break; case 'P': dc.SelectStockObject(LTGRAY_BRUSH); dc.Polygon (ShapePts,nPts); break; case 'B': if ((nPts - 4) % 3 == 0) dc.PolyBezier(ShapePts,nPts); else { // use max legal # of pts int n = (nPts - 4)/3; int NPts = __min(n*3 + 4, nPts); dc.PolyBezier(ShapePts,NPts); // then draw polyline dc.SelectStockObject (BLACK_PEN); dc.Polyline (ShapePts,nPts); } break; default: break; } } void CMainFrame::OnLButtonDown (UINT nFlags, CPoint pt) { if (nPts >= 99) // array full return; else { ShapePts[nPts] = pt; nPts++; CString s; s.Format("Last pt:(%d, %d)",pt.x, pt.y); myStatusBar.SetText (s,1,SBT_NOBORDERS);

    C 1 Reply Last reply
    0
    • S sidkraft

      // MainFrame.cpp #include "MainFrame.h" #include // for __min() "2 underscores" #define ID_SB 210 // All child windows require an // identifier. Not used here. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) // message calls this function ON_WM_PAINT() // void OnPaint() ON_WM_LBUTTONDOWN() // void OnLButtonDown(...) ON_WM_RBUTTONDOWN() //Left Button Down Add************ ON_WM_SIZE() // void OnSize(...) ON_WM_CHAR() // void OnChar(...) END_MESSAGE_MAP() CMainFrame::CMainFrame() // Constructor { // Step 1: Register a window class if wish // Step 2: Create the window Create(NULL, "Ex06a_StatusBar & Shapes", WS_OVERLAPPEDWINDOW, CRect(0,0,360,250)); // Step 3: Create a status bar myStatusBar.Create (WS_CHILD | WS_VISIBLE, CRect(1,2, 1,2), this, ID_SB); int rtEdges[] = {45,140,250}; // Right edge of panes myStatusBar.SetParts (3,rtEdges); // Step 4: Create Pens, Brushes, Fonts, etc penReg.CreatePen (PS_SOLID, 10, RGB(0,0,255)); // Step 5: Initialize application variables nPts = 0; ShapeKind = 'L'; CenterWindow(); }; void CMainFrame::OnPaint() { CPaintDC dc (this); dc.TextOut (1,1,"Click left button repeatedly. Press L, B, P"); CString s; s.Format("# pts:%d", nPts); myStatusBar.SetText (s,0,0); s.Format ("Shape(L,B,P): %c", ShapeKind); myStatusBar.SetText(s,2,SBT_POPOUT); if (nPts <= 1) return; dc.SelectObject (&penReg); switch (ShapeKind) { case 'L': dc.Polyline (ShapePts, nPts); break; case 'P': dc.SelectStockObject(LTGRAY_BRUSH); dc.Polygon (ShapePts,nPts); break; case 'B': if ((nPts - 4) % 3 == 0) dc.PolyBezier(ShapePts,nPts); else { // use max legal # of pts int n = (nPts - 4)/3; int NPts = __min(n*3 + 4, nPts); dc.PolyBezier(ShapePts,NPts); // then draw polyline dc.SelectStockObject (BLACK_PEN); dc.Polyline (ShapePts,nPts); } break; default: break; } } void CMainFrame::OnLButtonDown (UINT nFlags, CPoint pt) { if (nPts >= 99) // array full return; else { ShapePts[nPts] = pt; nPts++; CString s; s.Format("Last pt:(%d, %d)",pt.x, pt.y); myStatusBar.SetText (s,1,SBT_NOBORDERS);

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      It will repaint the window. If you want to erase the current shape, you need to change ShapeKind first. Christian Graus - Microsoft MVP - C++

      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