The following sample illustrates the source code (C):
/* * This file was generated by the SOM Compiler and Emitter Framework. * Generated using SOM Emitter emitctm: 2.40 */ #ifndef SOM_Module_hello_Source #define SOM_Module_hello_Source #endif #define Hello_Class_Source #define M_Hello_Class_Source #define INCL_DOS #include "hello.ih" MRESULT EXPENTRY ClientWinProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2); // Structure to pass the object pointer and // use list item to the window procedure typedef struct { WPObject *self; /* Pointer to the object */ USEITEM UseItem; /* Use list item header */ VIEWITEM ViewItem; /* Open view use list item */ } WINDOWDATA; typedef WINDOWDATA *PWINDOWDATA; /* * METHOD: wpFilterPopupMenu * * DESCRIPTION: Removes any menu items from the context menu that don't apply. * * HOW TO OVERRIDE: No restrictions. * * NOTES: * * This method is called when an object's context menu has been requested * (i.e. right click or S-F10 on an object) before displaying the menu. It * is called before wpModifyPopupMenu. */ SOM_Scope ULONG SOMLINK hlo_wpFilterPopupMenu(Hello somSelf, ULONG ulFlags, HWND hwndCnr, BOOL fMultiSelect) { /* HelloData *somThis = HelloGetData(somSelf); */ HelloMethodDebug("Hello","hlo_wpFilterPopupMenu"); // Return the parent class' menu bitstring minus the "move bit" return (parent_wpFilterPopupMenu(somSelf, ulFlags, hwndCnr, fMultiSelect) & ~CTXT_MOVE); } /* * METHOD: wpModifyPopupMenu * * DESCRIPTION: Adds the menu items to the context menu. * * NOTES: * * This method is called when an object's context menu has been requested * (i.e. right click or S-F10 on an object) before displaying the menu. It * is called after wpFilterPopupMenu. */ SOM_Scope BOOL SOMLINK hlo_wpModifyPopupMenu(Hello somSelf, HWND hwndMenu, HWND hwndCnr, ULONG iPosition) { HMODULE hmod; /* HelloData *somThis = HelloGetData(somSelf); */ HelloMethodDebug("Hello","hlo_wpModifyPopupMenu"); /* Get the module handle of the .DLL */ hmod = _clsQueryModuleHandle(_Hello); /* * Put the "Say Hello" submenu item in the Open submenu */ _wpInsertPopupMenuItems(somSelf, // Object hwndMenu, // Main context menu 0, // Position to insert menu at // 0 = top of menu hmod, // Module of menu to insert ID_OPENHELLO, // Menu to insert WPMENUID_OPEN); // Submenu to insert menu in /* * Put the "Product Info" menu item at the end of the main context menu */ _wpInsertPopupMenuItems(somSelf, // Object hwndMenu, // Main context menu iPosition, // Position to insert menu at // iPosition = next available hmod, // Module of menu to insert ID_MSGBOX, // Menu to insert 0); // Submenu to insert menu in // 0 = main context menu return (parent_wpModifyPopupMenu(somSelf, hwndMenu, hwndCnr, iPosition)); } /* * METHOD: wpMenuItemSelected * * DESCRIPTION: Processes input from the menu options that was added. * * NOTES: * * This method is called when an item in an objects' context menu has been * selected. */ SOM_Scope BOOL SOMLINK hlo_wpMenuItemSelected(Hello somSelf, HWND hwndFrame, ULONG ulMenuId) { /* HelloData *somThis = HelloGetData(somSelf); */ HelloMethodDebug("Hello","hlo_wpMenuItemSelected"); switch(ulMenuId) { case IDM_OPENHELLO: /* * Either the object was double clicked on or the Say Hello * item on the Open submenu was selected. * * We could call wpOpen here, but wpOpen will open a new view * no matter what. wpViewObject only opens a new view if * no open view exists or if mutliple concurrent views are enabled. * Otherwise, it will give focus to the current open view. * * wpViewObject should be used whenever possible instead of wpOpen * to prevent creating multiple open views inadvertently. */ _wpViewObject(somSelf, // Object NULLHANDLE, // Workplace Shell // internal use only OPEN_HELLO, // View to open. This ID must be the // same as the menu ID ID_OPENHELLO 0); // parameter passed to wpOpen break; case IDM_MSGBOX: { // Message Box menu item was selected WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, "Message box displayed from a Hello object's pop-up menu.", "Workplace Message", 1, MB_OK | MB_MOVEABLE | MB_INFORMATION); break; } default: return parent_wpMenuItemSelected(somSelf, hwndFrame, ulMenuId); } return TRUE; /* We processed it */ } /* * METHOD: wpOpen * * DESCRIPTION: Opens the Hello Workplace Shell window. * * NOTES: * * This method is called when a new open view of an object is needed, * i.e. when an item in an object's Open submenu has been selected or * when an object is double clicked on. This is equivalent to selecting * the default item in the object's Open submenu. * * wpOpen should always open a new view. The Workplace Shell actually * calls wpViewObject first when an object is double clicked on or an Open * submenu item is selected. wpViewObject will then call wpOpen if there * is currently no open view of the selected Open submenu item or if * mutliple concurrent views of the object are enabled. */ SOM_Scope HWND SOMLINK hlo_wpOpen(Hello somSelf, HWND hwndCnr, ULONG ulView, ULONG param) { /* HelloData *somThis = HelloGetData(somSelf); */ HelloMethodDebug("Hello","hlo_wpOpen"); switch (ulView) { case OPEN_HELLO: { // Request to open a Hello Workplace Shell window // Create a standard window HAB hab; // Anchor block handle HWND hwndClient; // Client window handle HWND hwndFrame; // Frame window handle PWINDOWDATA pWindowData; ULONG flCreate; // Window creation flags hab = WinQueryAnchorBlock(HWND_DESKTOP); // Create the class, adding a user word to the window data to // anchor the object use list item for this open view WinRegisterClass(hab, "hello", ClientWinProc, CS_SIZEREDRAW, sizeof(*pWindowData)); flCreate = FCF_SYSMENU | FCF_SIZEBORDER | FCF_TITLEBAR | FCF_MINMAX | FCF_SHELLPOSITION | FCF_TASKLIST; hwndFrame = WinCreateStdWindow(HWND_DESKTOP, WS_VISIBLE, &flCreate, "hello", _wpQueryTitle(somSelf), 0L, 0, ID_FRAME, &hwndClient); if (hwndFrame) { WinSetFocus(HWND_DESKTOP, hwndFrame); // Now that we have created an open view, add the view to the // object's use list. This use list is used by wpViewObject and // wpClose to check for existing open views. // Get storage for and initialize a use list item pWindowData = (PWINDOWDATA) _wpAllocMem(somSelf, sizeof(*pWindowData), NULL); memset((PVOID) pWindowData, 0, sizeof(*pWindowData)); pWindowData->self = somSelf; pWindowData->UseItem.type = USAGE_OPENVIEW; pWindowData->ViewItem.view = OPEN_HELLO; pWindowData->ViewItem.handle = hwndFrame; // Add the use list item to the object's use list _wpAddToObjUseList(somSelf, &(pWindowData->UseItem)); // Save the pointer to the use item in the window words so that // the window procedure can remove it from the list when the window // is closed WinSetWindowPtr(hwndClient, QWL_USER, pWindowData); } return hwndFrame; } // Some other view was requested. Pass the request on to the // parent (WPDataFile) class default: return (parent_wpOpen(somSelf, hwndCnr, ulView, param)); } /* end switch (ulView) */ } /* * METHOD: clsQueryModuleHandle * * DESCRIPTION: * * Returns the module handle of this class. If this is the * first invocation, DosQueryModuleHandle is called to save the handle * for future invocations. * * RETURN: * * 0 Unsuccessful * non-zero Module handle * * NOTES: * * This method is called when a new open view of an object is needed, * i.e. when an item in an object's Open submenu has been selected or * when an object is double clicked on. This is equivalent to selecting * the default item in the object's Open submenu. */ SOM_Scope HMODULE SOMLINK hloM_clsQueryModuleHandle(M_Hello somSelf) { M_HelloData *somThis = M_HelloGetData(somSelf); M_HelloMethodDebug("M_Hello","hloM_clsQueryModuleHandle"); // Make sure we already have the module handle if (_hmod == NULLHANDLE) { zString zsPathName; somId Id; // Retrieve registered path name of the module (DLL) // and query the module handle Id = somIdFromString("M_Hello"); zsPathName = _somLocateClassFile(SOMClassMgrObject, Id, M_Hello_MajorVersion, M_Hello_MinorVersion); SOMFree(Id); DosQueryModuleHandle(zsPathName, &_hmod); } return (_hmod); } /* * METHOD: wpclsQueryDefaultView * * DESCRIPTION: Returns the default view for a new instance of this object. * * REMARKS: * * Return the ID of the default view, OPEN_HELLO. This ID must be the * same as the ID of the Open submenu item, ID_OPENHELLO. * * NOTES: * * This method is called to determine which view to open when an object * of class Hello is double clicked on. */ SOM_Scope ULONG SOMLINK hloM_wpclsQueryDefaultView(M_Hello somSelf) { /* M_HelloData *somThis = M_HelloGetData(somSelf); */ M_HelloMethodDebug("M_Hello","hloM_wpclsQueryDefaultView"); return OPEN_HELLO; } /* * METHOD: wpclsQueryTitle * * DESCRIPTION: Returns the string "Hello Workplace Shell". * * NOTES: * * This method is called by the Workplace Shell to determine the object * title when an object of class Hello is created. */ SOM_Scope PSZ SOMLINK hloM_wpclsQueryTitle(M_Hello somSelf) { // M_HelloData *somThis = M_HelloGetData(somSelf); M_HelloMethodDebug("M_Hello","hloM_wpclsQueryTitle"); return "Hello Workplace Shell"; } /* * FUNCTION: ClientWinProc * * DESCRIPTION: Window procedure for the Hello, Workplace Shell window. */ MRESULT EXPENTRY ClientWinProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { BOOL fSuccess; // Return from function switch(msg) { case WM_PAINT: { HPS hps; // Cached PS RECTL rcl; // Window rectangle CHAR sz[25]; // String hps = WinBeginPaint (hwnd , (HPS)0, NULL); fSuccess = GpiErase (hps); WinQueryWindowRect (hwnd, &rcl); strcpy (sz, "Hello, Workplace Shell."); WinDrawText(hps, strlen(sz), sz, &rcl, CLR_BLACK, CLR_WHITE, DT_CENTER | DT_VCENTER); fSuccess = WinEndPaint (hps); return (MRESULT) NULL; } case WM_CLOSE: { // Get the object pointer and the use list item from the window PWINDOWDATA pWindowData = (PWINDOWDATA) WinQueryWindowPtr(hwnd, QWL_USER); // Remove this window from the object's use list _wpDeleteFromObjUseList(pWindowData->self,&pWindowData->UseItem); // Free the use list item. Note that there is no need to supply a // length since this storage was allocated with wpAllocMem _wpFreeMem(pWindowData->self,(PBYTE)pWindowData); // Destroy the window and return WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT)); return (MRESULT) NULL; } default: return WinDefWindowProc(hwnd, msg, mp1, mp2); } }