Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Print Preview Prebuilt Sample
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Print Preview Prebuilt Sample

 Post Reply Post Reply
Author
Message
CyberSky View Drop Down
Groupie
Groupie


Joined: 15 February 2010
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote CyberSky Quote  Post ReplyReply Direct Link To This Post Topic: Print Preview Prebuilt Sample
    Posted: 31 March 2010 at 12:54am

I've noticed that in my software clicking the Close button in the upper-right corner of the window while in print preview closes the entire application rather than just closing pring preview. I checked the Codejock sample and don't understand what I'm seeing.

If I run the prebuilt ToolkitPro.PrintPreview sample that comes with the AllSamples.zip available here, then the print preview fills the entire window. Clicking the Close button (X) does the same thing as clicking the Close Preview button on the print preview toolbar.
 
However, if I build the PrintPreview sample that's in the Toolkit Pro sample folder, and then run it, it behaves differently. The print preview doesn't fill the entire window (the menu bar is still visible), and clicking the Close button (X) closes the entire application rather than closing just the print preview.
 
I'm talking about the latest version 13.3.1, and am using VS2008 on Windows 7 64-bit.
 
I've noticed that a basic MFC program also behaves the same way: the Close button closes the entire application rather than just print preview.
 
Anybody else notice this? Anybody know why the prebuilt sample works one way and the one I built (not changing any options) works a different way?
 
Thanks for any comments!
 
Back to Top
CyberSky View Drop Down
Groupie
Groupie


Joined: 15 February 2010
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote CyberSky Quote  Post ReplyReply Direct Link To This Post Posted: 01 April 2010 at 11:02am

Okay, I figured out how to fix this to get the behavior I want.

If you look at the code for CPrintPreviewState:

struct CPrintPreviewState    // Print Preview context/state
{
    ...
    BOOL (CALLBACK* lpfnCloseProc)(CFrameWnd* pFrameWnd);
    ...
};

you can see there's a function that's supposed to get called when you close print preview. This is _AfxPreviewCloseProc(). I think it should be called if you click Close Preview on the toolbar or the application's Close button. However, it apparently is only called if you click Close Preview. If you click Close, the application closes instead.

When the main frame's OnSetPreviewMode() is called you can save the preview state:

void CMainFrame::OnSetPreviewMode(BOOL bPreview, CPrintPreviewState* pState)
{
    m_bPrintPreviewMode = bPreview;

    m_pPrintPreviewState = pState;
    ...

    // Show or hide the command bars, docking panes, etc.
}

and then in OnClose() call the preview close procedure rather than the normal code to close the application:

void CMainFrame::OnClose()
{
    if (m_bPrintPreviewMode)
    {
        if (m_pPrintPreviewState->lpfnCloseProc != NULL)
        {
            (*m_pPrintPreviewState->lpfnCloseProc)(this);
        }

    }
    else
    {
        // Save the current state of the main window, command bars, etc.
        ...

        CFrameWnd::OnClose();
    }
}

Now when the program is in print preview mode, clicking Close will close print preview rather than closing the entire application.

I hope somebody finds this useful.

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.047 seconds.