Click here to Skip to main content
15,917,859 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I would like to create MS Paint program by using MFC CDialog. I have problem in creating paint canvas. I don't want to draw directly on CDialog. I would like to put something on CDialog as a paint canvas. I mean, I would like to draw lines on white canvas. I tried the following methods.
1. I used mousemove events and pen on CDialog. I can draw and paint on CDialog. But I don't want to draw directly on CDialog.
2. I created GroupBox on CDialog to use as a canvas. By using CRect, I filled the GroupBox by white color. At that time, that rectangle was colored by white. It is what I need. Then, I use mousemove events and pen to draw on GroupBox. But, I can't draw lines on white rectangle. I can't see any lines that I draw.
3. I created GroupBox Class based on CStatic Class. Use OnEraseBkgnd(CDC* pDC) event, to fill GroupBox with white color. Then I add OnMouseMove, OnLButtonDown events there to handle mouse events. Then I added that class to CDialog. But, the problem is mouse events don't work for GroupBox. Am I right?

Summarizing, my requirement is to create a paint canvas and draw on it. But I don't know how to do it. Could anyone give me guidelines on it? Thanks in advanced.
Posted

I got the solution after trying several ways. My solution is as follow.
Create a canvas by using Picture Control. Fill color in Picture Control by overwriting OnEraseBkgnd event.
Set Picture Control Properties as Transparent "True", and Notify "True". Then, overwrite mouse events of Picture Control. Finally, I can get MS paint like canvas and drawing features.
Thanks all for thinking on my problem.
 
Share this answer
 
Probably the most flexible option is simply to create a control based on CWnd. Another option that I think will work is to create a class based on CButton. CButton certainly responds to user inputs, and you could draw it flat to hide the fact that it is a button.
 
Share this answer
 
Comments
April2004 12-Mar-11 13:08pm    
I think Microsoft Paint Canvas is not based on CButton. Am I right?
I would like to get the one similar to Microsoft Paint Canvas. If you have some ideas, please let me know.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900