0

I'm using MFC (yes must be MFC and no I can't interop with .Net) to create a CFrameWnd.

My goal is to create a CFrameWnd containing a CFormView which is based on a Dialog Template that resembles something like:

enter image description here

I have got the frame and view to display, and I have an Edit control on there. Now what I want is to have a CToolbar aligned to the top of the Edit Text control but not docked to the top frame.

Ideally I would like to have a child frame/view that I can dynamically add in place of the Statement Group. That way I could just dock the toolbar as normal.

The thing that I find odd is that I could easily achieve this if I had a splitter in there by using the CreateView function. I really don't want to have a splitter and feel there ought to be another way.

In summary, these are the question I need help with:

  • Q1 - How can I have a CFrameWnd within a CView (like what CSplitter::CreateView does)?
  • Q2 - How can I position a toolbar within a CView without docking or floating it within another frame (I'm more than willing to resize, position it manually if only I knew how)?

Now I really appreciate how easy things are in .Net.

steinybot
  • 5,491
  • 6
  • 37
  • 55

1 Answers1

3

I wouldn't recommend sticking a CFrameWnd within a CView. You'll be fighting MFC all the way, basically living in a world of ASSERTs as the internal functionality such as message routing assumes that Frames don't live in views.

Instead just use a CWnd instead of the CFrameWnd and in the 'Create' method manually create the toolbar and the edit ctrl and size and position them yourself (create a AdjustLayout method that uses CMFCToolbar::CalcFixedLayout to adjust the position of your other components).

A great example of this is in the Visual Studio sample app PropertiesViewBar.cpp:

http://msdn.microsoft.com/en-us/library/bb983983(v=vs.90).aspx

Note: You might need to override OnCmdMsg to extend the message routing to the internal controls.

snowdude
  • 3,854
  • 1
  • 18
  • 27
  • Thanks a bunch. I hadn't looked at the samples but they are pretty good. Going from our existing code sent me down the wrong path. Is it just me or is the documentation a little vague / cryptic as to which control is best suited for a particular task? I need a better strategy for determining which controls to use. It seems so much more intuitive in .Net. – steinybot Apr 19 '11 at 03:26
  • Yeah, documentation isn't very good at all. What's needed is an updated version of the excellent Professional MFC book to cover the new feature pack. I use a product called FileLocator Pro to navigate through the MFC source and sample apps. – snowdude Apr 19 '11 at 08:52