win32 drawing shape and StrokeAndFillPath(hDC) please help

Discussion in 'Win32' started by sujan.dasmahapatra, Jul 8, 2013.

  1. sujan.dasmahapatra

    sujan.dasmahapatra Member

    Joined:
    Jun 11, 2009
    Messages:
    39
    Likes Received:
    0
    Trophy Points:
    6
    Gender:
    Male
    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;
    
    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;
    		}
    
    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
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    If you try to draw things in WM_LBUTTONUP and if you move your window using mouse, it will all be gone and so it should be redrawn in WM_PAINT.

    You have to be using WM_PAINT if you want to draw anything in an application.
     
  3. sujan.dasmahapatra

    sujan.dasmahapatra Member

    Joined:
    Jun 11, 2009
    Messages:
    39
    Likes Received:
    0
    Trophy Points:
    6
    Gender:
    Male
    Thanks for the info friend Let me try this . Thanks Sujan
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    The pleasure is all mine.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice