Hide

SftPrintPreview/DLL 2.0 - Print Preview Control for C/C++

Display
Print

Built-In Tool Bar

SftPrintPreview/DLL offers a built-in tool bar to allow the end-user to customize the current Print Preview.

The tool bar components offer ToolTip help when the mouse cursor rests over the item.

The tool bar and ToolTip text is customizable and can be translated into other languages (see National Language Support).

Some of the tool bar buttons can be hidden (see SFTPRINTPREVIEW_CONTROL, fWantCloseButton, fWantHelpButton and fWantPageSetupButton members), if they are not needed by an application.

The entire tool bar can be hidden using the SetControlInfo function (see SFTPRINTPREVIEW_CONTROL, fToolbar member), if an application wishes to implement its own tool bar. This may be desirable if achieving the same, consistent look across the entire application is necessary.

The Print Preview control by default allows the display of 1 through 64 pages at one time. The end-user can select the exact number of pages using the "Multiple Pages" button. By clicking on the drop down portion, a grid appears where the number of rows and pages per row can be selected. Some applications may want to limit the maximum number of pages, particularly if rendering the output can be time consuming. The maximum number of pages is defined using the SetControlInfo function (see SFTPRINTPREVIEW_CONTROL, maxPageRows and maxPageGroups members).

InputDescription
Zoom FactorAllows entry of a zoom factor value between 10 and up to the maximum defined using the SetControlInfo function (see SFTPRINTPREVIEW_CONTROL, maxZoom member). The default maximum value is 1000%.
Zoom InIncreases the zoom factor by the value defined using the SetControlInfo function (see SFTPRINTPREVIEW_CONTROL, zoomIncrDecr member). The default value is 100%. If multiple pages are currently displayed, only the current page will be displayed, at the specified zoom factor.
Zoom OutDecreases the zoom factor by the value defined using the SetControlInfo function (see SFTPRINTPREVIEW_CONTROL, zoomIncrDecr member). The default value is 100%. If the resulting zoom factor is 0%, multiple pages are displayed.
Single PageSwitches to single page mode, setting a zoom factor suitable to show the entire current page in the available display area.
Multiple PagesClicking this button, will increase the currently displayed number of pages, going from one page to 1 x 2, 2 x 4, 3 x 6, 4 x 8, 5 x 10, 6 x 12, back to one page.
Multiple Pages (Drop down button)Displays a grid, allowing selection of the exact number of pages (rows and columns) to be displayed.
Current PageAllows entry of the selected page number. Page numbering starts at 1.
Previous PageMakes the previous page the new current page.
Next PageMakes the next page the new current page.
Page SetupThe NM_SFTPRINTPREVIEW_PAGESETUP_CODE notification code is sent when the user clicks on the Page Setup button. The Page Setup dialog is not automatically invoked.
Print SetupThe Print Setup dialog is automatically invoked.
PrintThe Print dialog is automatically invoked.
HelpThe NM_SFTPRINTPREVIEW_HELP_CODE notification code is sent when the user requests online help.
Close Print PreviewThe NM_SFTPRINTPREVIEW_CLOSE_CODE notification code is sent when the users requests to close the Print Preview control window.

If Windows XP themes are enabled (see SFTPRINTPREVIEW_CONTROL, fUseThemes member) and available, the tool bar will be rendered using Windows themes and the user-defined background color (see SFTPRINTPREVIEW_COLORS, colorToolbar member) is ignored.

The control colors and button images cannot be customized. If detailed customization is required, an application can implement its own tool bar.

Handling Tool Bar Events

Most components of the tool bar automatically perform the desired action, such as zooming in/out, displaying the selected page(s), etc. A few components will generate events which must be handled by the application, so the application can respond to the requested action. The events generated by the "Page Setup", "Print" and "Help" buttons must be handled, otherwise these buttons have no effect.

Applications handle the following WM_NOTIFY messages:

WM_NOTIFY / NM_SFTPRINTPREVIEW_CLOSE_CODE

The NM_SFTPRINTPREVIEW_CLOSE_CODE notification code is sent when the users requests to close the Print Preview control window.

Applications using C++/MFC and the CSftPrintPreview_View class do not need to handle this notification as it is automatically handled by the CSftPrintPreview_View class.

WM_NOTIFY / NM_SFTPRINTPREVIEW_HELP_CODE

The NM_SFTPRINTPREVIEW_HELP_CODE notification code is sent when the user requests online help.

WM_NOTIFY / NM_SFTPRINTPREVIEW_PAGESETUP_CODE

The NM_SFTPRINTPREVIEW_PAGESETUP_CODE notification code is sent when the user requests the Page Setup dialog.

Applications using C++/MFC and the CSftPrintPreview_View class do not need to handle this notification as it is automatically handled by the CSftPrintPreview_View class.

WM_COMMAND / SFTPRINTPREVIEWN_STARTPRINTING

The SFTPRINTPREVIEWN_STARTPRINTING notification code is sent when the user requests printing of the current contents.

Applications using C++/MFC and the CSftPrintPreview_View class do not need to handle this notification as it is automatically handled by the CSftPrintPreview_View class.

Example

C

LRESULT CALLBACK MainWindowProc(HWND hwndMain, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg) {
        case WM_NOTIFY: {
            int id = (int) wParam;
            LPNMHDR pnmh = (LPNMHDR) lParam;
            switch (id) {
                case IDC_PREVIEW:
                    switch (pnmh->code) {
                        case NM_SFTPRINTPREVIEW_CLOSE_CODE: { // user wants to close
                            NM_SFTPRINTPREVIEW_CLOSE* pNtfy = (NM_SFTPRINTPREVIEW_CLOSE*) lParam;
                            SendMessage(hwndMain, WM_CLOSE, 0, 0);
                            break;
                        }
                        case NM_SFTPRINTPREVIEW_HELP_CODE: { // help requested
                            NM_SFTPRINTPREVIEW_HELP* pNtfy = (NM_SFTPRINTPREVIEW_HELP*) lParam;
                            MessageBox(hwndMain, TEXT("Sorry, this sample application doesn't include online help."),
                            TEXT("SftPrintPreview/DLL"), MB_OK);
                            break;
                        }
                        case NM_SFTPRINTPREVIEW_PAGESETUP_CODE: { // Page setup requested
                            SftPrintPreview_PageSetup(m_hwndPreview, hwndMain);
                            break;
                        }
                    }
                    break;
            }
            break;
        }
        case WM_COMMAND: {
            HWND hwndCtl = (HWND) lParam;
            int id = LOWORD(wParam);
            int code = HIWORD(wParam);
            if (hwndCtl) {
                switch (id) {
                    case IDC_PREVIEW:
                        switch (code) {
                            case SFTPRINTPREVIEWN_STARTPRINTING:
                                SftPrintPreview_Print(hwndCtl, hwndMain);
                                break;
                        }
                        break;
                }
            }
            break;
        }
    }
    return DefWindowProc(hwndMain, uMsg, wParam, lParam);
}

C++

BEGIN_MESSAGE_MAP(CPreviewPagePrinting, CSftPrintPreview_View)
    ON_NM_SFTPRINTPREVIEW_HELP_CODE_REFLECT(OnNotifyHelpReflect)
END_MESSAGE_MAP()

afx_msg void CPreviewPagePrinting::OnNotifyHelpReflect(NMHDR * pNotifyStruct, LRESULT* lResult)
{
    MessageBox(_T("Sorry, this sample application doesn't include online help."),
    _T("SftPrintPreview/DLL"), MB_OK);
    *lResult = 0;
}

Last Updated 08/13/2020 - (email)
© 2024 Softel vdm, Inc.