Handling preview window events

Using the Crystal Report Engine API, you can create a Windows CALLBACK function to handle events that occur in a preview window. For instance, if a user clicks on a button in the toolbar of the preview window, such as the Zoom button or the Next Page button, Windows registers an event for the preview window.

Using the Event functions in the Crystal REAPI, you can add instructions to your own applications to perform specific actions according to events that occur in a preview window. The sample code below demonstrates how to handle preview window events by creating a CALLBACK function for the preview window, then initializing the preview window with that CALLBACK function in your Crystal Report Engine code. The code can handle toolbar button events, Group Tree events, and even drill-down events.

The Crystal Report Engine API Event functions are only valid when a print job is sent to a preview window using PEOutputToWindow.

#define  PE_ERR_INVALIDPARAMETERRANGEINFO 672
#include "crpe.h"
#include "Windows.h" // The EventCallback function is defined as a standard
// Windows CALLBACK procedure. Return TRUE to allow the
// Crystal Report Engine to provide default behavior.
// Return FALSE to prevent default behavior from being carried out. // The comment TODO indicates where you need to add event
// handling code specific to your application. #if defined (WIN32)
BOOL CALLBACK EventCallback (short eventID,
                    void *param, void *userData)
#else
BOOL CALLBACK __export EventCallback (short eventID,
                        void *param, void *userData)
