win32 drawing shape and StrokeAndFillPath(hDC) please help
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: win32 drawing shape and StrokeAndFillPath(hDC) please help

  1. #1
    Join Date
    Sep 2007
    Location
    Bangalore,India
    Posts
    163

    win32 drawing shape and StrokeAndFillPath(hDC) please help

    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. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,274

    Re: win32 drawing shape and StrokeAndFillPath(hDC) please help

    Quote Originally Posted by sujan.dasmahapatra View Post
    I am not implementing it in WM_PAINT but drawing is done in WM_LBUTTONUP.
    Why not in WM_PAINT?
    Victor Nijegorodov

  3. #3
    Join Date
    Sep 2007
    Location
    Bangalore,India
    Posts
    163

    Re: win32 drawing shape and StrokeAndFillPath(hDC) please help

    Because I want to do it in WM_LBUTTONUP

    Please help

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,274

    Re: win32 drawing shape and StrokeAndFillPath(hDC) please help

    Well, "I want to" is not a reason to develop your program against the design of Windows.
    Have a look at the Scribble sample in MSDN.
    Victor Nijegorodov

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,762

    Re: win32 drawing shape and StrokeAndFillPath(hDC) please help

    If you do any painting, then the Windows GUI requires that you at the least are able to fully repaint your entire window as part of the WM_PAINT message. Failure to do so will have all sorts of weird behaviour.

    You can do additional painting outside of WM_PAINT, but you must adhere to some rules, again, failure to do so will have all sorts of weird behaviour.

    What you are doing here simply won't work at all. If you do any painting at all, you MUST fully complete your painting operations within a single message.

    Trying to do some painting one a button click, and finish the painting on another button click simply won't work. There is no way for you to guarantee that nothing in between those 2 clicks happens with the DC that would even allow what you're trying. In effect, if you do painting, you're required to fully restore/reset the DC before finishing the message handler. What you're doing here cannot possibily comply to that.

    In addition, mixing Messageboxes with paint commands is asking for troubles.

  6. #6
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,762

    Re: win32 drawing shape and StrokeAndFillPath(hDC) please help

    Quote Originally Posted by Igor Vartanov View Post
    Begin/EndPaint are intended to be used in WM_PAINT only.
    it didn't look like the OP was using BeginPaint/EndPaint in his original code... He is using BeginPath/EndPath which is an entirely different beast however, were you confusing things ?

    You're right about BeginPaint/EndPaint only being used as part of WM_PAINT handlers, but that doesn't look like the issue here (or I'm missing something).

  7. #7
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,927

    Re: win32 drawing shape and StrokeAndFillPath(hDC) please help

    Sorry, my bad. He really did not.

    @sujan.dasmahapatra
    My apologies.
    Last edited by Igor Vartanov; July 10th, 2013 at 11:51 AM.
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center