开发者

How to add canvas in MFC Dialog?

I wa开发者_StackOverflownt to create an application which main window has canvas (or something where I can draw custom things) and some controls, like buttons and edit fields. But I got stuck about how to do it.

I tried to create MFC with SDI, but how to add control to CDC..? I tried to create one dialog with buttons and edit fields, but which control refers to something I can draw at..?

Please, enlighten me how to do this..


Its been a few years for me, but here goes:

I don't think that MFC has a specific canvas control. Instead, when I wanted a drawing surface, I added a group box to the form in design mode. I made the group box invisible, so it would not show up at runtime.

In the OnCreate handler for the form view, I created a CWnd, and gave it the size and location of the invisible group box.

I set up an OnPaint message handler for the CWnd, and voila, instant graphics canvas, or a canvas for whatever else you may need.

Now, this was last done five years ago, and MFC may have advanced incrementally since then, but this is the general mechanism.


Instead of SDI, use a Dialog based application. You can easily add any controls you wish to a dialog.

You will probably want to make the app resizable. Set the border style to Thick and enable the minimize and Maximize buttons. Override OnSize to move and/or resize the controls as the dialog size changes. Override OnSizing if you need to set a minimum size for the window.

The easiest way to do arbitrary drawing on the dialog is to override OnPaint. Define an area of the dialog to contain your custom drawing, perhaps surrounding it with a frame control, and just draw into the DC that OnPaint creates.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