#endif
{     switch(eventID)
    {
        case PE_CLOSE_PRINT_WINDOW_EVENT:
        case PE_PRINT_BUTTON_CLICKED_EVENT:
        case PE_EXPORT_BUTTON_CLICKED_EVENT:
        case PE_FIRST_PAGE_BUTTON_CLICKED_EVENT:
        case PE_PREVIOUS_PAGE_BUTTON_CLICKED_EVENT:
        case PE_NEXT_PAGE_BUTTON_CLICKED_EVENT:
        case PE_LAST_PAGE_BUTTON_CLICKED_EVENT:
        case PE_CANCEL_BUTTON_CLICKED_EVENT:
        case PE_ACTIVATE_PRINT_WINDOW_EVENT:
        case PE_DEACTIVATE_PRINT_WINDOW_EVENT:
        case PE_PRINT_SETUP_BUTTON_CLICKED_EVENT:
        case PE_REFRESH_BUTTON_CLICKED_EVENT:
        {
            PEGeneralPrintWindowEventInfo * eventInfo =
                (PEGeneralPrintWindowEventInfo *) param;
            ASSERT(eventInfo != 0 && eventInfo->StructSize ==
                PE_SIZEOF_GENERAL_PRINT_WINDOW_EVENT_INFO);             // TODO         }
            break;         case PE_ZOOM_LEVEL_CHANGING_EVENT:
        {
            PEZoomLevelChangingEventInfo * eventInfo =
                (PEZoomLevelChangingEventInfo *) param;
            ASSERT(eventInfo != 0 && eventInfo->StructSize ==
                PE_SIZEOF_ZOOM_LEVEL_CHANGING_EVENT_INFO);             // TODO         }
            break;         case PE_GROUP_TREE_BUTTON_CLICKED_EVENT:
        {
            PEGroupTreeButtonClickedEventInfo * eventInfo =
                (PEGroupTreeButtonClickedEventInfo *)param;
            ASSERT(eventInfo != 0 && eventInfo->StructSize ==
             PE_SIZEOF_GROUP_TREE_BUTTON_CLICKED_EVENT_INFO);             // TODO         }
            break;         case PE_CLOSE_BUTTON_CLICKED_EVENT:
        {
            PECloseButtonClickedEventInfo *eventInfo =
                (PECloseButtonClickedEventInfo *)param;
            ASSERT(eventInfo != 0 && eventInfo->StructSize ==
                PE_SIZEOF_CLOSE_BUTTON_CLICKED_EVENT_INFO);             // TODO         }
            break;         case PE_SEARCH_BUTTON_CLICKED_EVENT:
        {
            PESearchButtonClickedEventInfo *eventInfo =
                (PESearchButtonClickedEventInfo *)param;
            ASSERT(eventInfo != 0 && eventInfo->StructSize ==
                PE_SIZEOF_SEARCH_BUTTON_CLICKED_EVENT_INFO);             // TODO         }
            break;         case PE_SHOW_GROUP_EVENT:
        {
            PEShowGroupEventInfo * eventInfo =
                (PEShowGroupEventInfo *)param;
            ASSERT(eventInfo != 0 && eventInfo->StructSize ==
                PE_SIZEOF_SHOW_GROUP_EVENT_INFO);             // TODO         }
            break;         case PE_DRILL_ON_GROUP_EVENT:
        {
            PEDrillOnGroupEventInfo * eventInfo =
                (PEDrillOnGroupEventInfo *) param;
            ASSERT(eventInfo != 0 && eventInfo->StructSize ==
                PE_SIZEOF_DRILL_ON_GROUP_EVENT_INFO);             // TODO         }
            break;         case PE_DRILL_ON_DETAIL_EVENT:
        {
            PEDrillOnDetailEventInfo * eventInfo =
                (PEDrillOnDetailEventInfo *) param;
            ASSERT(eventInfo != 0 && eventInfo->StructSize ==
                PE_SIZEOF_DRILL_ON_DETAIL_EVENT_INFO);             // TODO         }
            break;         case PE_READING_RECORDS_EVENT:
        {
            PEReadingRecordsEventInfo * readingRecordsInfo =
                (PEReadingRecordsEventInfo *) param;
            ASSERT(readingRecordsInfo != 0 &&
                readingRecordsInfo->StructSize ==
                PE_SIZEOF_READING_RECORDS_EVENT_INFO);             // TODO         }
            break;         case PE_START_EVENT:
        {
            PEStartEventInfo * startEventInfo =
                (PEStartEventInfo *) param;
            ASSERT(startEventInfo != 0 &&
                startEventInfo->StructSize ==
                PE_SIZEOF_START_EVENT_INFO);             // TODO         }
            break;         case PE_STOP_EVENT:
        {
            PEStopEventInfo * stopEventInfo =
                (PEStopEventInfo *) param;
            ASSERT(stopEventInfo != 0 &&
                stopEventInfo->StructSize ==
                PE_SIZEOF_STOP_EVENT_INFO);             // TODO         }
            break;         default:
            break;     } return TRUE;
} // call this function after open a print job
// before call PEStartPrintJob BOOL initializeEvent(short printJob)
{
    // initialize window options
    // do not have to set window options to get events,
    // however, some of the events are fired only when
    // certain window options are on.     PEWindowOptions windowOptions;
    windowOptions.StructSize = PE_SIZEOF_WINDOW_OPTIONS;     PEGetWindowOptions(printJob, &windowOptions);     windowOptions.hasGroupTree = TRUE;
    windowOptions.hasSearchButton = TRUE;
    windowOptions.canDrillDown = TRUE;     if(!PESetWindowOptions(printJob, &windowOptions))
        return FALSE;     // enable event.
    // by default, events are disabled.     PEEnableEventInfo eventInfo;
    eventInfo.StructSize = sizeof(PEEnableEventInfo);
    eventInfo.activatePrintWindowEvent = PE_UNCHANGED;
    eventInfo.closePrintWindowEvent = TRUE;
    eventInfo.startStopEvent = TRUE;
    eventInfo.printWindowButtonEvent = PE_UNCHANGED;
    eventInfo.drillEvent = TRUE;
    eventInfo.readingRecordEvent = TRUE;     if(!PEEnableEvent(printJob, &eventInfo))
        return FALSE;     // set tracking cursor, gives the user feedback
    // when the cursor is in the detail area
    // (for a drill-down on detail event)
    // use the default cursor behavior in group area.     PETrackCursorInfo cursorInfo;
    cursorInfo.StructSize = sizeof(PETrackCursorInfo);
    cursorInfo.groupAreaCursor = PE_UNCHANGED;
    cursorInfo.groupAreaFieldCursor = PE_UNCHANGED;
    cursorInfo.detailAreaCursor = PE_TC_CROSS_CURSOR;
    cursorInfo.detailAreaFieldCursor = PE_TC_IBEAM_CURSOR;
    cursorInfo.graphCursor = PE_UNCHANGED;     if(!PESetTrackCursorInfo(printJob, &cursorInfo))
        return FALSE;     // set call back function
    if (!PESetEventCallback(printJob, lEventCallback, 0))
        return FALSE;     return TRUE;
}


Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com