0

My program/environment...VS2010, C++, MFC100, CWinAppEx, CMDIFrameWndEx. MFC feature pack.

I am creating and handling a CPreviewView derivative. My method treats this preview view as a normal view that the user can keep up and active. Where as the default PreviewView paints over the current view and 'takes over' the child frame.

One thing I can't figure out is how to gain control over the ON_UPDATE_COMMAND_UI message maps that should be directed to all CDocuments. When a CPreviewView is created it somehow disables all the command handlers to CDocuments. The command handlers to CViews are still up and working.

All Documents open in my MDI app don't receive their ON_UPDATE_COMMAND_UI messages. I can move these message handlers out to the View, or Frame but there are too many to do this efficiently.

Does anyone know where in the CPreviewView class turns off document handlers?

diox8tony
  • 348
  • 3
  • 13
  • Try putting a breakpoint in `CView::OnCmdMsg(...)` and following the logic to see why the document message maps are being bypassed. – user1793036 May 20 '14 at 01:39
  • This really helped. I watched the commands be tossed on the floor by my own program in MyDoc::OnCmdMsg(). thanks! – diox8tony May 20 '14 at 23:42

1 Answers1

2

First of all, MFC is not a "locked" framework. Its complete source resides on your own PC in the following folder: "your Visual Studio folder"\VC\atlmfc\src\mfc\ (on my PC it is: c:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\src\mfc) The source for CPreviewView is in viewprev.cpp file. I just opened the file and in the DoPrintPreview they are calling this:

pParent->OnSetPreviewMode(TRUE, pState);    // Take over Frame Window

According to MSDN this method:

The default implementation disables all standard toolbars and hides the main menu and the main client window. This turns MDI frame windows into temporary SDI frame windows.

I have opened the file called winfrm.cpp and checked that this method is doing, and it does disable all the menu. Obviously, no Update messages will be sent to documents while preview mode is on.

The MSDN article at the hyperlink above says that you need to override the OnSetPreviewMode method for your frame to:

customize the hiding and showing of control bars and other frame window parts during print preview. Call the base class implementation from within the overridden version.

This should not be a problem.

cha
  • 10,301
  • 1
  • 18
  • 26
  • Yes, commenting out the OnSetPreviewMode() function calls worked and is the best answer to this question. I had already done this however, and I found my problem which was inside our code MyDoc::OnCmdMsg disabled itself if a preview window was up. – diox8tony May 20 '14 at 23:41
  • BTW, I didn't recommend you commenting any code in MFC library. It is not the right way to do. Instead, you are supposed to override the method in your class and configure the toolbar as you wish – cha May 21 '14 at 06:28
  • exactly. I have an inherited class and I overload the function, then edit the code in my class. – diox8tony May 21 '14 at 14:01