home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warptlk3.zip / TOOLKIT / SAMPLES / WPS / CARPP / CARPP.CPP < prev    next >
C/C++ Source or Header  |  1995-08-24  |  66KB  |  2,027 lines

  1. /******************************************************************************
  2. *
  3. *  Module Name: CARPP.CPP
  4. *
  5. *  OS/2 WorkPlace Shell Sample Program - SOM 2.0 / IDL Version
  6. *
  7. *  Copyright (C) 1992-1995 IBM Corporation
  8. *
  9. *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  10. *      sample code created by IBM Corporation. This sample code is not
  11. *      part of any standard or IBM product and is provided to you solely
  12. *      for  the purpose of assisting you in the development of your
  13. *      applications.  The code is provided "AS IS", without
  14. *      warranty of any kind.  IBM shall not be liable for any damages
  15. *      arising out of your use of the sample code, even if they have been
  16. *      advised of the possibility of such damages.                                                    *
  17. *
  18. *  Entry Points:
  19. *
  20. *     Class Methods:
  21. *
  22. *        carppM_QueryModuleHandle
  23. *
  24. *     Overridden Class Methods:
  25. *
  26. *        carppM_wpclsInitData
  27. *        carppM_wpclsQueryDefaultHelp
  28. *        carppM_wpclsQueryDefaultView
  29. *        carppM_wpclsQueryDetailsInfo
  30. *        carppM_wpclsQueryIconData
  31. *        carppM_wpclsQueryStyle
  32. *        carppM_wpclsQueryTitle
  33. *        carppM_wpclsUnInitData
  34. *
  35. *     Instance Methods:
  36. *
  37. *        carpp_AddDashboardPage
  38. *        carpp_AddHornBeepPage
  39. *
  40. *     Overridden Instance Methods:
  41. *
  42. *        carpp_wpAddSettingsPages
  43. *        carpp_wpFilterPopupMenu
  44. *        carpp_wpInitData
  45. *        carpp_wpMenuItemHelpSelected
  46. *        carpp_wpMenuItemSelected
  47. *        carpp_wpModifyPopupMenu
  48. *        carpp_wpViewObject
  49. *        carpp_wpQueryDetailsData
  50. *        carpp_wpRestoreState
  51. *        carpp_wpSaveState
  52. *        carpp_wpUnInitData
  53. *
  54. *     Non-Method Functions:
  55. *
  56. *        CarInit
  57. *        CarWndProc
  58. *        DashBoardDlgProc
  59. *        HornBeepDlgProc
  60. *
  61. ******************************************************************************/
  62.  
  63. #define Carpp_Class_Source
  64. #define M_Carpp_Class_Source
  65.  
  66. #include "carpp.xih"          /* implementation header emitted from carpp.idl */
  67.  
  68. #include <string.h>
  69. #include <stdio.h>
  70. #include <memory.h>
  71. #include <stdlib.h>
  72. #include <setjmp.h>
  73.  
  74. /*
  75.  *   Non-Method function prototypes
  76.  */
  77.  
  78. HWND             CarInit (Carpp*);
  79. MRESULT EXPENTRY DashBoardDlgProc( HWND hwnd, ULONG msg,
  80.                                    MPARAM mp1, MPARAM mp2 );
  81. MRESULT EXPENTRY HornBeepDlgProc( HWND hwnd, ULONG msg,
  82.                                    MPARAM mp1, MPARAM mp2 );
  83. MRESULT EXPENTRY CarWndProc ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  84.  
  85. ULONG _System _Exception(EXCEPTIONREPORTRECORD       *parg,
  86.                  EXCEPTIONREGISTRATIONRECORD *pRegisRecord,
  87.                  PCONTEXTRECORD               pContextRecord,
  88.                  PVOID                        pvSpare);
  89.  
  90.  
  91.  
  92. /***************** GLOBAL/STATIC (NON-INSTANCE) DATA SECTION ******************
  93. *****                                                                     *****
  94. *****    This data shouldn't be changed by instance methods or it will    *****
  95. *****    affect all instances!  Any variables that are specific (unique   *****
  96. *****    values) for each instance of this object should be declared as   *****
  97. *****  instance data or dynamically allocated and stored as window data.  *****
  98. *****                                                                     *****
  99. *****      This global data should be declared as class instance data     *****
  100. *****    if it will change after initialization.  In this case, it will   *****
  101. *****                  be accessed through class methods.                 *****
  102. *****                                                                     *****
  103. ******************************************************************************/
  104.  
  105.    CHAR       szCarWindowClass[] =    "CARSAMPPP";
  106.    CHAR       szCarInstanceFilter[] = "*.CAR";
  107.    CHAR       szHelpLibrary[] =       "carpp.hlp";
  108.    CHAR       szCarClassTitle[CCHMAXPATH] = "";
  109.    HMODULE    hmod = NULLHANDLE;
  110.  
  111.    PCSZ       pcszDefaultText ="\
  112.                                \n\
  113.      Bill of Sale              \n\
  114.    =========================   \n\
  115.                                \n\
  116.    Make........ Toyota         \n\
  117.                                \n\
  118.    Model....... Camry          \n\
  119.                                \n\
  120.    Color....... Blue           \n\
  121.                                \n\
  122.    Sale Date... 3/31/92        \n\
  123.                                \n\
  124.    Price....... 14,995         \n";
  125.  
  126.    /*
  127.     *   Globals required for Exception handling
  128.     */
  129.  
  130.    jmp_buf jmpState;
  131.  
  132.    PCSZ pcszTrapMessage =                        "\
  133. \
  134. A Memory Access Violation occurred.  The Car \
  135. sample's exception handler has transferred \
  136. control back to the cleanup code in the method \
  137. where the exception occurred.\n";
  138.  
  139.    /*
  140.     *   Statics required for FIELDINFO structures needed for DETAILS view are
  141.     *   handled in the three functions:
  142.     *
  143.     *   carpp_wpclsInitData, carpp_wpQueryDetailsData, carpp_wpQueryClassDetailsInfo
  144.     */
  145.  
  146.    #define NUM_CAR_FIELDS    5
  147.  
  148.    CLASSFIELDINFO fieldinfo[NUM_CAR_FIELDS];      /* structure in wpobject.h */
  149.  
  150.    PCSZ apszCarColTitles[] =
  151.    {
  152.       "Make",           /* details column 1 */
  153.       "Model",          /* details column 2 */
  154.       "Color",          /* details column 3 */
  155.       "Sale date",      /* details column 4 */
  156.       "Price ($)"       /* details column 5 */
  157.    };
  158.  
  159.  
  160. /*************************  INSTANCE METHODS SECTION  *************************
  161. *****                                                                     *****
  162. *****              Do not put any code in this section unless             *****
  163. *****                   it is an object INSTANCE method                   *****
  164. *****                                                                     *****
  165. ******************************************************************************/
  166. #undef SOM_CurrentClass
  167. #define SOM_CurrentClass SOMInstance
  168.  
  169. /*
  170.  *
  171.  * METHOD: AddDashboardPage                               ( ) PRIVATE
  172.  *                                                        (X) PUBLIC
  173.  * DESCRIPTION:
  174.  *
  175.  *   This method adds the dashboard page to the settings notebook.
  176.  *
  177.  * RETURN:
  178.  *
  179.  *   0              Unsuccessful
  180.  *   ulPageId       Identifier for the inserted page
  181.  *
  182.  * HOW TO OVERRIDE:
  183.  *
  184.  *   Method should always be overridden in order to replace or remove
  185.  *   the dashboard page from an object which is a descendant of Car.
  186.  *   In most cases, an override of this method will not call the parent.
  187.  */
  188.  
  189. SOM_Scope ULONG SOMLINK carpp_AddDashboardPage(Carpp *somSelf, HWND hwndNotebook)
  190. {
  191.     PAGEINFO pageinfo;
  192.  
  193.     CarppData *somThis = CarppGetData(somSelf);
  194.     CarppMethodDebug("Carpp","carpp_AddDashboardPage");
  195.  
  196.     memset((PCH)&pageinfo,0,sizeof(PAGEINFO));
  197.     pageinfo.cb                 = sizeof(PAGEINFO);
  198.     pageinfo.hwndPage           = NULLHANDLE;
  199.     pageinfo.usPageStyleFlags   = BKA_MAJOR;
  200.     pageinfo.usPageInsertFlags  = BKA_FIRST;
  201.     pageinfo.pfnwp              = DashBoardDlgProc;
  202.     pageinfo.resid              = hmod;
  203.     pageinfo.dlgid              = IDD_DASHBOARD;
  204.     pageinfo.pszName            = "Dashboard";
  205.     pageinfo.pCreateParams      = somSelf;
  206.     pageinfo.idDefaultHelpPanel = ID_HELP_DASHBOARD;
  207.     pageinfo.pszHelpLibraryName = szHelpLibrary;
  208.  
  209.     return somSelf->wpInsertSettingsPage( hwndNotebook, &pageinfo );
  210.  
  211. }   /* end carpp_AddDashboardPage() */
  212.  
  213.  
  214. /*
  215.  *
  216.  * METHOD: AddHornBeepPage                                ( ) PRIVATE
  217.  *                                                        (X) PUBLIC
  218.  * DESCRIPTION:
  219.  *
  220.  *   This method adds the horn beep page to the settings
  221.  *   notebook.
  222.  *
  223.  * RETURN:
  224.  *
  225.  *   0              Unsuccessful
  226.  *   ulPageId       Identifier for the inserted page
  227.  *
  228.  * HOW TO OVERRIDE:
  229.  *
  230.  *   Method should always be overridden in order to replace or remove
  231.  *   the horn beep page from an object which is a descendant of Car.
  232.  *   In most cases, an override of this method will not call the parent.
  233.  */
  234.  
  235. SOM_Scope ULONG SOMLINK carpp_AddHornBeepPage(Carpp *somSelf, HWND hwndNotebook)
  236. {
  237.     PAGEINFO pageinfo;
  238.  
  239.     CarppData *somThis = CarppGetData(somSelf);
  240.     CarppMethodDebug("Carpp","carpp_AddHornBeepPage");
  241.  
  242.     /* Insert the settings pages for a car
  243.      */
  244.     memset((PCH)&pageinfo,0,sizeof(PAGEINFO));
  245.     pageinfo.cb                 = sizeof(PAGEINFO);
  246.     pageinfo.hwndPage           = NULLHANDLE;
  247.     pageinfo.usPageStyleFlags   = BKA_MAJOR;
  248.     pageinfo.usPageInsertFlags  = BKA_FIRST;
  249.     pageinfo.pfnwp              = HornBeepDlgProc;
  250.     pageinfo.resid              = hmod;
  251.     pageinfo.dlgid              = IDD_HORNBEEP;
  252.     pageinfo.pszName            = "Horn Beep";
  253.     pageinfo.pCreateParams      = somSelf;
  254.     pageinfo.idDefaultHelpPanel = ID_HELP_HORNBEEP;
  255.     pageinfo.pszHelpLibraryName = szHelpLibrary;
  256.  
  257.     return somSelf->wpInsertSettingsPage( hwndNotebook, &pageinfo );
  258.  
  259. }   /* end carpp_AddHornBeepPage() */
  260.  
  261. /*
  262.  *
  263.  *  OVERRIDE: wpInitData                                   ( ) PRIVATE
  264.  *                                                         (X) PUBLIC
  265.  *  DESCRIPTION:
  266.  *
  267.  *    Initialize our state variables. Allocate any extra memory that
  268.  *    we might need.
  269.  *
  270.  */
  271.  
  272. SOM_Scope void  SOMLINK carpp_wpInitData(Carpp *somSelf)
  273. {
  274.     CarppData *somThis = CarppGetData(somSelf);
  275.     CarppMethodDebug("Carpp","carpp_wpInitData");
  276.  
  277.     /*
  278.      *   We can initialize our instance data to 0's by using the somThis
  279.      *   pointer and the size of the CarppData structure created by SOM.
  280.      *
  281.      *   SOM stores instance data in a data structure named by prefixing
  282.      *   the name "Data" with the class name, in this case, "Carpp".
  283.      */
  284.  
  285.     memset((PVOID)somThis, 0, sizeof(CarppData));
  286.  
  287.     /*
  288.      *   And/or we can explicitly initialize our instance variables.
  289.      */
  290.  
  291.     somThis->carBrake   = new Brake;
  292.     somThis->carHorn    = new Horn;
  293.     somThis->carRPM     = new RPM;
  294.  
  295.     parent_wpInitData(somSelf);
  296.  
  297. }   /* end carpp_wpInitData() */
  298.  
  299. /*
  300.  *
  301.  *  OVERRIDE: wpUnInitData                                 ( ) PRIVATE
  302.  *                                                         (X) PUBLIC
  303.  *  DESCRIPTION:
  304.  *
  305.  *    Clear up memory that was allocated on wpInitData.
  306.  *
  307.  */
  308.  
  309. SOM_Scope void  SOMLINK carpp_wpUnInitData(Carpp *somSelf)
  310. {
  311.     CarppData *somThis = CarppGetData(somSelf);
  312.     CarppMethodDebug("Carpp","carpp_wpUnInitData");
  313.  
  314.     parent_wpUnInitData(somSelf);
  315.  
  316. }   /* end carpp_wpUnInitData() */
  317.  
  318.  
  319. /*
  320.  *
  321.  *  METHOD: wpSaveState                                    ( ) PRIVATE
  322.  *                                                         (X) PUBLIC
  323.  *  DESCRIPTION:
  324.  *
  325.  *    Save our state variables (pitch and duration).
  326.  *
  327.  */
  328.  
  329. SOM_Scope BOOL SOMLINK carpp_wpSaveState(Carpp *somSelf)
  330. {
  331.     CarppData *somThis = CarppGetData(somSelf);
  332.     CarppMethodDebug("Carpp","carpp_wpSaveState");
  333.  
  334.     somThis->carBrake->SaveState(somSelf, szCarClassTitle);
  335.     somThis->carHorn->SaveState(somSelf, szCarClassTitle);
  336.     somThis->carRPM->SaveState(somSelf, szCarClassTitle);
  337.  
  338.     return (parent_wpSaveState(somSelf));
  339.  
  340. }   /* end carpp_wpSaveState() */
  341.  
  342. /*
  343.  *
  344.  *  METHOD: wpRestoreState                                 ( ) PRIVATE
  345.  *                                                         (X) PUBLIC
  346.  *  DESCRIPTION:
  347.  *
  348.  *    Retrieve our saved state variables (pitch and duration).
  349.  *
  350.  */
  351.  
  352. SOM_Scope BOOL SOMLINK carpp_wpRestoreState(Carpp *somSelf, ULONG ulReserved)
  353. {
  354.     CarppData *somThis = CarppGetData(somSelf);
  355.     CarppMethodDebug("Carpp","carpp_wpRestoreState");
  356.  
  357.     somThis->carBrake->RestoreState(somSelf, szCarClassTitle);
  358.     somThis->carHorn->RestoreState(somSelf, szCarClassTitle);
  359.     somThis->carRPM->RestoreState(somSelf, szCarClassTitle);
  360.  
  361.     return (parent_wpRestoreState(somSelf,ulReserved));
  362.  
  363. }   /* carpp_wpRestoreState() */
  364.  
  365. /*
  366.  *
  367.  *  METHOD: wpAddSettingsPages                             ( ) PRIVATE
  368.  *                                                         (X) PUBLIC
  369.  *  DESCRIPTION:
  370.  *
  371.  *    Add our own settings page to let the user alter the pitch
  372.  *    and duration of the car's beep.
  373.  *
  374.  */
  375.  
  376. SOM_Scope BOOL SOMLINK carpp_wpAddSettingsPages(Carpp *somSelf, HWND hwndNotebook)
  377. {
  378.     CarppData *somThis = CarppGetData(somSelf);
  379.     CarppMethodDebug("Carpp","carpp_wpAddSettingsPages");
  380.  
  381.     if (parent_wpAddSettingsPages(somSelf, hwndNotebook)
  382.              && somSelf->AddHornBeepPage( hwndNotebook)
  383.              && somSelf->AddDashboardPage( hwndNotebook))
  384.     {
  385.         return(TRUE);
  386.     }
  387.     else
  388.     {
  389.         DebugBox("carpp_wpAddSettingsPages", " Failed to add a settings page.");
  390.         return( FALSE );
  391.     }
  392.  
  393. }   /* carpp_wpAddSettingsPages() */
  394.  
  395. /*
  396.  *
  397.  *  METHOD: wpFilterPopupMenu                              ( ) PRIVATE
  398.  *                                                         (X) PUBLIC
  399.  *  DESCRIPTION:
  400.  *
  401.  *    Filter out any options from the context that don't apply.
  402.  *
  403.  *  HOW TO OVERRIDE:
  404.  *
  405.  *    No restrictions.
  406.  *
  407.  */
  408.  
  409. SOM_Scope ULONG SOMLINK carpp_wpFilterPopupMenu(Carpp *somSelf,
  410.                 ULONG ulFlags,
  411.                 HWND hwndCnr,
  412.                 BOOL fMultiSelect)
  413. {
  414.     CarppData *somThis = CarppGetData(somSelf);
  415.     CarppMethodDebug("Carpp","carpp_wpFilterPopupMenu");
  416.  
  417.     /*
  418.      *   This method allows you to filter which menus to include in the
  419.      *   popup menu.  Note: wpclsQueryStyle is overridden to disallow
  420.      *   linking (creating shadow) as well.
  421.      */
  422.     return( parent_wpFilterPopupMenu(somSelf,ulFlags,hwndCnr,
  423.                     fMultiSelect) & ~CTXT_LINK );
  424.  
  425. }   /* end carpp_wpFilterPopupMenu() */
  426.  
  427. /*
  428.  *
  429.  *  METHOD: wpModifyPopupMenu                              ( ) PRIVATE
  430.  *                                                         (X) PUBLIC
  431.  *  DESCRIPTION:
  432.  *
  433.  *    Add our extra option to the context menu to beep the horn
  434.  *
  435.  */
  436.  
  437. SOM_Scope BOOL SOMLINK carpp_wpModifyPopupMenu(Carpp *somSelf,
  438.                 HWND hwndMenu,
  439.                 HWND hwndCnr,
  440.                 ULONG iPosition)
  441. {
  442.     CarppData *somThis = CarppGetData(somSelf);
  443.     CarppMethodDebug("Carpp","carpp_wpModifyPopupMenu");
  444.  
  445.     /*
  446.      *   Put in our special "open car" submenu item under the "open" menu
  447.      */
  448.     somSelf->wpInsertPopupMenuItems( hwndMenu, 0,
  449.                                hmod, ID_OPENMENU, WPMENUID_OPEN);
  450.     /*
  451.      *   insert a "beep horn" menu item at the end of the list.
  452.      */
  453.     somSelf->wpInsertPopupMenuItems( hwndMenu, iPosition,
  454.                                hmod, ID_BEEPMENU, 0 );
  455.  
  456.     /*
  457.      *   insert a "TRAP-D" menu item at the end of the list.
  458.      */
  459.     somSelf->wpInsertPopupMenuItems( hwndMenu, 0,
  460.                                hmod, ID_TRAPMENU, 0 );
  461.  
  462.     return (parent_wpModifyPopupMenu(somSelf,hwndMenu,hwndCnr,iPosition));
  463.  
  464. }   /* end carpp_wpModifyPopupMenu() */
  465.  
  466. /*
  467.  *
  468.  *  METHOD: wpMenuItemSelected                             ( ) PRIVATE
  469.  *                                                         (X) PUBLIC
  470.  *  DESCRIPTION:
  471.  *
  472.  *    Process input from the extra menu option that we added.
  473.  *
  474.  */
  475.  
  476. SOM_Scope BOOL SOMLINK carpp_wpMenuItemSelected(Carpp *somSelf,
  477.                 HWND hwndFrame,
  478.                 ULONG MenuId)
  479. {
  480.     CarppData *somThis = CarppGetData(somSelf);
  481.     CarppMethodDebug("Carpp","carpp_wpMenuItemSelected");
  482.  
  483.     /* Which of our menu items was selected ?
  484.      */
  485.     switch( MenuId )
  486.     {
  487.        case IDM_OPENCAR:
  488.           /*
  489.            *   We could call wpOpen here, but, if the object is already opened,
  490.            *   the following API determines whether the object should be
  491.            *   resurfaced, or if multiple views are desired.
  492.            */
  493.           somSelf->wpViewObject( NULLHANDLE, OPEN_CAR, 0);
  494.           break;
  495.  
  496.        case IDM_BEEPHORN:
  497.           somThis->carHorn->Beep();
  498.           break;
  499.  
  500.        case IDM_TRAPCAR:
  501.           somSelf->TrapTest();
  502.           break;
  503.  
  504.        default:
  505.           return parent_wpMenuItemSelected(somSelf, hwndFrame, MenuId);
  506.           break;
  507.     }
  508.     return TRUE;                                          /* we processed it */
  509.  
  510. }   /* end carpp_wpMenuItemSelected() */
  511.  
  512. /*
  513.  *
  514.  *  METHOD: wpMenuItemHelpSelected                         ( ) PRIVATE
  515.  *                                                         (X) PUBLIC
  516.  *  DESCRIPTION:
  517.  *
  518.  *    Process input from the extra menu option that we added.
  519.  *
  520.  */
  521.  
  522. SOM_Scope BOOL SOMLINK carpp_wpMenuItemHelpSelected(Carpp *somSelf,ULONG MenuId)
  523. {
  524.     CarppData *somThis = CarppGetData(somSelf);
  525.     CarppMethodDebug("Carpp","carpp_wpMenuItemHelpSelected");
  526.  
  527.     /* Which of our menu items was selected ?
  528.      */
  529.    switch( MenuId )
  530.    {
  531.       case IDM_BEEPHORN:
  532.  
  533.          return(somSelf->wpDisplayHelp( ID_HELP_BEEPHORN, szHelpLibrary));
  534.          break;
  535.  
  536.       case IDM_OPENCAR:
  537.  
  538.          return(somSelf->wpDisplayHelp( ID_HELP_OPENCAR, szHelpLibrary));
  539.          break;
  540.  
  541.       case IDM_TRAPCAR:
  542.  
  543.          return(somSelf->wpDisplayHelp( ID_HELP_TRAPCAR, szHelpLibrary));
  544.          break;
  545.  
  546.       default:
  547.          break;
  548.    }
  549.  
  550.    return FALSE;
  551.  
  552. }   /* end carpp_wpMenuItemHelpSelected() */
  553.  
  554. /*
  555.  *
  556.  *  METHOD: wpQueryDetailsData                             ( ) PRIVATE
  557.  *                                                         (X) PUBLIC
  558.  *  DESCRIPTION:
  559.  *
  560.  *    Returns the car specific data for the details view of this object.
  561.  *    Sets the pointer (*ppDetailsData) to the beginning of the buffer
  562.  *    into which the data is written.
  563.  *
  564.  */
  565.  
  566. SOM_Scope ULONG SOMLINK carpp_wpQueryDetailsData(Carpp *somSelf,
  567.                 PVOID *ppDetailsData,
  568.                 PULONG pcp)
  569. {
  570.    PCARDETAILS pCarDetails;
  571.    PBYTE       pSize;
  572.     CarppData *somThis = CarppGetData(somSelf);
  573.     CarppMethodDebug("Carpp","carpp_wpQueryDetailsData");
  574.  
  575.    parent_wpQueryDetailsData(somSelf,ppDetailsData, pcp);
  576.  
  577.    if (ppDetailsData)                                          /* query data */
  578.    {
  579.       pCarDetails                  = (PCARDETAILS) *ppDetailsData;
  580.       pCarDetails->pszMake         = "Toyota";               /* Manufacturer */
  581.       pCarDetails->pszModel        = "Camry";                  /* Model name */
  582.       pCarDetails->pszColor        = "BLUE";             /* Color of the car */
  583.       pCarDetails->cdateSale.day   = 24;                     /* Date of sale */
  584.       pCarDetails->cdateSale.month = 12;
  585.       pCarDetails->cdateSale.year  = 91;
  586.       pCarDetails->ulPrice         = 14000;              /* Price in dollars */
  587.  
  588.       /* point to buffer location after our details data */
  589.       *ppDetailsData = ((PBYTE) (*ppDetailsData)) + sizeof(*pCarDetails);
  590.  
  591.    }   /* end if (ppDetailsData) */
  592.    else                                                /* query size of data */
  593.    {
  594.       *pcp += sizeof(*pCarDetails);     /* caller is querying size of buffer */
  595.    }
  596.  
  597.    return(TRUE);
  598.  
  599. }   /* end carpp_wpQueryDetailsData() */
  600.  
  601. /*
  602.  *
  603.  *   METHOD: wpOpen                                         ( ) PRIVATE
  604.  *                                                          (X) PUBLIC
  605.  *   DESCRIPTION:
  606.  *
  607.  *     Opens the car window.
  608.  *
  609.  */
  610.  
  611. SOM_Scope HWND SOMLINK carpp_wpOpen(Carpp *somSelf,
  612.                 HWND hwndCnr,
  613.                 ULONG ulView,
  614.                 ULONG param)
  615. {
  616.  CarppData *somThis = CarppGetData(somSelf);
  617.  CarppMethodDebug("Carpp","carpp_wpOpen");
  618.  
  619.    switch (ulView)
  620.    {
  621.       case OPEN_CAR:
  622.  
  623.          if (!(somSelf->wpSwitchTo( ulView )))
  624.          {
  625.             /*
  626.              *   Create a basic Frame and Client window for this instance.
  627.              */
  628.            return CarInit(somSelf);
  629.          }
  630.          break;
  631.  
  632.       default:
  633.          return parent_wpOpen(somSelf,hwndCnr,ulView,param);
  634.          break;
  635.  
  636.    }   /* end switch (ulView) */
  637.  
  638. }   /* end carpp_wpOpen() */
  639.  
  640.  
  641. /*
  642.  *
  643.  *  METHOD: wpSetup                                        ( ) PRIVATE
  644.  *                                                         (X) PUBLIC
  645.  *  DESCRIPTION:
  646.  *
  647.  *    Specify Setup strings and do some initialization.  This method is
  648.  *    invoked once an object is completely created.
  649.  *
  650.  *  Note:  We're overriding this method to write some default data to the
  651.  *         object's real filename.  This will give us something to look at
  652.  *         if the user drag/drops us on an editor or selects the open/editor
  653.  *         view.
  654.  */
  655.  
  656. SOM_Scope BOOL   SOMLINK carpp_wpSetup(Carpp *somSelf,
  657.                 PSZ pszSetupString)
  658. {
  659.  ULONG cbBytesWritten;           /* pointer to variable receiving byte count */
  660.  APIRET rc;
  661.  BOOL fSuccess;
  662.  HFILE hf;                            /* pointer to variable for file handle */
  663.  ULONG ulAction;                     /* pointer to variable for action taken */
  664.  CHAR szObjectFilename[CCHMAXPATH];          /* buffer for wpQueryRealName() */
  665.  ULONG cb  = sizeof(szObjectFilename);
  666.  
  667.  
  668.     CarppData *somThis = CarppGetData(somSelf);
  669.     CarppMethodDebug("Carpp","carpp_wpSetup");
  670.  
  671.    /*
  672.     *   Write an initial bill-of-sale to the object data file
  673.     */
  674.  
  675.    fSuccess =
  676.    somSelf->wpQueryRealName(                 /* query full-pathname of object's file */
  677.       szObjectFilename,                                     /* return buffer */
  678.       &cb,                                                  /* sizeof buffer */
  679.       TRUE);                            /* request fully qualified pathname? */
  680.  
  681.    if (fSuccess)
  682.    {
  683.       rc =
  684.       DosOpen(szObjectFilename, &hf, &ulAction,
  685.          0,                             /* file size if created or truncated */
  686.          FILE_NORMAL,                                      /* file attribute */
  687.          FILE_OPEN             /* action taken if file exists/does not exist */
  688.             | FILE_CREATE,
  689.          OPEN_ACCESS_READWRITE                          /* open mode of file */
  690.             | OPEN_SHARE_DENYNONE,
  691.          NULL);              /* pointer to structure for extended attributes */
  692.  
  693.       if (rc)
  694.       {
  695.        CHAR ach[10];
  696.  
  697.          _ltoa(rc, ach, 10);
  698.          DebugBox("carpp_wpSetup:DosOpen failed rc =", ach);
  699.       }
  700.       else
  701.       {
  702.          DosWrite(hf,
  703.                   (PVOID)pcszDefaultText,
  704.                   strlen(pcszDefaultText),
  705.                   &cbBytesWritten);
  706.          DosClose(hf);
  707.       }
  708.    }   /* end if (fSuccess) */
  709.  
  710.    return (parent_wpSetup(somSelf,pszSetupString));
  711.  
  712. }   /* end carpp_wpSetup() */
  713.  
  714. /*
  715.  *
  716.  *  METHOD: TrapTest                                        ( ) PRIVATE
  717.  *                                                          (X) PUBLIC
  718.  *  DESCRIPTION:
  719.  *
  720.  *    Specify Setup strings and do some initialization.  This method is
  721.  *    invoked once an object is completely created.
  722.  *
  723.  *  Note:  The variable used to communicate the current state to the
  724.  *         exception handler is global.  If an exception occurs in more than
  725.  *         one instance of this object at the same time, the results will
  726.  *         be unpredictable.
  727.  */
  728.  
  729. #pragma handler (carpp_TrapTest)
  730. /*
  731.  *
  732.  * METHOD: TrapTest                                       ( ) PRIVATE
  733.  *                                                        (X) PUBLIC
  734.  * DESCRIPTION:
  735.  *
  736.  *   This method tests the exception handling in this sample.
  737.  *
  738.  * RETURN:
  739.  *
  740.  *   nothing
  741.  *
  742.  * HOW TO OVERRIDE:
  743.  *
  744.  *   n/a
  745.  *
  746.  *
  747.  *   Methods from the WPObject class
  748.  */
  749.  
  750. SOM_Scope void  SOMLINK carpp_TrapTest(Carpp *somSelf)
  751. {
  752.   PSZ      pszTrap = NULL;
  753.   jmp_buf  saveState;
  754.   CarppData *somThis = CarppGetData(somSelf);
  755.   CarppMethodDebug("Carpp","carpp_TrapTest");
  756.  
  757.    memcpy(saveState, jmpState, sizeof(jmpState));
  758.    if (!setjmp(jmpState))   /* no exception?*/
  759.    {
  760.       /*
  761.        *   Normal code for this method goes here
  762.        */
  763.  
  764.       *pszTrap = 'a';
  765.    }
  766.    else   /* we just returned from exception handler */
  767.    {
  768.       /*
  769.        *   An exception just occurred in this method.  We should put any
  770.        *   cleanup/recovery code in this code block and then return the
  771.        *   error to the caller.
  772.        */
  773.  
  774.       WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, pcszTrapMessage,
  775.                       "Exception Handler Test",
  776.                       999, MB_MOVEABLE | MB_OK | MB_ERROR);
  777.    }
  778.  
  779.    memcpy(jmpState, saveState, sizeof(jmpState));
  780.  
  781. }   /* end carpp_TrapTest() */
  782.  
  783. /**************************  CLASS METHODS SECTION  ***************************
  784. *****                                                                     *****
  785. *****              Do not put any code in this section unless             *****
  786. *****                     it is an object CLASS method                    *****
  787. *****                                                                     *****
  788. ******************************************************************************/
  789. #undef SOM_CurrentClass
  790. #define SOM_CurrentClass SOMMeta
  791.  
  792.  
  793. /*
  794.  *
  795.  *  METHOD: clsQueryModuleHandle                           ( ) PRIVATE
  796.  *                                                         (X) PUBLIC
  797.  *  DESCRIPTION:
  798.  *
  799.  *    This method returns the module handle of this class.  If this is the
  800.  *    first invocation, DosQueryModuleHandle is called to save the handle
  801.  *    for future invocations.
  802.  *
  803.  *  RETURN:
  804.  *
  805.  *    0              Unsuccessful
  806.  *    non-zero       module handle
  807.  *
  808.  */
  809.  
  810. /*
  811.  * METHOD: clsQueryModuleHandle                           ( ) PRIVATE
  812.  *                                                        (X) PUBLIC
  813.  * DESCRIPTION:
  814.  *
  815.  *   This method returns the module handle of this class.  If this is the
  816.  *   first invocation, DosQueryModuleHandle is called to save the handle
  817.  *   for future invocations.
  818.  *
  819.  * RETURN:
  820.  *
  821.  *   0              Unsuccessful
  822.  *   non-zero       module handle
  823.  */
  824.  
  825. SOM_Scope HMODULE   SOMLINK carppM_clsQueryModuleHandle(M_Carpp *somSelf)
  826. {
  827.  APIRET rc;
  828.  
  829.     /* M_CarppData *somThis = M_CarppGetData(somSelf); */
  830.     M_CarppMethodDebug("M_Carpp","carppM_clsQueryModuleHandle");
  831.  
  832.    /*
  833.     *   Make sure we already have module handle
  834.     */
  835.  
  836.  
  837.     if (hmod == NULLHANDLE)
  838.     {
  839.      zString zsPathName;
  840.        /*
  841.         *   Retrieve registered pathname of our module (DLL) and query the
  842.         *   module handle.
  843.         */
  844.        zsPathName =
  845.        (SOMClassMgrObject->somLocateClassFile(  SOM_IdFromString("Carpp"),
  846.                                               Carpp_MajorVersion, Carpp_MinorVersion));
  847.        rc =
  848.        DosQueryModuleHandle( zsPathName, &hmod);
  849.        if (rc)
  850.        {
  851.           DebugBox("carppM_wpclsInitData", "Failed to load module");
  852.           return 0L;
  853.        }
  854.  
  855.     }   /* end if (hmod == NULLHANDLE) */
  856.  
  857.     return (hmod);
  858.  
  859. }   /* end carppM_clsQueryModuleHandle() */
  860.  
  861. /*
  862.  *
  863.  *  METHOD: wpclsQueryStyle                                ( ) PRIVATE
  864.  *                                                         (X) PUBLIC
  865.  *  DESCRIPTION:
  866.  *
  867.  *     The wpclsQueryStyle method is called to allow the class object
  868.  *     to specify the default object class style for its instances.
  869.  *
  870.  *  REMARKS:
  871.  *
  872.  *     This method can be called at any time in order to determine the
  873.  *     default style for instances of this class.
  874.  *
  875.  *     This method should be overridden in order to modify the default
  876.  *     object style for instances of this class.
  877.  *
  878.  */
  879.  
  880. SOM_Scope ULONG   SOMLINK carppM_wpclsQueryStyle(M_Carpp *somSelf)
  881. {
  882.     /* M_CarppData *somThis = M_CarppGetData(somSelf); */
  883.     M_CarppMethodDebug("M_Carpp","carppM_wpclsQueryStyle");
  884.  
  885.     /*
  886.      *   Modify style bits as described in programming reference.  This
  887.      *   particular style (link) is also disabled in wpFilterPopupMenu()
  888.      */
  889.     return (parent_wpclsQueryStyle(somSelf) | CLSSTYLE_NEVERLINK);
  890. }
  891.  
  892. /*
  893.  *
  894.  *  METHOD: wpclsInitData                                  ( ) PRIVATE
  895.  *                                                         (X) PUBLIC
  896.  *  DESCRIPTION:
  897.  *
  898.  *    Initialize the class data
  899.  *
  900.  */
  901.  
  902. SOM_Scope void  SOMLINK carppM_wpclsInitData(M_Carpp *somSelf)
  903. {
  904.  ULONG rc, i;
  905.  PCLASSFIELDINFO pCFI;
  906.  
  907.     /* M_CarppData *somThis  = M_CarppGetData(somSelf); */
  908.     M_CarppMethodDebug("M_Carpp","carppM_wpclsInitData");
  909.  
  910.     /*
  911.      *   Call the parent class method first
  912.      */
  913.     parent_wpclsInitData(somSelf);
  914.  
  915.     /*
  916.      *   Get class title
  917.      */
  918.     if (!WinLoadString(WinQueryAnchorBlock(HWND_DESKTOP), somSelf->clsQueryModuleHandle(), ID_TITLE,
  919.                          sizeof(szCarClassTitle), szCarClassTitle))
  920.                               /* Load string failed: use the parent's string */
  921.        strcpy(szCarClassTitle, parent_wpclsQueryTitle(somSelf));
  922.  
  923.    /*
  924.     *   Initialize everything needed for the CLASSFIELDINFO structures
  925.     *   for the Car object class
  926.     */
  927.  
  928.    for (i=0, pCFI=fieldinfo; i < NUM_CAR_FIELDS; i++, pCFI++)
  929.    {
  930.       memset((PCH) pCFI, 0, sizeof(CLASSFIELDINFO));               /* zero's */
  931.  
  932.       pCFI->cb        = sizeof(CLASSFIELDINFO);
  933.       pCFI->flData    = CFA_RIGHT | CFA_SEPARATOR | CFA_FIREADONLY;
  934.       pCFI->flTitle   = CFA_CENTER | CFA_SEPARATOR | CFA_HORZSEPARATOR |
  935.                         CFA_STRING | CFA_FITITLEREADONLY;
  936.       pCFI->pNextFieldInfo = pCFI + 1;       /* point to next CLASSFIELDINFO */
  937.       pCFI->pTitleData = (PVOID) apszCarColTitles[i];
  938.       pCFI->flCompare  = COMPARE_SUPPORTED | SORTBY_SUPPORTED;
  939.  
  940.  
  941. /*******************************************************/
  942. /* KLUDGE - w/o the ULONG typecast there is an error */
  943. /******************************************************* */
  944. /* Calculate the byte offset of a field in a structure of type type. */
  945. #define LFIELDOFFSET(type, field)    ((ULONG)&(((type *)0)->field))
  946.  
  947.       switch (i)
  948.       {
  949.          case INDEX_MAKE:
  950.  
  951.             pCFI->flData           |= CFA_STRING;
  952.             pCFI->offFieldData      = (ULONG)(LFIELDOFFSET(CARDETAILS,pszMake));
  953.             pCFI->ulLenFieldData    = sizeof(PSZ);
  954.             pCFI->DefaultComparison = CMP_EQUAL;
  955.  
  956.             break;
  957.  
  958.          case INDEX_MODEL:
  959.  
  960.             pCFI->flData           |= CFA_STRING;
  961.             pCFI->offFieldData      = (ULONG)(LFIELDOFFSET(CARDETAILS,pszModel));
  962.             pCFI->ulLenFieldData    = sizeof(PSZ);
  963.             pCFI->DefaultComparison = CMP_EQUAL;
  964.  
  965.             break;
  966.  
  967.          case INDEX_COLOR:
  968.  
  969.             pCFI->flData           |= CFA_STRING;
  970.             pCFI->offFieldData      = (ULONG)(LFIELDOFFSET(CARDETAILS,pszColor));
  971.             pCFI->ulLenFieldData    = sizeof(PSZ);
  972.             pCFI->DefaultComparison = CMP_EQUAL;
  973.  
  974.             break;
  975.  
  976.          case INDEX_SALE_DATE:
  977.  
  978.             pCFI->flData           |= CFA_DATE;
  979.             pCFI->offFieldData      = (ULONG)(LFIELDOFFSET(CARDETAILS,cdateSale));
  980.             pCFI->ulLenFieldData    = sizeof(CDATE);
  981.             pCFI->ulLenCompareValue = sizeof(CDATE);
  982.             pCFI->DefaultComparison = CMP_GREATER;
  983.  
  984.             break;
  985.  
  986.          case INDEX_PRICE:
  987.  
  988.             pCFI->flData           |= CFA_ULONG;
  989.             pCFI->offFieldData      = (ULONG)(LFIELDOFFSET(CARDETAILS,ulPrice));
  990.             pCFI->ulLenFieldData    = sizeof(ULONG);
  991.             pCFI->ulLenCompareValue = sizeof(ULONG);
  992.             pCFI->DefaultComparison = CMP_GREATER;
  993.  
  994.             break;
  995.  
  996.       }   /* end switch(i) */
  997.  
  998.    }   /* end for (i=0, pCFI=fieldinfo; i < NUM_CAR_FIELDS; i++, pCFI++)  */
  999.  
  1000.    fieldinfo[NUM_CAR_FIELDS-1].pNextFieldInfo = NULL;/* terminate linked list */
  1001.  
  1002. }   /* end carppM_ wpclsInitData() */
  1003.  
  1004. /*
  1005.  *
  1006.  *  METHOD: wpclsUnInitData                                ( ) PRIVATE
  1007.  *                                                         (X) PUBLIC
  1008.  *  DESCRIPTION:
  1009.  *
  1010.  *    Free any class data
  1011.  *
  1012.  */
  1013.  
  1014. SOM_Scope void SOMLINK carppM_wpclsUnInitData(M_Carpp *somSelf)
  1015. {
  1016.     M_CarppMethodDebug("M_Carpp","carppM_wpclsUnInitData");
  1017.  
  1018.     parent_wpclsUnInitData(somSelf);
  1019.  
  1020. }   /* end carppM_wpclsUnInitData() */
  1021.  
  1022. /*
  1023.  *
  1024.  *  METHOD: wpclsQueryTitle                                ( ) PRIVATE
  1025.  *                                                         (X) PUBLIC
  1026.  *  DESCRIPTION:
  1027.  *
  1028.  *    Return the string "New car".
  1029.  *
  1030.  */
  1031.  
  1032. SOM_Scope PSZ SOMLINK carppM_wpclsQueryTitle(M_Carpp *somSelf)
  1033. {
  1034.                               /* M_CarppData *somThis = M_CarppGetData(somSelf); */
  1035.     M_CarppMethodDebug("M_Carpp","carppM_wpclsQueryTitle");
  1036.  
  1037.     /*
  1038.      *   Return the class title for a car
  1039.      */
  1040.  
  1041.     if (*szCarClassTitle )
  1042.        return( szCarClassTitle );
  1043.     else
  1044.        return( parent_wpclsQueryTitle(somSelf));
  1045.  
  1046. }   /* end carppM_wpclsQueryTitle() */
  1047.  
  1048. /*
  1049.  *
  1050.  *  METHOD: wpclsQueryIconDdata                            ( ) PRIVATE
  1051.  *                                                         (X) PUBLIC
  1052.  *  DESCRIPTION:
  1053.  *
  1054.  *    Return the class icon
  1055.  *
  1056.  */
  1057.  
  1058. SOM_Scope ULONG SOMLINK carppM_wpclsQueryIconData(M_Carpp *somSelf,
  1059.                   PICONINFO pIconInfo)
  1060. {
  1061.    APIRET rc;
  1062.  
  1063.    M_CarppMethodDebug("M_Carpp","carppM_wpclsQueryIconData");
  1064.  
  1065.    if (pIconInfo)
  1066.    {
  1067.       /*
  1068.        *   fill in icon information
  1069.        */
  1070.       pIconInfo->fFormat = ICON_RESOURCE;
  1071.       pIconInfo->hmod= somSelf->clsQueryModuleHandle();
  1072.       pIconInfo->resid= ID_ICON;
  1073.    }
  1074.  
  1075.    return (sizeof(ICONINFO));
  1076.  
  1077. }   /* end carppM_wpclsQueryIconData() */
  1078.  
  1079. /*
  1080.  *
  1081.  *  METHOD: wpclsQueryDefaultHelp                          ( ) PRIVATE
  1082.  *                                                         (X) PUBLIC
  1083.  *  DESCRIPTION:
  1084.  *
  1085.  *    Process input from the extra menu option that we added.
  1086.  *
  1087.  */
  1088.  
  1089. SOM_Scope BOOL SOMLINK carppM_wpclsQueryDefaultHelp(M_Carpp *somSelf,
  1090.                 PULONG pHelpPanelId,
  1091.                 PSZ pszHelpLibrary)
  1092. {
  1093.                               /* M_CarppData *somThis = M_CarppGetData(somSelf); */
  1094.     M_CarppMethodDebug("M_Carpp","carppM_wpclsQueryDefaultHelp");
  1095.  
  1096.     if (pHelpPanelId)                           /* set default help panel id */
  1097.        *pHelpPanelId   = ID_HELP_DEFAULT;
  1098.  
  1099.     if (pszHelpLibrary)                                /* copy help filename */
  1100.        strcpy(pszHelpLibrary, szHelpLibrary);
  1101.  
  1102.     return (TRUE);
  1103.  
  1104. }   /* end carppM_wpclsQueryDefaultHelp() */
  1105.  
  1106. /*
  1107.  *
  1108.  *  METHOD: wpclsQueryDefaultView                          ( ) PRIVATE
  1109.  *                                                         (X) PUBLIC
  1110.  *  DESCRIPTION:
  1111.  *
  1112.  *    Returns the default view for a new instance of this object.
  1113.  *
  1114.  *  REMARKS:
  1115.  *
  1116.  *    Tell the system what our default open view is...
  1117.  *
  1118.  */
  1119.  
  1120. SOM_Scope ULONG SOMLINK carppM_wpclsQueryDefaultView(M_Carpp *somSelf)
  1121. {
  1122.                               /* M_CarppData *somThis = M_CarppGetData(somSelf); */
  1123.     M_CarppMethodDebug("M_Carpp","carppM_wpclsQueryDefaultView");
  1124.  
  1125.     return OPEN_CAR;
  1126.  
  1127. }   /* end carppM_wpclsQueryDefaultView() */
  1128.  
  1129. /*
  1130.  *
  1131.  *  METHOD: wpclsQueryDetailsInfo                          ( ) PRIVATE
  1132.  *                                                         (X) PUBLIC
  1133.  *  DESCRIPTION:
  1134.  *
  1135.  *    Appends the car specific chain of FIELDINFO structures describing the
  1136.  *    details data of this object to *ppClassFieldInfo (if ppClassFieldInfo
  1137.  *    is NON-NULL).  In this case it also sets *ppClassFieldInfo to the
  1138.  *    head of the linked list.
  1139.  *
  1140.  *    Adds the number of bytes required by the details data for car to *pSize
  1141.  *    (if pSize is NON-NULL).
  1142.  *
  1143.  *  REMARKS:
  1144.  *
  1145.  *    Add details data for this object.
  1146.  *
  1147.  */
  1148.  
  1149. SOM_Scope ULONG SOMLINK carppM_wpclsQueryDetailsInfo(M_Carpp *somSelf,
  1150.                 PCLASSFIELDINFO *ppClassFieldInfo,
  1151.                 PULONG pSize)
  1152. {
  1153.  ULONG           cParentColumns;
  1154.  PCLASSFIELDINFO pCFI;
  1155.  ULONG           i;
  1156.  
  1157.     /* M_CarppData *somThis = M_CarppGetData(somSelf); */
  1158.     M_CarppMethodDebug("M_Carpp","carppM_wpclsQueryDetailsInfo");
  1159.  
  1160.    /*
  1161.     *   Always call the parent method first to retrieve number of details
  1162.     *   columns and parent's data already defined in details buffer.
  1163.     */
  1164.  
  1165.    cParentColumns =
  1166.    parent_wpclsQueryDetailsInfo(somSelf, ppClassFieldInfo, pSize);
  1167.  
  1168.    /*
  1169.     *   If pSize is non-NULL, we must add the size of our deatils column
  1170.     *   data structure.
  1171.     */
  1172.  
  1173.    if (pSize)
  1174.       *pSize += sizeof(CARDETAILS);                           /* adjust size */
  1175.  
  1176.    /*
  1177.     *   If the request was for the chained fieldinfo structures
  1178.     *   (ppClassFieldInfo is non-NULL), link them in
  1179.     *
  1180.     *   eventually the chain will look like
  1181.     *
  1182.     *   Grandad - Dad - Me - Kid - Grandkid
  1183.     *
  1184.     *   I will be getting the pointer to the beginning of the chain
  1185.     *
  1186.     *   If the beginning of the chain is 0, I will assign the address
  1187.     *   of my first CLASSFIELDINFO structure to *ppClassFieldInfo.
  1188.     *   Otherwise *pp points to the first column description in the
  1189.     *   chain.  We need to walk the chain and link our CLASSFIELDINFO
  1190.     *   structures at the end.
  1191.     */
  1192.  
  1193.    if (ppClassFieldInfo)
  1194.    {
  1195.       /*
  1196.        *   Find the last link in the chain;  Then link our CLASSFIELDINFO
  1197.        *   structures to the chain.
  1198.        */
  1199.  
  1200.       if (*ppClassFieldInfo)
  1201.       {
  1202.          pCFI = *ppClassFieldInfo;
  1203.          for (i=0;i<cParentColumns;i++)
  1204.             pCFI = (pCFI->pNextFieldInfo) ? pCFI->pNextFieldInfo : pCFI;
  1205.  
  1206.          pCFI->pNextFieldInfo = fieldinfo;
  1207.       }
  1208.       else
  1209.          *ppClassFieldInfo = fieldinfo;
  1210.    }
  1211.    return ((ULONG) (cParentColumns + NUM_CAR_FIELDS));
  1212.  
  1213. }   /* end carppM_wpclsQueryDetailsInfo() */
  1214.  
  1215. /*
  1216.  *
  1217.  *  METHOD: wpclsQueryInstanceFilter                       ( ) PRIVATE
  1218.  *                                                         (X) PUBLIC
  1219.  *  DESCRIPTION:
  1220.  *
  1221.  *     The wpclsQueryInstanceFilter method is called to allow the class
  1222.  *     object to specify the file title filters for instances of its
  1223.  *     class.
  1224.  *
  1225.  *  REMARKS:
  1226.  *
  1227.  *     A pointer to a string containing file title filter(s).  This
  1228.  *     string can contain several file title filters separated by a
  1229.  *     comma.  Example: "*.TXT, *.DOC"
  1230.  *
  1231.  *  Note:  Overriding this method will cause any data file with the extension
  1232.  *         ".CAR" to become a data object of the class "Car."
  1233.  *
  1234.  */
  1235.  
  1236. SOM_Scope PSZ   SOMLINK carppM_wpclsQueryInstanceFilter(M_Carpp *somSelf)
  1237. {
  1238.     /* M_CarppData *somThis = M_CarppGetData(somSelf); */
  1239.     M_CarppMethodDebug("M_Carpp","carppM_wpclsQueryInstanceFilter");
  1240.  
  1241.     return (szCarInstanceFilter);
  1242. }
  1243.  
  1244.  
  1245. /*
  1246.  *
  1247.  *  METHOD: wpclsQueryDetails                              ( ) PRIVATE
  1248.  *                                                         (X) PUBLIC
  1249.  *  DESCRIPTION:
  1250.  *
  1251.  *     Specify default details to display in details view
  1252.  *
  1253.  *  REMARKS:
  1254.  *
  1255.  *     A pointer details structure is modified and returned.
  1256.  *     Note: this is purely virtual at the moment (parent class doesn't
  1257.  *     do anything).
  1258.  */
  1259.  
  1260. SOM_Scope PCLASSDETAILS   SOMLINK carppM_wpclsQueryDetails(M_Carpp *somSelf)
  1261. {
  1262.     /* M_CarppData *somThis = M_CarppGetData(somSelf); */
  1263.     M_CarppMethodDebug("M_Carpp","carppM_wpclsQueryDetails");
  1264.  
  1265.     return (parent_wpclsQueryDetails(somSelf));
  1266. }
  1267.  
  1268.  
  1269. /**************************  ORDINARY CODE SECTION  ***************************
  1270. *****                                                                     *****
  1271. *****                  Any non-method code should go here.                *****
  1272. *****                                                                     *****
  1273. ******************************************************************************/
  1274. #undef SOM_CurrentClass
  1275.  
  1276.  
  1277. /***************************************************************************
  1278. *                                                                          *
  1279. *       ROUTINE:    CarInit ( )                                            *
  1280. *                                                                          *
  1281. *       DESCRIPTION:    Car Initialization                                 *
  1282. *                                                                          *
  1283. *       RETURNS:    Handle of car frame window, NULL if error              *
  1284. *                                                                          *
  1285. ***************************************************************************/
  1286. HWND CarInit (Carpp* somSelf)
  1287. {
  1288.    HAB  hab;                                       /* PM anchor block handle */
  1289.    HWND hwndFrame = NULLHANDLE;                       /* Frame window handle */
  1290.    HWND hwndClient = NULLHANDLE;
  1291.    PWINDOWDATA pWindowData;
  1292.    BOOL fSuccess;
  1293.    SWCNTRL    swcEntry;                                      /* Switch Entry */
  1294.    FRAMECDATA flFrameCtlData;                              /* Frame Ctl Data */
  1295.  
  1296.    hab = WinQueryAnchorBlock(HWND_DESKTOP);
  1297.    if (!WinRegisterClass( hab , szCarWindowClass, (PFNWP)CarWndProc ,
  1298.                             CS_SIZEREDRAW | CS_SYNCPAINT, sizeof(pWindowData)))
  1299.    {
  1300.       DebugBox("CarInit", "Failure in WinRegisterClass");
  1301.       return NULLHANDLE ;
  1302.    }
  1303.  
  1304.    /*
  1305.     *   Allocate some instance specific data in Window words of Frame window.
  1306.     *   This will ensure our window procedure can use this object's methods
  1307.     *   (our window proc isn't passed a * somSelf pointer).
  1308.     */
  1309.    pWindowData = (PWINDOWDATA) somSelf->wpAllocMem( sizeof(*pWindowData), NULL);
  1310.  
  1311.    if (!pWindowData)
  1312.    {
  1313.       DebugBox("CarInit", "wpAllocMem failed to allocate pWindowData");
  1314.       return NULLHANDLE;
  1315.    }
  1316.  
  1317.    memset((PVOID) pWindowData, 0, sizeof(*pWindowData));
  1318.    pWindowData->cb = sizeof(*pWindowData);             /* first field = size */
  1319.    pWindowData->somSelf = somSelf;
  1320.  
  1321.    /* Create a frame window
  1322.     */
  1323.    flFrameCtlData.cb            = sizeof( flFrameCtlData );
  1324.    flFrameCtlData.flCreateFlags = FCF_SIZEBORDER | FCF_TITLEBAR | FCF_SYSMENU |
  1325.                                   FCF_MINMAX ;
  1326.    flFrameCtlData.hmodResources = hmod;
  1327.    flFrameCtlData.idResources   = ID_ICON;
  1328.  
  1329.    hwndFrame =                                        /* create frame window */
  1330.    WinCreateWindow(
  1331.       HWND_DESKTOP,               /* parent-window handle                    */
  1332.       WC_FRAME,                   /* pointer to registered class name        */
  1333.       somSelf->wpQueryTitle(),     /* pointer to window text                  */
  1334.       0,                          /* window style                            */
  1335.       0, 0, 0, 0,                 /* position of window                      */
  1336.       NULLHANDLE,                 /* owner-window handle                     */
  1337.       HWND_TOP,                   /* handle to sibling window                */
  1338.       (USHORT) ID_FRAME,          /* window identifier                       */
  1339.       (PVOID) &flFrameCtlData,    /* pointer to buffer                       */
  1340.       NULL);      ;               /* pointer to structure with pres. params. */
  1341.  
  1342.    if (!hwndFrame)
  1343.    {
  1344.       DebugBox("CarInit", "Failure in WinCreateWindow");
  1345.       return NULLHANDLE;
  1346.    }
  1347.    hwndClient =         /* use WinCreateWindow so we can pass pres params */
  1348.    WinCreateWindow(
  1349.       hwndFrame,               /* parent-window handle                    */
  1350.       szCarWindowClass,        /* pointer to registered class name        */
  1351.       NULL,                    /* pointer to window text                  */
  1352.       0,                       /* window style                            */
  1353.       0, 0, 0, 0,              /* position of window                      */
  1354.       hwndFrame,               /* owner-window handle                     */
  1355.       HWND_TOP,                /* handle to sibling window                */
  1356.       (USHORT)FID_CLIENT,      /* window identifier                       */
  1357.       pWindowData,             /* pointer to buffer                       */
  1358.       NULL);                   /* pointer to structure with pres. params. */
  1359.  
  1360.    if (!hwndClient)
  1361.    {
  1362.       WinDestroyWindow(hwndFrame);
  1363.       return NULLHANDLE;
  1364.    }
  1365.  
  1366.    WinSendMsg(hwndFrame, WM_SETICON, MPFROMP(somSelf->wpQueryIcon()), NULL);
  1367.    WinSetWindowText(WinWindowFromID(hwndFrame,(USHORT)FID_TITLEBAR),
  1368.                                                          somSelf->wpQueryTitle());
  1369.  
  1370.    /*
  1371.     * Restore the Window Position
  1372.     */
  1373.    fSuccess =
  1374.    WinRestoreWindowPos(
  1375.       szCarClassTitle,                                        /* class title */
  1376.       somSelf->wpQueryTitle(),                                /* object title */
  1377.       hwndFrame);
  1378.  
  1379.    if (!fSuccess)
  1380.    {
  1381.     SWP        swp;
  1382.  
  1383.       /* Get the dimensions and the shell's suggested
  1384.        * location for the window
  1385.        */
  1386.       WinQueryTaskSizePos(hab,0,&swp);
  1387.  
  1388.       /* Set the frame window position
  1389.        */
  1390.      swp.fl               = SWP_SIZE|SWP_MOVE|SWP_RESTORE|SWP_ZORDER;
  1391.      WinSetWindowPos(hwndFrame, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy, swp.fl);
  1392.    }
  1393.  
  1394.    WinShowWindow(hwndFrame,TRUE);
  1395.    WinStartTimer(hab, hwndClient, CAR_TIMER, (ULONG)100);
  1396.  
  1397.    return hwndFrame;                                              /* success */
  1398.  
  1399. }   /* end CarInit() */
  1400.  
  1401.  
  1402. /******************************************************************************
  1403. *
  1404. *   CarWndProc()
  1405. *
  1406. *   DESCRIPTION: Car Window Procedure
  1407. *
  1408. ******************************************************************************/
  1409. MRESULT EXPENTRY CarWndProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  1410. {
  1411.   ULONG    MenuId;
  1412.   PWINDOWDATA pWindowData;
  1413.   CarppData *somThis;
  1414.   HWND     hwndFrame;
  1415.   CHAR     acBuffer[10];
  1416.   BOOL     fSuccess;
  1417.  
  1418.    hwndFrame = WinQueryWindow(hwnd, QW_PARENT);
  1419.  
  1420.    switch( msg )
  1421.    {
  1422.       case WM_CREATE:
  1423.  
  1424.         pWindowData = (PWINDOWDATA) mp1;
  1425.  
  1426.         if (pWindowData == NULL)
  1427.         {
  1428.            DebugBox("CarWndProc:WM_CREATE", "couldn't get window words");
  1429.            return FALSE;
  1430.         }
  1431.         /*
  1432.          *   Fill in the class view/usage details and window specific data
  1433.          *   for this instance.
  1434.          */
  1435.         pWindowData->UseItem.type    = USAGE_OPENVIEW;
  1436.         pWindowData->ViewItem.view   = OPEN_CAR;
  1437.         pWindowData->ViewItem.handle = hwndFrame;
  1438.         pWindowData->x               = 10;
  1439.         pWindowData->y               = 10;
  1440.         pWindowData->xDir            = CAR_RIGHT;
  1441.         pWindowData->yDir            = CAR_UP;
  1442.  
  1443.         /*
  1444.          *   Set window pointer with object pointer and instance view info.
  1445.          *   Then add view to the in-use list so wpSwitchTo works.
  1446.          */
  1447.         WinSetWindowPtr(hwnd, QWL_USER, pWindowData);
  1448.         pWindowData->somSelf->wpAddToObjUseList( &pWindowData->UseItem);
  1449.         pWindowData->somSelf->wpRegisterView( hwndFrame,
  1450.                                              pWindowData->somSelf->wpQueryTitle());
  1451.         WinSetFocus( HWND_DESKTOP, hwndFrame);
  1452.  
  1453.         break;
  1454.  
  1455.       case WM_COMMAND:
  1456.  
  1457.         break;
  1458.  
  1459.       case WM_TIMER:
  1460.  
  1461.          pWindowData = (PWINDOWDATA) WinQueryWindowPtr(hwnd, QWL_USER);
  1462.  
  1463.          if (pWindowData == NULL)
  1464.          {
  1465.             DebugBox("CarWndProc:WM_TIMER", "couldn't get window words");
  1466.             return FALSE;
  1467.          }
  1468.          else
  1469.          {
  1470.           RECTL  rectl;
  1471.           somThis = CarppGetData(pWindowData->somSelf);
  1472.  
  1473.             /*
  1474.              *   If the car's brakes are off, we move the car by modifying it's
  1475.              *   x,y position.  Direction (xDir, yDir) changes when the car's
  1476.              *   position reaches a border of the window.  The distance it
  1477.              *   moves is based on the speed contained in an instance variable.
  1478.              */
  1479.  
  1480.             if (somThis->carBrake->IsSet() == FALSE)
  1481.             {
  1482.                WinQueryWindowRect(hwnd,&rectl);
  1483.  
  1484.                if (pWindowData->x <= 0)                   /* at left border? */
  1485.                   pWindowData->xDir = CAR_RIGHT;              /* mult. by  1 */
  1486.                else
  1487.                   if (pWindowData->x >= rectl.xRight - ICON_WIDTH)
  1488.                      pWindowData->xDir = CAR_LEFT;            /* mult. by -1 */
  1489.  
  1490.                if (pWindowData->y <= 0)                 /* at bottom border? */
  1491.                   pWindowData->yDir = CAR_UP;                 /* mult. by  1 */
  1492.                else
  1493.                   if (pWindowData->y >= rectl.yTop - ICON_HEIGHT)
  1494.                      pWindowData->yDir = CAR_DOWN;            /* mult. by -1 */
  1495.  
  1496.                pWindowData->x +=
  1497.                   pWindowData->xDir * (somThis->carRPM->Query());
  1498.  
  1499.                pWindowData->y +=
  1500.                   pWindowData->yDir * (somThis->carRPM->Query());
  1501.  
  1502.                WinInvalidateRect(hwnd, &rectl, TRUE);  /* invalidate car region */
  1503.             }
  1504.          }
  1505.          break;
  1506.  
  1507.       case WM_PAINT:
  1508.          pWindowData = (PWINDOWDATA) WinQueryWindowPtr(hwnd, QWL_USER);
  1509.  
  1510.          if (pWindowData == NULL)
  1511.          {
  1512.             DebugBox("CarWndProc:WM_PAINT", "couldn't get window words");
  1513.             return FALSE;
  1514.          }
  1515.          else
  1516.          {
  1517.           HPS    hps;
  1518.           RECTL  rectl;
  1519.  
  1520.            hps = WinBeginPaint( hwnd, (HPS)NULLHANDLE, &rectl);
  1521.            WinFillRect( hps, &rectl, SYSCLR_WINDOW);
  1522.            WinDrawPointer(hps, pWindowData->x, pWindowData->y,
  1523.                           pWindowData->somSelf->wpQueryIcon(), DP_NORMAL);
  1524.            WinEndPaint( hps );
  1525.          }
  1526.          break;
  1527.  
  1528.       case WM_CLOSE:
  1529.          {
  1530.           HAB hab;
  1531.  
  1532.             hab = WinQueryAnchorBlock(HWND_DESKTOP);
  1533.             WinStopTimer(hab,hwnd,CAR_TIMER);
  1534.  
  1535.             pWindowData = (PWINDOWDATA) WinQueryWindowPtr(hwnd, QWL_USER);
  1536.  
  1537.             if (pWindowData == NULL)
  1538.             {
  1539.                DebugBox("CarWndProc:WM_CLOSE", "couldn't get window words");
  1540.                return FALSE;
  1541.             }
  1542.             fSuccess =
  1543.             WinStoreWindowPos(szCarClassTitle,pWindowData->somSelf->wpQueryTitle(),
  1544.                                                                         hwndFrame);
  1545.             pWindowData->somSelf->wpDeleteFromObjUseList( &pWindowData->UseItem );
  1546.             pWindowData->somSelf->wpFreeMem( (PBYTE)pWindowData );
  1547.  
  1548.             WinPostMsg( hwnd, WM_QUIT, 0, 0 );
  1549.             WinDestroyWindow ( hwndFrame ) ;
  1550.          }
  1551.          break;
  1552.  
  1553.       default:
  1554.          return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  1555.    }
  1556.    return FALSE;
  1557.  
  1558. }   /* end CarWndProc() */
  1559.  
  1560. /******************************************************************************
  1561. *
  1562. *   DashBoardDlgProc()
  1563. *
  1564. *   DESCRIPTION: Dialog Procedure for Dashboaard settings page
  1565. *
  1566. ******************************************************************************/
  1567. MRESULT EXPENTRY DashBoardDlgProc(HWND hwndDlg, ULONG msg,
  1568.                                   MPARAM mp1, MPARAM mp2)
  1569. {
  1570.  DASHDLGDATA * pDashDlgData;
  1571.  CarppData *somThis;
  1572.  CHAR          acBuffer[10];
  1573.  
  1574.    switch (msg)
  1575.    {
  1576.       case WM_INITDLG:
  1577.       {
  1578.          USHORT    usCount;
  1579.          SLDCDATA  SliderData;
  1580.          WNDPARAMS wprm;
  1581.  
  1582.          /*
  1583.           *   Store some instance specific data in Window words of this dialog.
  1584.           *   This will ensure our dialog procedure can access this objects
  1585.           *   data (our dialog proc isn't always passed a *somSelf pointer).
  1586.           */
  1587.          pDashDlgData =
  1588.             (PDASHDLGDATA) (((Carpp *)mp2)->wpAllocMem(sizeof(*pDashDlgData), NULL));
  1589.          if (pDashDlgData)
  1590.          {
  1591.             memset((PVOID) pDashDlgData, 0, sizeof(*pDashDlgData));
  1592.             pDashDlgData->cb = sizeof(*pDashDlgData);
  1593.             pDashDlgData->somSelf = (Carpp *) mp2;   /* pointer to this object */
  1594.             somThis = CarppGetData(pDashDlgData->somSelf);
  1595.             pDashDlgData->PrevBrakes = somThis->carBrake->IsSet();
  1596.             pDashDlgData->PrevSpeed  = somThis->carRPM->Query();
  1597.          }
  1598.          else
  1599.          {
  1600.             DebugBox("DashboardDlgProc:WM_INITDLG", "Couldn't allocate window words");
  1601.             break;
  1602.          }
  1603.  
  1604.          WinSetWindowPtr(hwndDlg, QWL_USER, pDashDlgData);
  1605.  
  1606.          SliderData.cbSize = sizeof(SLDCDATA);
  1607.          SliderData.usScale1Increments = 10;
  1608.          SliderData.usScale1Spacing = 20;
  1609.          SliderData.usScale2Increments = 10;
  1610.          SliderData.usScale2Spacing = 20;
  1611.  
  1612.          wprm.fsStatus = WPM_CTLDATA;
  1613.          wprm.cchText = 0;
  1614.          wprm.cbPresParams = 0;
  1615.          wprm.cbCtlData = 0;
  1616.          wprm.pCtlData = &SliderData;
  1617.          WinSendDlgItemMsg(hwndDlg,ID_SPEEDSLIDER,
  1618.                           WM_SETWINDOWPARAMS,(MPARAM)&wprm,(MPARAM)NULL ) ;
  1619.  
  1620.          for (usCount = 0; usCount < 10; usCount++ )
  1621.          {
  1622.             WinSendDlgItemMsg(hwndDlg,ID_SPEEDSLIDER,
  1623.                 SLM_SETTICKSIZE,MPFROM2SHORT(usCount,5),NULL);
  1624.  
  1625.            _itoa((usCount*10),acBuffer,10);
  1626.             WinSendDlgItemMsg(hwndDlg, ID_SPEEDSLIDER, SLM_SETSCALETEXT,
  1627.                MPFROMSHORT(usCount), MPFROMP(acBuffer));
  1628.          }
  1629.          WinSendDlgItemMsg(hwndDlg,ID_SPEEDSLIDER,SLM_SETSLIDERINFO,
  1630.             MPFROM2SHORT(SMA_SLIDERARMDIMENSIONS,NULL),
  1631.             MPFROM2SHORT(20,40));
  1632.  
  1633.          WinSendDlgItemMsg(hwndDlg,ID_SPEEDSLIDER,SLM_SETSLIDERINFO,
  1634.             MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE),
  1635.             MPFROMSHORT((SHORT)(somThis->carRPM->Query())/10));
  1636.  
  1637.          WinSetDlgItemText(hwndDlg,ID_SPEEDDATA,
  1638.             _ltoa(somThis->carRPM->Query(),acBuffer,10));
  1639.  
  1640.          if (somThis->carBrake->IsSet() == FALSE)
  1641.          {
  1642.             WinSendDlgItemMsg(hwndDlg,ID_GO,BM_SETCHECK,(MPARAM)1L, MPVOID);
  1643.          }
  1644.          else
  1645.          {
  1646.             WinSendDlgItemMsg(hwndDlg,ID_STOP,BM_SETCHECK,(MPARAM)1L, MPVOID);
  1647.          }
  1648.  
  1649.          return (MRESULT) TRUE;
  1650.  
  1651.       }   /* end case WM_INITDLG: */
  1652.  
  1653.       case WM_DESTROY:
  1654.  
  1655.          pDashDlgData = (PDASHDLGDATA)WinQueryWindowPtr(hwndDlg, QWL_USER);
  1656.          if (pDashDlgData == NULL)
  1657.          {
  1658.             DebugBox("DashboardDlgProc:WM_DESTROY", "couldn't get window words");
  1659.             break;
  1660.          }
  1661.          pDashDlgData->somSelf->wpFreeMem((PBYTE)pDashDlgData);
  1662.          return (WinDefDlgProc(hwndDlg, msg, mp1, mp2) );
  1663.  
  1664.       case WM_COMMAND:
  1665.  
  1666.          pDashDlgData = (PDASHDLGDATA)WinQueryWindowPtr(hwndDlg, QWL_USER);
  1667.          somThis = CarppGetData(pDashDlgData->somSelf);
  1668.          if (pDashDlgData == NULL)
  1669.          {
  1670.             DebugBox("DashboardDlgProc:WM_COMMAND", "couldn't get window words");
  1671.             break;
  1672.          }
  1673.  
  1674.          switch (SHORT1FROMMP(mp1))
  1675.          {
  1676.             case ID_UNDO:
  1677.                if (pDashDlgData->PrevBrakes == TRUE)
  1678.                {
  1679.                  somThis->carBrake->Set();
  1680.                }
  1681.                else
  1682.                {
  1683.                  somThis->carBrake->Release();
  1684.                }
  1685.  
  1686.                somThis->carRPM->Set( pDashDlgData->PrevSpeed);
  1687.  
  1688.                WinSendDlgItemMsg(hwndDlg,ID_SPEEDSLIDER,SLM_SETSLIDERINFO,
  1689.                   MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE),
  1690.                   MPFROMSHORT((SHORT)(somThis->carRPM->Query()/10)));
  1691.  
  1692.                WinSetDlgItemText(hwndDlg,ID_SPEEDDATA,
  1693.                   _ltoa(somThis->carRPM->Query(),acBuffer,10));
  1694.  
  1695.                if (somThis->carBrake->IsSet() == FALSE)
  1696.                {
  1697.                   WinSendDlgItemMsg(hwndDlg,ID_GO,BM_SETCHECK,
  1698.                      (MPARAM)1L, MPVOID);
  1699.                }
  1700.                else
  1701.                {
  1702.                   WinSendDlgItemMsg(hwndDlg,ID_STOP,BM_SETCHECK,
  1703.                      (MPARAM)1L, MPVOID);
  1704.                }
  1705.  
  1706.                break;
  1707.  
  1708.             case ID_DEFAULT:
  1709.                /*
  1710.                 *   preserve previous values
  1711.                 */
  1712.                pDashDlgData->PrevBrakes = somThis->carBrake->IsSet();
  1713.                pDashDlgData->PrevSpeed  = somThis->carRPM->Query();
  1714.  
  1715.                somThis->carBrake->SetToDefault();
  1716.                somThis->carRPM->SetToDefault();
  1717.  
  1718.                WinSendDlgItemMsg(hwndDlg,ID_SPEEDSLIDER,SLM_SETSLIDERINFO,
  1719.                   MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE),
  1720.                   MPFROMSHORT((SHORT)(somThis->carRPM->Query()/10)));
  1721.  
  1722.                WinSetDlgItemText(hwndDlg,ID_SPEEDDATA,
  1723.                   _ltoa(somThis->carRPM->Query(), acBuffer,10));
  1724.  
  1725.                WinSendDlgItemMsg(hwndDlg,ID_GO,BM_SETCHECK,
  1726.                   (MPARAM)1L, MPVOID);
  1727.  
  1728.                break;
  1729.  
  1730.             case ID_HELP:
  1731.  
  1732.                break;
  1733.  
  1734.          }   /* end switch (SHORT1FROMMP(mp1)) */
  1735.  
  1736.          return (MRESULT) TRUE;
  1737.  
  1738.       case WM_CONTROL:
  1739.       {
  1740.          ULONG temp;
  1741.  
  1742.          pDashDlgData = (PDASHDLGDATA)WinQueryWindowPtr(hwndDlg, QWL_USER);
  1743.          somThis = CarppGetData(pDashDlgData->somSelf);
  1744.  
  1745.          if (pDashDlgData == NULL)
  1746.          {
  1747.             DebugBox("DashboardDlgProc:WM_CONTROL", "couldn't get window words");
  1748.             break;
  1749.          }
  1750.  
  1751.          switch (SHORT1FROMMP(mp1))
  1752.          {
  1753.             case ID_GO:
  1754.                if ((USHORT) SHORT2FROMMP(mp1) == BN_CLICKED)
  1755.                {
  1756.                   pDashDlgData->PrevBrakes = somThis->carBrake->IsSet();
  1757.                   somThis->carBrake->Release();
  1758.                }
  1759.                break;
  1760.  
  1761.             case ID_STOP:
  1762.                if ((USHORT) SHORT2FROMMP(mp1) == BN_CLICKED)
  1763.                {
  1764.                   pDashDlgData->PrevBrakes = somThis->carBrake->IsSet();
  1765.                   somThis->carBrake->Set();
  1766.                }
  1767.                break;
  1768.  
  1769.             case ID_SPEEDSLIDER:
  1770.                if ((USHORT) SHORT2FROMMP(mp1) == SLN_CHANGE)
  1771.                {
  1772.                   pDashDlgData->PrevSpeed  = somThis->carRPM->Query();
  1773.                   temp = (ULONG) WinSendDlgItemMsg(hwndDlg, ID_SPEEDSLIDER,
  1774.                      SLM_QUERYSLIDERINFO,
  1775.                      MPFROM2SHORT(SMA_SLIDERARMPOSITION,SMA_INCREMENTVALUE),
  1776.                      NULL);
  1777.                   temp = temp * 10;
  1778.                   WinSetDlgItemText(hwndDlg,ID_SPEEDDATA,
  1779.                                    _ltoa(temp,acBuffer,10));
  1780.                   somThis->carRPM->Set( temp);
  1781.                }
  1782.                break;
  1783.  
  1784.          }   /* end switch (SHORT1FROMMP(mp1)) */
  1785.  
  1786.          return (MRESULT) TRUE;
  1787.          break;
  1788.  
  1789.       }   /* end case WM_CONTROL: */
  1790.  
  1791.    }   /* end switch (msg) */
  1792.  
  1793.    return (WinDefDlgProc(hwndDlg, msg, mp1, mp2) );
  1794.  
  1795. }   /* end DashBoardDlgProc() */
  1796.  
  1797. /******************************************************************************
  1798. *
  1799. *   HornBeepDlgProc()
  1800. *
  1801. *   DESCRIPTION:  Dialog Procedure for Horn Beep settings page
  1802. *
  1803. ******************************************************************************/
  1804. MRESULT EXPENTRY HornBeepDlgProc(HWND hwndDlg, ULONG msg,
  1805.                                   MPARAM mp1, MPARAM mp2)
  1806. {
  1807.  HORNDLGDATA * pHornDlgData;
  1808.  CarppData *somThis;
  1809.  CHAR acBuffer[10];
  1810.  
  1811.    switch (msg)
  1812.    {
  1813.       case WM_INITDLG:
  1814.       {
  1815.          /*
  1816.           *   Store some instance specific data in Window words of this dialog.
  1817.           *   This will ensure our dialog procedure can access this objects
  1818.           *   data (our dialog proc isn't always passed a *somSelf pointer).
  1819.           */
  1820.          pHornDlgData =
  1821.             (PHORNDLGDATA) (((Carpp *)mp2)->wpAllocMem(sizeof(*pHornDlgData), NULL));
  1822.          if (pHornDlgData)
  1823.          {
  1824.             memset((PVOID) pHornDlgData, 0, sizeof(*pHornDlgData));
  1825.             pHornDlgData->cb = sizeof(*pHornDlgData);
  1826.             pHornDlgData->somSelf = (Carpp *) mp2;  /* pointer to this object */
  1827.             somThis = CarppGetData(pHornDlgData->somSelf);
  1828.             pHornDlgData->PrevDuration = somThis->carHorn->QueryDuration();
  1829.             pHornDlgData->PrevHighTone = somThis->carHorn->QueryHighTone();
  1830.             pHornDlgData->PrevLowTone  = somThis->carHorn->QueryLowTone();
  1831.          }
  1832.          else
  1833.          {
  1834.             DebugBox("HornBeepDlgProc", "Couldn't allocate window words");
  1835.             break;
  1836.          }
  1837.  
  1838.          WinSetWindowPtr(hwndDlg, QWL_USER, pHornDlgData);
  1839.  
  1840.          WinSendDlgItemMsg( hwndDlg, ID_HITONE, SPBM_SETLIMITS,
  1841.             MPFROMLONG(1000), MPFROMLONG(0));
  1842.  
  1843.          WinSendDlgItemMsg( hwndDlg, ID_HITONE, SPBM_SETCURRENTVALUE,
  1844.             MPFROMLONG(pHornDlgData->PrevHighTone), MPFROMLONG(0));
  1845.  
  1846.          WinSendDlgItemMsg( hwndDlg, ID_LOTONE, SPBM_SETLIMITS,
  1847.             MPFROMLONG(1000), MPFROMLONG(0));
  1848.  
  1849.          WinSendDlgItemMsg( hwndDlg, ID_LOTONE, SPBM_SETCURRENTVALUE,
  1850.             MPFROMLONG(pHornDlgData->PrevLowTone), MPFROMLONG(0));
  1851.  
  1852.          return (MRESULT) TRUE;
  1853.          break;
  1854.  
  1855.       }   /* end case WM_INITDLG: */
  1856.  
  1857.       case WM_DESTROY:
  1858.  
  1859.          pHornDlgData = (PHORNDLGDATA) WinQueryWindowPtr(hwndDlg, QWL_USER);
  1860.  
  1861.          if (pHornDlgData == NULL)
  1862.          {
  1863.             DebugBox("HornBeepDlgProc", "Couldn't get window words");
  1864.             break;
  1865.          }
  1866.  
  1867.          pHornDlgData->somSelf->wpFreeMem((PBYTE)pHornDlgData);
  1868.          return (WinDefDlgProc(hwndDlg, msg, mp1, mp2) );
  1869.  
  1870.       case WM_COMMAND:
  1871.  
  1872.          pHornDlgData = (PHORNDLGDATA) WinQueryWindowPtr(hwndDlg, QWL_USER);
  1873.          somThis = CarppGetData(pHornDlgData->somSelf);
  1874.          if (pHornDlgData == NULL)
  1875.          {
  1876.             DebugBox("HornBeepDlgProc", "Couldn't get window words");
  1877.             break;
  1878.          }
  1879.  
  1880.          switch (SHORT1FROMMP(mp1))
  1881.          {
  1882.             case ID_UNDO:
  1883.  
  1884.                WinSendDlgItemMsg( hwndDlg, ID_HITONE, SPBM_SETCURRENTVALUE,
  1885.                   MPFROMLONG(pHornDlgData->PrevHighTone),
  1886.                   MPFROMLONG(0));
  1887.  
  1888.                WinSendDlgItemMsg( hwndDlg, ID_LOTONE, SPBM_SETCURRENTVALUE,
  1889.                   MPFROMLONG(pHornDlgData->PrevLowTone),
  1890.                   MPFROMLONG(0));
  1891.  
  1892.                break;
  1893.  
  1894.             case ID_DEFAULT:
  1895.                /*
  1896.                 *   preserve previous values
  1897.                 */
  1898.                pHornDlgData->PrevHighTone =
  1899.                   somThis->carHorn->QueryHighTone();
  1900.                pHornDlgData->PrevLowTone =
  1901.                   somThis->carHorn->QueryLowTone();
  1902.  
  1903.                somThis->carHorn->SetToDefault();
  1904.  
  1905.                WinSendDlgItemMsg( hwndDlg, ID_HITONE, SPBM_SETCURRENTVALUE,
  1906.                   MPFROMLONG(somThis->carHorn->QueryHighTone()), MPFROMLONG(0));
  1907.  
  1908.                WinSendDlgItemMsg( hwndDlg, ID_LOTONE, SPBM_SETCURRENTVALUE,
  1909.                   MPFROMLONG(somThis->carHorn->QueryLowTone()), MPFROMLONG(0));
  1910.                break;
  1911.  
  1912.             case ID_HELP:
  1913.                break;
  1914.  
  1915.          }   /* end switch (SHORT1FROMMP(mp1)) */
  1916.  
  1917.          return (MRESULT) TRUE;
  1918.          break;
  1919.  
  1920.       case WM_CONTROL:
  1921.       {
  1922.        ULONG temp;
  1923.  
  1924.          pHornDlgData = (PHORNDLGDATA) WinQueryWindowPtr(hwndDlg, QWL_USER);
  1925.          somThis = CarppGetData(pHornDlgData->somSelf);
  1926.  
  1927.          if (pHornDlgData == NULL)
  1928.          {
  1929.             DebugBox("HornBeepDlgProc", "Couldn't get window words");
  1930.             break;
  1931.          }
  1932.  
  1933.          switch (SHORT2FROMMP(mp1))
  1934.          {
  1935.             /************************************************************** */
  1936.             /* When the value of either of the tones change, set the new values in the */
  1937.             /* car object after saving the current settings for "undo" purposes             */
  1938.             /***************************************************************/
  1939.             case SPBN_ENDSPIN:
  1940.  
  1941.                /*
  1942.                 *   preserve previous values
  1943.                 */
  1944.                pHornDlgData->PrevHighTone =
  1945.                   somThis->carHorn->QueryHighTone();
  1946.                pHornDlgData->PrevLowTone =
  1947.                   somThis->carHorn->QueryLowTone();
  1948.  
  1949.                WinSendDlgItemMsg( hwndDlg, ID_HITONE, SPBM_QUERYVALUE,
  1950.                   (MPARAM)&temp, MPFROM2SHORT(0,SPBQ_UPDATEIFVALID));
  1951.  
  1952.                somThis->carHorn->SetHighTone( temp);
  1953.  
  1954.                WinSendDlgItemMsg( hwndDlg, ID_LOTONE, SPBM_QUERYVALUE,
  1955.                   (MPARAM)&temp, MPFROM2SHORT(0,SPBQ_UPDATEIFVALID));
  1956.  
  1957.                somThis->carHorn->SetLowTone( temp);
  1958.  
  1959.                break;
  1960.  
  1961.          }   /* end switch (SHORT2FROMMP(mp1)) */
  1962.  
  1963.       }   /* end case WM_CONTROL: */
  1964.  
  1965.       return (MRESULT) TRUE;
  1966.       break;
  1967.  
  1968.    }   /* end switch(msg) */
  1969.  
  1970.    return (WinDefDlgProc(hwndDlg, msg, mp1, mp2) );
  1971.  
  1972. }   /* end HornBeepDlgProc() */
  1973.  
  1974. /******************************************************************************
  1975. *
  1976. *   _Exception()
  1977. *
  1978. *   DESCRIPTION:  Exception handler routine for this object.
  1979. *
  1980. *   PURPOSE: To notify user when an illegal memory access is made
  1981. *
  1982. *   METHOD:  Whenever a memory protection exception occurs, a message
  1983. *            box is put on the screen to inform the user.
  1984. *
  1985. *   RETURNS: Returns HANDLED if memory exception,
  1986. *            otherwise, returns NOT_HANDLED
  1987. *
  1988. ******************************************************************************/
  1989. ULONG _Exception(EXCEPTIONREPORTRECORD       *parg,
  1990.                  EXCEPTIONREGISTRATIONRECORD *pRegisRecord,
  1991.                  PCONTEXTRECORD               pContextRecord,
  1992.                  PVOID                        pvSpare)
  1993. {
  1994.    LONG  rc;
  1995.    CHAR  szText[CCHMAXPATH];
  1996.  
  1997.    switch (parg->ExceptionNum)
  1998.    {
  1999.       case XCPT_ACCESS_VIOLATION:
  2000.  
  2001.          /*
  2002.           *   Notify the user when memory access violation occurs.
  2003.           */
  2004.          WinAlarm(HWND_DESKTOP, WA_ERROR);
  2005.          longjmp(jmpState, ERROR_PROTECTION_VIOLATION);
  2006.          break;
  2007.  
  2008.       case XCPT_PROCESS_TERMINATE:
  2009.       case XCPT_ASYNC_PROCESS_TERMINATE:
  2010.       case XCPT_SIGNAL:
  2011.       default:
  2012.          /*
  2013.           *   For more exceptions, see the header files or the programming
  2014.           *   reference(s).
  2015.           */
  2016.          break;
  2017.  
  2018.    }   /* end switch (parg->ExceptionNum) */
  2019.  
  2020.    return(XCPT_CONTINUE_SEARCH);
  2021.  
  2022. }   /* end _Exception() */
  2023.  
  2024. /********************************  END carpp.cpp  ********************************/
  2025.  
  2026.  
  2027.