Page 1 of 1

Drawing Window?

PostPosted: Jul 12, 2001 @ 9:09pm
by Tom
I'm using eVC++ and MFC.  I want to add a window or control, that I can draw into, to a tab control thats on a formview.  I'm going to draw a graph into the window or control and need horizontal scrolling capabilities in it.<br><br>As a first try, I created a new class (CDrawingWnd) derived from the generic CWnd.  I overrode OnPaint to do my drawing.  I then created a custom control on the tab and set the Class of the custom control to CDrawingWnd.<br><br>It didn't work.  I realized I probably need to register a new window class and set that as my class in the custom control... or... create the window programmatically instead of adding a custom control in a template.<br><br>Am I even on the right track?  Is there a better way.  I'd rather spend the time working on the logic of my app then trying to figure out the best way to do a drawing window.  Can you just use a static or edit control and get its DC and start drawing?<br><br>If this isn't the right track, just point me towards it and I'll figure out the details.  Thanks in advance.<br><br>Tom

Re: Drawing Window?

PostPosted: Jul 12, 2001 @ 9:57pm
by Dan East
There are a dozen ways to go. If your class will pretty much be display only, then derive a new class from CStatic. That will allow you to incorporate it into dialogs a bit easier. Override the OnPaint and do your drawing there. Make sure you don't call the base class's OnPaint. The part I'm not getting is where you "created a custom control on the tab". Are you trying to use your control in a dialog, or CWnd::Create it manually? <br><br>Dan East

Re: Drawing Window?

PostPosted: Jul 13, 2001 @ 3:36pm
by Tom
Thanks for the info Dan!  Thats exactly what I needed to know.  It will be pretty much display only.  I thought I might be able to use something derived from the CStatic or CEdit classes, but wasn't sure.  I thought their functions to output the text might get in the way, but if just avoiding the base class OnPaint will avoid that then thats easy.<br><br>About adding the custom control:  I was trying to add it to a dialog template instead of creating it manually with the CWnd::Create.  The custom control option puts up a blank rectangle and in the properties has a spot for the class name, but that probably is for the name of a registered window/control class rather than just the name of a derived class like I was trying to use.  It doesn't matter now since I will be using one derived from CStatic.<br><br>Thanks again.<br>

Re: Drawing Window?

PostPosted: Jul 13, 2001 @ 7:14pm
by Dan East
Don't bother with the Custom Control junk. Just place a CStatic in the dialog box where you want it and at the desired size. Create a class for your dialog box, then go into the Class Wizard and create a Variable for your CStatic control (a control variable, which I think is the only type allowed for static controls). Make sure you assign it a new ID instead of the default IDC_STATIC. Then in the header file for your dialog class find the member variable declaration for that CStatic var you created (it will be in the odd-colored Class Wizard generated block). Change it to use your custom CStatic-derived class instead of CStatic. Of course you'll have to include the header for your custom class in that header.<br>That's about the easiest way to use a custom control in a dialog.<br><br>Dan East<br><br>

Re: Drawing Window?

PostPosted: Jul 16, 2001 @ 4:35pm
by Tom
Thanks again Dan!  It works!<br><br>And I discovered something else cool.  I derived my custom CDrawingWnd class from CStatic, added the CStatic control to my dialog template and then added the header file for CDrawingWnd to my dialogs .h file before I went into the class wizard to create my control variable for the CStatic control.  It recognized that CDrawingWnd was derived from CStatic and gave me the option to create a CDrawingWnd control variable as well as a CStatic... so I didn't even need to go back in and edit the file afterward.<br><br>Tom