Print Page | Close Window

Print Preview Prebuilt Sample

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=16542
Printed Date: 28 April 2025 at 4:20am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Print Preview Prebuilt Sample
Posted By: CyberSky
Subject: Print Preview Prebuilt Sample
Date 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!
 



Replies:
Posted By: CyberSky
Date 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.




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net