-
July 8th, 2013, 08:53 AM
#1
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
-
July 8th, 2013, 09:37 AM
#2
Re: win32 drawing shape and StrokeAndFillPath(hDC) please help
Originally Posted by sujan.dasmahapatra
I am not implementing it in WM_PAINT but drawing is done in WM_LBUTTONUP.
Why not in WM_PAINT?
Victor Nijegorodov
-
July 8th, 2013, 10:56 AM
#3
Re: win32 drawing shape and StrokeAndFillPath(hDC) please help
Because I want to do it in WM_LBUTTONUP
Please help
-
July 8th, 2013, 11:06 AM
#4
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
-
July 9th, 2013, 07:23 AM
#5
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.
-
July 10th, 2013, 06:44 AM
#6
Re: win32 drawing shape and StrokeAndFillPath(hDC) please help
Originally Posted by Igor Vartanov
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).
-
July 10th, 2013, 11:49 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|