example_hooks.cpp

This is an example of how to use the hooks in a GPI to get notifications of ShapeUp events.

00001 #include <ShapeUpAPI.h>
00002 
00003 SURESULT __cdecl fnInit(SUExport *pExport)
00004 {
00005     ...
00006 
00007     // Set-up our hook callback
00008     pExport->import.pfnHook = HookFunc;
00009 
00010     // In this example we send a zero as user data to the various
00011     // ShapeUp_AddXxxHook() functions. You can specify any value,
00012     // and this value can later be found when the hook function
00013     // is called.
00014 
00015     // We want notification when the user presses our toolbar buttons
00016     ShapeUp_AddToolBarButtonHook(0);
00017 
00018     // The idle hook is used to set the state of toolbar buttons (disabled/checked/...)
00019     ShapeUp_AddIdleHook(0);
00020 
00021     // We want notification when the user presses the left mouse button in the map window
00022     ShapeUp_AddLButtonDownHook(0);
00023 
00024     // We want notification when the user removes a layer from a workspace
00025     ShapeUp_AddRemoveLayerHook(0);
00026 
00027     ...
00028 }
00029 
00030 // ShapeUp will call this function when an event occurs
00031 SURESULT __cdecl HookFunc(SUHANDLE hWorkspace, int hookType, SUHookData *args)
00032 {
00033     AFX_MANAGE_STATE(AfxGetStaticModuleState());
00034 
00035     // args->userData contains the value specified when adding the hook
00036     // The args pointer is interpreted differently for different hook types.
00037     // For more info check the various hook type values.
00038 
00039     switch (hookType)
00040     {
00041     case HOOKTYPE_TOOLBARBUTTON:
00042         return OnToolBarButton(hWorkspace, (SUToolBarButtonHookData*) args);
00043     case HOOKTYPE_IDLE:
00044         return OnIdle(hWorkspace, args);
00045     case HOOKTYPE_LBUTTONDOWN:
00046         return OnLButtonDown(hWorkspace, (SUMouseHookData*) args);
00047     case HOOKTYPE_PREREMOVETHEME:
00048         return OnRemoveTheme(hWorkspace, (SUPreRemoveThemeHookData*) args);
00049     case ...:
00050         break;
00051     default:
00052         break;
00053     }
00054 
00055     return SURESULT_OK;
00056 }

Generated on Thu Apr 15 10:55:32 2010 for ShapeUp API by  doxygen 1.5.2