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. win32 drawing shape and StrokeAndFillPath(hDC) please help

win32 drawing shape and StrokeAndFillPath(hDC) please help

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelptutorialquestion
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.
  • A Offline
    A Offline
    appollosputnik
    wrote on last edited by
    #1

    I am trying to draw a shape or font on dialog and then fill the outline. I have 2 buttons on this 2 buttons I have the following code [code] case IDC_BUTTON1: MessageBox(hDlg, L"Start Drawing!!", L"ButtonPressed", MB_OK | MB_ICONEXCLAMATION); hDC = GetDC(hDlg); brush = CreateSolidBrush(RGB(128, 128, 128)); SelectObject(hDC, brush); hpen = CreatePen(PS_SOLID, 1, RGB(128, 0, 128)); SelectObject(hDC, hpen); BeginPath(hDC); break; case IDC_BUTTON2: MessageBox(hDlg, L"End Drawing!!", L"ButtonPressed", MB_OK | MB_ICONEXCLAMATION); EndPath(hDC); StrokeAndFillPath(hDC); DeleteObject(brush); ReleaseDC(hDlg, hDC); break; [/code] Then in the drawing part I have the following. [code] case WM_LBUTTONUP: if (IsDlgButtonChecked(hDlg, IDC_RADIO1) == BST_CHECKED ) { EndX = LOWORD(lParam); EndY = HIWORD(lParam); SetROP2(hDC, R2_XORPEN); MoveToEx(hDC, StartX, StartY, NULL); LineTo(hDC, EndX, EndY); IsDrawing = FALSE; } [/code] When I remove the BeginPath() and EndPath() functions my lines are being drawn. But when I insert this BeginPath() and EndPath() and StrokeAndFillPath(hDC); the nothing is being drawn. Why it is not doing as per the expectations. I want to draw a shape for example A with a outline. And i want it to be closed when drawing is ended and filled the hollow portion. What am I doing wrong in this ? Please help. I am not implementing it in WM_PAINT but drawing is done in WM_LBUTTONUP. Please help. Thanks a lot in advance

    L 1 Reply Last reply
    0
    • A appollosputnik

      I am trying to draw a shape or font on dialog and then fill the outline. I have 2 buttons on this 2 buttons I have the following code [code] case IDC_BUTTON1: MessageBox(hDlg, L"Start Drawing!!", L"ButtonPressed", MB_OK | MB_ICONEXCLAMATION); hDC = GetDC(hDlg); brush = CreateSolidBrush(RGB(128, 128, 128)); SelectObject(hDC, brush); hpen = CreatePen(PS_SOLID, 1, RGB(128, 0, 128)); SelectObject(hDC, hpen); BeginPath(hDC); break; case IDC_BUTTON2: MessageBox(hDlg, L"End Drawing!!", L"ButtonPressed", MB_OK | MB_ICONEXCLAMATION); EndPath(hDC); StrokeAndFillPath(hDC); DeleteObject(brush); ReleaseDC(hDlg, hDC); break; [/code] Then in the drawing part I have the following. [code] case WM_LBUTTONUP: if (IsDlgButtonChecked(hDlg, IDC_RADIO1) == BST_CHECKED ) { EndX = LOWORD(lParam); EndY = HIWORD(lParam); SetROP2(hDC, R2_XORPEN); MoveToEx(hDC, StartX, StartY, NULL); LineTo(hDC, EndX, EndY); IsDrawing = FALSE; } [/code] When I remove the BeginPath() and EndPath() functions my lines are being drawn. But when I insert this BeginPath() and EndPath() and StrokeAndFillPath(hDC); the nothing is being drawn. Why it is not doing as per the expectations. I want to draw a shape for example A with a outline. And i want it to be closed when drawing is ended and filled the hollow portion. What am I doing wrong in this ? Please help. I am not implementing it in WM_PAINT but drawing is done in WM_LBUTTONUP. Please help. Thanks a lot in advance

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

      You are probably doing it in the wrong place. All painting should be done in response to a WM_PAINT message. Doing it elsewhere means that it will be overwritten the next time the window gets repainted. Note: please put your code (properly indented) in between <pre> tags (use the code link above the edit window) so it is like:

      if (IsDlgButtonChecked(hDlg, IDC_RADIO1) == BST_CHECKED )
      {
      EndX = LOWORD(lParam);
      EndY = HIWORD(lParam);

      SetROP2(hDC, R2\_XORPEN);
      
      MoveToEx(hDC, StartX, StartY, NULL);
      LineTo(hDC, EndX, EndY);
       
      IsDrawing = FALSE;
      

      }

      Use the best guess

      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