0
votes

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.

1

1 Answers

3
votes

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.