1

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

corneliu
  • 656
  • 13
  • 37

2 Answers2

1

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.

ScottMcP-MVP
  • 10,337
  • 2
  • 15
  • 15
  • I am sorry for answering this late. I had to stop working on this project for a few days. Thank you very much for your help. I declared a constant in Resource.h like this `#define IDD_MYVIEW 301` and I declared the enum in the header file of my class like this `enum { IDD = IDD_MYVIEW };` and then I changed all references from CView to CFormView and modified the signature of the constructor like this `CMyView::CMyView():CFormView( CMyView::IDD )`. I still get the same error in the same place. Did I forget anything? – corneliu Nov 16 '13 at 03:08
  • Continued in this new comment because of length restriction -> I did create another project that uses a CFormView from the beginning and it works but I would continue with the old project rather than moving all the stuff to the new project. I took a look at how the class CFormView is used but I couldn't find anything useful other than the stuff that I have already mentioned. What should I do next? – corneliu Nov 16 '13 at 03:09
  • Did you just make up the number 301? The number you need is the number of the dialog resource, and that number should already be present in resource.h – ScottMcP-MVP Nov 17 '13 at 17:12
  • Yes, I have made up the number myself. I checked all the existing constants in resource.h and I couldn't find any constant that matched the name of my view. I assigned an arbitrary unique int to my new constant. I am using Visual Studio. How can I tell which constant is already linked to my view? – corneliu Nov 19 '13 at 03:18
  • A CFormView displays a dialog template. A dialog template is created visually in the resource editor by dragging controls onto it from a toolbar. Did you create a dialog template for your CFormView? The ID of that dialog template (like IDD_DIALOG1) is the symbol needed. Like enum { IDD = IDD_DIALOG1 }; – ScottMcP-MVP Nov 19 '13 at 15:56
  • I did not start with a CFormView. I started with a CView which I am trying to convert to a CFormView. It seems that the CView did not have an ID registered in Resource.h. That's why I created my own. There is something missing. Anyway, I gave up. I will start from scratch with a CFormView and I will move all the code there. Thank you for your help. – corneliu Nov 23 '13 at 14:57
0

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
Pooya
  • 6,083
  • 3
  • 23
  • 43