home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v5.zip / TOOLKT21 / CPLUS / SAMPLES / WPCAR / CARPP.CPP < prev    next >
C/C++ Source or Header  |  1993-04-30  |  66KB  |  2,004 lines

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