Question

I have a CView and I've been painting stuff on it just fine. Then I realized I needed to add some controls like text boxes and combo boxes to my CView. So I am trying to convert my CView into a CFormView which does not have a default constructor. But I need a default constructor for this line IMPLEMENT_DYNCREATE(CMyView, CFormView) so I have created a default constructor like this CMyView::CMyView():CFormView( ( UINT )666 ) { ... }. That 666 is because I don't know which argument I am supposed to pass there. I am guessing that I need to pass the ID of my CMyView class. I can't find the id of my CMyView class which was originally created by the Visual Studio project wizard automatically. Where should I look for it? When I run the program I get this error: First-chance exception at 0x75AEC41F in myapp.exe: Microsoft C++ exception: CInvalidArgException at memory location 0x003CF134. Critical error detected c0000374 myapp.exe has triggered a breakpoint. And it stops at line 51 in free.c So my question is: how can I fix this? Also I want to keep the stuff that I previously painted in my former CView, now CFormView. Is the CFormView able to paint like the CView? If not, should I use a split pane in my CMainFrame and have a CView and a CFormView? I might have used terms specific to Java swing and I apologize for that. I am new to MFC and C++. Thank you in advance, Corneliu

Was it helpful?

Solution

The CFormView constructor needs the ID of the form's dialog template to be passed in. That is the template you create in the visual editor. You can see how this works by creating a little test project with a CFormView to make your declarations look like the MFC declarations in the test project.

The CFormView can be painted like a CView (in OnDraw), but you might have undesired effects on the controls if you do any scaling or scrolling of the view.

Other alternatives for mixing controls with painted output are (1) Using CControlBar to put controls on the edge of the view or (2) Put a CStatic on the CFormView and do your painting in the CStatic.

OTHER TIPS

Check out Resources.rc.

You can try adding something like this:

IDD_DIALOG1 DIALOG  0, 0, 400, 400
STYLE DS_SETFONT | WS_CHILD
FONT 8, "MS Sans Serif"
BEGIN
END
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top