home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 15 / CD_ASCQ_15_070894.iso / vrac / memsz231.zip / SUPPORT.CPP < prev    next >
Text File  |  1994-03-01  |  34KB  |  824 lines

  1. /***************************************************************** SUPPORT.CC
  2.  *                                                                          *
  3.  *                Presentation Manager Support Functions                    *
  4.  *                                                                          *
  5.  ****************************************************************************/
  6.  
  7. #define INCL_BASE
  8. #define INCL_PM
  9. #include <os2.h>
  10.  
  11. #include <stdarg.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15.  
  16. #include "support.h"
  17. #include "debug.h"
  18.  
  19.  
  20. /****************************************************************************
  21.  *                                                                          *
  22.  *      Definitions & Declarations                                          *
  23.  *                                                                          *
  24.  ****************************************************************************/
  25.  
  26.   // Local Function Prototypes
  27.  
  28. static ULONG BuildExtendedAttributeItem ( PFEA2 pFEA, PEADATA Item ) ;
  29.  
  30.  
  31. /****************************************************************************
  32.  *                                                                          *
  33.  *                        Message Dispatcher                                *
  34.  *                                                                          *
  35.  ****************************************************************************/
  36.  
  37. extern MRESULT DispatchMessage
  38. (
  39.   HWND    hwnd,
  40.   ULONG   msg,
  41.   MPARAM  mp1,
  42.   MPARAM  mp2,
  43.   PMETHOD MethodTable,
  44.   USHORT  MethodCount,
  45.   PFNWP   DefaultProcessor
  46. )
  47. {
  48.  /***************************************************************************
  49.   * Process messages according to object's class method table.              *
  50.   ***************************************************************************/
  51.  
  52.   PMETHOD pMethod = MethodTable ;
  53.   USHORT cNumberLeft = MethodCount ;
  54.  
  55.   while ( ( cNumberLeft ) AND ( pMethod->Action != msg ) ) {
  56.     pMethod ++ ;
  57.     cNumberLeft -- ;
  58.   }
  59.  
  60.   MRESULT mr ;
  61.  
  62.   if ( cNumberLeft ) {
  63.     mr = pMethod->pFunction ( hwnd, msg, mp1, mp2 ) ;
  64.   } else {
  65.     if ( DefaultProcessor )
  66.       mr = DefaultProcessor ( hwnd, msg, mp1, mp2 ) ;
  67.     else
  68.       mr = 0 ;
  69.   }
  70.  
  71.  /***************************************************************************
  72.   * Return result from message processor.                                   *
  73.   ***************************************************************************/
  74.  
  75.   return ( mr ) ;
  76. }
  77.  
  78. /****************************************************************************
  79.  *                                                                          *
  80.  *                         Add Item to System Menu                          *
  81.  *                                                                          *
  82.  ****************************************************************************/
  83.  
  84. extern VOID AddSysMenuItem ( HWND hwndFrame, MENUITEM *Item, PSZ Text ) {
  85.  
  86.  /***************************************************************************
  87.   * Obtain the system menu window handle.                                   *
  88.   ***************************************************************************/
  89.  
  90.   HWND hwndSysMenu = WinWindowFromID ( hwndFrame, FID_SYSMENU ) ;
  91.  
  92.  /***************************************************************************
  93.   * Get the system menu's base item and its window handle.                  *
  94.   ***************************************************************************/
  95.  
  96.   USHORT idSysMenu = SHORT1FROMMR ( WinSendMsg ( hwndSysMenu, MM_ITEMIDFROMPOSITION, NULL, NULL ) ) ;
  97.  
  98.   MENUITEM miSysMenu ;
  99.   WinSendMsg ( hwndSysMenu, MM_QUERYITEM,
  100.     MPFROM2SHORT(idSysMenu,FALSE), MPFROMP(&miSysMenu) ) ;
  101.  
  102.   HWND hwndSysSubMenu = miSysMenu.hwndSubMenu ;
  103.  
  104.  /***************************************************************************
  105.   * Add the new item to the system menu's submenu, which is what we see.    *
  106.   ***************************************************************************/
  107.  
  108.   WinSendMsg ( hwndSysSubMenu, MM_INSERTITEM, MPFROMP(Item), MPFROMP(Text) ) ;
  109. }
  110.  
  111. /****************************************************************************
  112.  *                                                                          *
  113.  *                   Add Item to Submenu on System Menu                     *
  114.  *                                                                          *
  115.  ****************************************************************************/
  116.  
  117. extern VOID AddSysSubMenuItem
  118. (
  119.   HWND hwndFrame,
  120.   USHORT SubMenuID,
  121.   MENUITEM *Item,
  122.   PSZ Text
  123. )
  124. {
  125.  /***************************************************************************
  126.   * Obtain the system menu window handle.                                   *
  127.   ***************************************************************************/
  128.  
  129.   HWND hwndSysMenu = WinWindowFromID ( hwndFrame, FID_SYSMENU ) ;
  130.  
  131.  /***************************************************************************
  132.   * Get the system menu's base item and its window handle.                  *
  133.   ***************************************************************************/
  134.  
  135.   USHORT idSysMenu = SHORT1FROMMR ( WinSendMsg ( hwndSysMenu, MM_ITEMIDFROMPOSITION, NULL, NULL ) ) ;
  136.  
  137.   MENUITEM MenuItem ;
  138.   WinSendMsg ( hwndSysMenu, MM_QUERYITEM,
  139.     MPFROM2SHORT(idSysMenu,FALSE), MPFROMP(&MenuItem) ) ;
  140.  
  141.   HWND hwndSysSubMenu = MenuItem.hwndSubMenu ;
  142.  
  143.  /***************************************************************************
  144.   * Get the submenu's base item and its window handle.                      *
  145.   ***************************************************************************/
  146.  
  147.   WinSendMsg ( hwndSysSubMenu, MM_QUERYITEM,
  148.     MPFROM2SHORT ( SubMenuID, TRUE ),
  149.     (MPARAM) &MenuItem ) ;
  150.  
  151.   HWND hwndSubMenu = MenuItem.hwndSubMenu ;
  152.  
  153.  /***************************************************************************
  154.   * Add the new item to the system menu's submenu, which is what we see.    *
  155.   ***************************************************************************/
  156.  
  157.   WinSendMsg ( hwndSubMenu, MM_INSERTITEM, MPFROMP(Item), MPFROMP(Text) ) ;
  158. }
  159.  
  160. /****************************************************************************
  161.  *                                                                          *
  162.  *                           Add Item to Menu                               *
  163.  *                                                                          *
  164.  ****************************************************************************/
  165.  
  166. extern VOID AddMenuItem
  167. (
  168.   HWND hwndFrame,
  169.   USHORT MenuID,
  170.   MENUITEM *Item,
  171.   PSZ Text
  172. )
  173. {
  174.  /***************************************************************************
  175.   * Obtain the menu window handle.                                          *
  176.   ***************************************************************************/
  177.  
  178.   HWND hwndMenu = WinWindowFromID ( hwndFrame, MenuID ) ;
  179.  
  180.  /***************************************************************************
  181.   * Add the new item to the menu.                                           *
  182.   ***************************************************************************/
  183.  
  184.   WinSendMsg ( hwndMenu, MM_INSERTITEM, MPFROMP(Item), MPFROMP(Text) ) ;
  185. }
  186.  
  187. /****************************************************************************
  188.  *                                                                          *
  189.  *                        Add Item to SubMenu                               *
  190.  *                                                                          *
  191.  ****************************************************************************/
  192.  
  193. extern VOID AddSubMenuItem
  194. (
  195.   HWND hwndFrame,
  196.   USHORT MenuID,
  197.   USHORT SubMenuID,
  198.   MENUITEM *Item,
  199.   PSZ Text
  200. )
  201. {
  202.  /***************************************************************************
  203.   * Obtain the menu window handle.                                          *
  204.   ***************************************************************************/
  205.  
  206.   HWND hwndMenu = WinWindowFromID ( hwndFrame, MenuID ) ;
  207.  
  208.  /***************************************************************************
  209.   * Obtain the submenu window handle.                                       *
  210.   ***************************************************************************/
  211.  
  212.   MENUITEM MenuItem ;
  213.   WinSendMsg ( hwndMenu, MM_QUERYITEM,
  214.     MPFROM2SHORT ( SubMenuID, TRUE ),
  215.     (MPARAM) &MenuItem ) ;
  216.  
  217.   HWND hwndSubMenu = MenuItem.hwndSubMenu ;
  218.  
  219.  /***************************************************************************
  220.   * Add the new item to the menu.                                           *
  221.   ***************************************************************************/
  222.  
  223.   WinSendMsg ( hwndSubMenu, MM_INSERTITEM, MPFROMP(Item), MPFROMP(Text) ) ;
  224. }
  225.  
  226. /****************************************************************************
  227.  *                                                                          *
  228.  *                       Remove Item from SubMenu                           *
  229.  *                                                                          *
  230.  ****************************************************************************/
  231.  
  232. extern VOID RemoveSubMenuItem
  233. (
  234.   HWND hwndFrame,
  235.   USHORT MenuID,
  236.   USHORT SubMenuID,
  237.   USHORT ItemID
  238. )
  239. {
  240.  /***************************************************************************
  241.   * Obtain the menu window handle.                                          *
  242.   ***************************************************************************/
  243.  
  244.   HWND hwndMenu = WinWindowFromID ( hwndFrame, MenuID ) ;
  245.  
  246.  /***************************************************************************
  247.   * Obtain the submenu window handle.                                       *
  248.   ***************************************************************************/
  249.  
  250.   MENUITEM MenuItem ;
  251.   WinSendMsg ( hwndMenu, MM_QUERYITEM,
  252.     MPFROM2SHORT ( SubMenuID, TRUE ),
  253.     (MPARAM) &MenuItem ) ;
  254.  
  255.   HWND hwndSubMenu = MenuItem.hwndSubMenu ;
  256.  
  257.  /***************************************************************************
  258.   * Remove the item from the menu.                                          *
  259.   ***************************************************************************/
  260.  
  261.   WinSendMsg ( hwndSubMenu, MM_REMOVEITEM, MPFROM2SHORT(ItemID,TRUE), 0 ) ;
  262. }
  263.  
  264. /****************************************************************************
  265.  *                                                                          *
  266.  *      Enable/Disable menu item.                                           *
  267.  *                                                                          *
  268.  ****************************************************************************/
  269.  
  270. extern VOID EnableMenuItem ( HWND hwndFrame, USHORT MenuID, USHORT ItemID, BOOL Enable ) {
  271.  
  272.  /***************************************************************************
  273.   * Get the menu's window handle.                                           *
  274.   ***************************************************************************/
  275.  
  276.   HWND hwndMenu = WinWindowFromID ( hwndFrame, MenuID ) ;
  277.  
  278.  /***************************************************************************
  279.   * Set the menu item's enable/disable status.                              *
  280.   ***************************************************************************/
  281.  
  282.   WinSendMsg ( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT ( ItemID, TRUE ),
  283.     MPFROM2SHORT ( MIA_DISABLED, Enable ? 0 : MIA_DISABLED ) ) ;
  284. }
  285.  
  286. /****************************************************************************
  287.  *                                                                          *
  288.  *      Check/Uncheck menu item.                                            *
  289.  *                                                                          *
  290.  ****************************************************************************/
  291.  
  292. extern VOID CheckMenuItem ( HWND hwndFrame, USHORT MenuID, USHORT ItemID, BOOL Enable ) {
  293.  
  294.  /***************************************************************************
  295.   * Get the menu's window handle.                                           *
  296.   ***************************************************************************/
  297.  
  298.   HWND hwndMenu = WinWindowFromID ( hwndFrame, MenuID ) ;
  299.  
  300.  /***************************************************************************
  301.   * Set the menu item's enable/disable status.                              *
  302.   ***************************************************************************/
  303.  
  304.   WinSendMsg ( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT ( ItemID, TRUE ),
  305.     MPFROM2SHORT ( MIA_CHECKED, Enable ? MIA_CHECKED : 0 ) ) ;
  306. }
  307.  
  308. /****************************************************************************
  309.  *                                                                          *
  310.  *                        Add Program to Task List                          *
  311.  *                                                                          *
  312.  ****************************************************************************/
  313.  
  314. extern VOID Add2TaskList ( HWND hwnd, PSZ Name ) {
  315.  
  316.  /***************************************************************************
  317.   * Get the window's process ID.                                            *
  318.   ***************************************************************************/
  319.  
  320.   PID pid ;
  321.   WinQueryWindowProcess ( hwnd, &pid, PTID(NULL) ) ;
  322.  
  323.  /***************************************************************************
  324.   * Add an entry to the system task list.                                   *
  325.   ***************************************************************************/
  326.  
  327.   SWCNTRL swctl ;
  328.   swctl.hwnd = hwnd ;
  329.   swctl.hwndIcon = 0 ;
  330.   swctl.hprog = 0 ;
  331.   swctl.idProcess = pid ;
  332.   swctl.idSession = 0 ;
  333.   swctl.uchVisibility = SWL_VISIBLE ;
  334.   swctl.fbJump = SWL_JUMPABLE ;
  335.   strcpy ( swctl.szSwtitle, (PCHAR)Name ) ;
  336.  
  337.   WinAddSwitchEntry ( &swctl ) ;
  338. }
  339.  
  340. /****************************************************************************
  341.  *                                                                          *
  342.  *  Build Presentation Parameters                                           *
  343.  *                                                                          *
  344.  ****************************************************************************/
  345.  
  346. extern PPRESPARAMS BuildPresParams
  347. (
  348.   USHORT ParmCount,
  349.   PULONG Ids,
  350.   PULONG ByteCounts,
  351.   PBYTE *Parms
  352. )
  353. {
  354.  /***************************************************************************
  355.   * Determine final size of presentation parameter block.                   *
  356.   ***************************************************************************/
  357.  
  358.   ULONG Size = sizeof(ULONG) ;
  359.  
  360.   for ( int i=0; i<ParmCount; i++ ) {
  361.     Size += sizeof(ULONG) ;
  362.     Size += sizeof(ULONG) ;
  363.     Size += ByteCounts[i] ;
  364.   }
  365.  
  366.  /***************************************************************************
  367.   * Allocate memory for block.  Return if unable to do so.                  *
  368.   ***************************************************************************/
  369.  
  370.   PPRESPARAMS PresParams = (PPRESPARAMS) AllocateMemory ( (USHORT) Size ) ;
  371.  
  372.   if ( PresParams == NULL )
  373.     return ( PresParams ) ;
  374.  
  375.  /***************************************************************************
  376.   * Initialize the block header.                                            *
  377.   ***************************************************************************/
  378.  
  379.   PresParams->cb = Size - sizeof(PresParams->cb) ;
  380.  
  381.  /***************************************************************************
  382.   * Load the presentation parameters into the block.                        *
  383.   ***************************************************************************/
  384.  
  385.   PPARAM Param = PresParams->aparam ;
  386.  
  387.   for ( i=0; i<ParmCount; i++ ) {
  388.     Param->id = Ids[i] ;
  389.     Param->cb = ByteCounts[i] ;
  390.     memcpy ( Param->ab, Parms[i], (USHORT)ByteCounts[i] ) ;
  391.     PBYTE p = PBYTE ( Param ) ;
  392.     p += sizeof(Param->id) ;
  393.     p += sizeof(Param->cb) ;
  394.     p += ByteCounts[i] ;
  395.     Param = PPARAM ( p ) ;
  396.   }
  397.  
  398.  /***************************************************************************
  399.   * Return the pointer to the block.  It will need freeing by the caller.   *
  400.   ***************************************************************************/
  401.  
  402.   return ( PresParams ) ;
  403. }
  404.  
  405. /****************************************************************************
  406.  *                                                                          *
  407.  *      Build Extended Attributes                                           *
  408.  *                                                                          *
  409.  ****************************************************************************/
  410.  
  411. extern PEAOP2 BuildExtendedAttributes ( ULONG Count, EADATA Table[] ) {
  412.  
  413.  /***************************************************************************
  414.   * Find out how much memory will be needed for the block.                  *
  415.   ***************************************************************************/
  416.  
  417.   ULONG cbEA = sizeof(FEA2LIST) - sizeof(FEA2) ;
  418.  
  419.   for ( int i=0; i<Count; i++ ) {
  420.     cbEA += BuildExtendedAttributeItem ( PFEA2(NULL), &Table[i] ) ;
  421.     while ( cbEA % 4 ) {
  422.       cbEA ++ ;
  423.     }
  424.   }
  425.  
  426.  /***************************************************************************
  427.   * Allocate memory for the FEA2 list.                                      *
  428.   ***************************************************************************/
  429.  
  430.   PFEA2LIST pFEAList = PFEA2LIST ( AllocateMemory ( cbEA ) ) ;
  431.  
  432.   if ( pFEAList == NULL ) {
  433.     return ( PEAOP2(NULL) ) ;
  434.   }
  435.  
  436.  /***************************************************************************
  437.   * Construct the extended attributes.                                      *
  438.   ***************************************************************************/
  439.  
  440.   PFEA2 pFEA = pFEAList->list ;
  441.  
  442.   for ( i=0; i<Count; i++ ) {
  443.     PFEA2 Start = PFEA2 ( pFEA ) ;
  444.     PBYTE p = PBYTE(pFEA) + BuildExtendedAttributeItem ( pFEA, &Table[i] ) ;
  445.     pFEA = PFEA2 ( p ) ;
  446.     while ( (PBYTE(pFEA)-PBYTE(pFEAList->list)) % 4 ) {
  447.       PBYTE p = PBYTE ( pFEA ) + 1 ;
  448.       pFEA = PFEA2 ( p ) ;
  449.     }
  450.     if ( i < Count-1 )
  451.       Start->oNextEntryOffset = PBYTE(pFEA) - PBYTE(Start) ;
  452.     else
  453.       Start->oNextEntryOffset = 0 ;
  454.   }
  455.  
  456.   pFEAList->cbList = PBYTE(pFEA) - PBYTE(pFEAList) ;
  457.  
  458.  /***************************************************************************
  459.   * Allocate memory for the EA header block.                                *
  460.   ***************************************************************************/
  461.  
  462.   PEAOP2 pExtendedAttributes = PEAOP2 ( AllocateMemory ( sizeof(EAOP2) ) ) ;
  463.  
  464.   if ( pExtendedAttributes == NULL ) {
  465.     FreeMemory ( pFEAList ) ;
  466.     return ( PEAOP2(NULL) ) ;
  467.   }
  468.  
  469.  /***************************************************************************
  470.   * Fill in the extended attribute header block and return its address.     *
  471.   ***************************************************************************/
  472.  
  473.   pExtendedAttributes->fpGEA2List = PGEA2LIST(NULL) ;
  474.   pExtendedAttributes->fpFEA2List = pFEAList ;
  475.   pExtendedAttributes->oError = 0 ;
  476.  
  477.   return ( pExtendedAttributes ) ;
  478. }
  479.  
  480. /****************************************************************************
  481.  *                                                                          *
  482.  *      Build Extended Attribute Item                                       *
  483.  *                                                                          *
  484.  ****************************************************************************/
  485.  
  486. static ULONG BuildExtendedAttributeItem ( PFEA2 pFEA, PEADATA Item ) {
  487.  
  488.  /***************************************************************************
  489.   * Store next entry's offset (set to zero at this point).                  *
  490.   ***************************************************************************/
  491.  
  492.   PBYTE p = PBYTE ( pFEA ) ;
  493.  
  494.   if ( pFEA ) {
  495.     *(PULONG(p)) = 0 ;
  496.   }
  497.  
  498.   p += sizeof(ULONG) ;
  499.  
  500.  /***************************************************************************
  501.   * Store flag byte.                                                        *
  502.   ***************************************************************************/
  503.  
  504.   if ( pFEA ) {
  505.     *p = 0 ;
  506.   }
  507.  
  508.   p ++ ;
  509.  
  510.  /***************************************************************************
  511.   * Store count of bytes in name.                                           *
  512.   ***************************************************************************/
  513.  
  514.   if ( pFEA ) {
  515.     *p = BYTE ( strlen ( PCHAR(Item->Name) ) ) ;
  516.   }
  517.  
  518.   p ++ ;
  519.  
  520.  /***************************************************************************
  521.   * Store count of bytes in value.                                          *
  522.   ***************************************************************************/
  523.  
  524.   if ( pFEA ) {
  525.     *(PUSHORT(p)) = Item->Length + 2 * sizeof(USHORT) ;
  526.   }
  527.  
  528.   p += sizeof(USHORT) ;
  529.  
  530.  /***************************************************************************
  531.   * Store name.                                                             *
  532.   ***************************************************************************/
  533.  
  534.   if ( pFEA ) {
  535.     strcpy ( PCHAR(p), PCHAR(Item->Name) ) ;
  536.   }
  537.  
  538.   p += strlen ( PCHAR(Item->Name) ) + 1 ;
  539.  
  540.  /***************************************************************************
  541.   * Store value's type.                                                     *
  542.   ***************************************************************************/
  543.  
  544.   if ( pFEA ) {
  545.     *(PUSHORT(p)) = Item->Type ;
  546.   }
  547.  
  548.   p += sizeof(USHORT) ;
  549.  
  550.  /***************************************************************************
  551.   * Store value's length.                                                   *
  552.   ***************************************************************************/
  553.  
  554.   if ( pFEA ) {
  555.     *(PUSHORT(p)) = Item->Length ;
  556.   }
  557.  
  558.   p += sizeof(USHORT) ;
  559.  
  560.  /***************************************************************************
  561.   * Store value.                                                            *
  562.   ***************************************************************************/
  563.  
  564.   if ( pFEA ) {
  565.     memcpy ( p, Item->Value, Item->Length ) ;
  566.   }
  567.  
  568.   p += Item->Length ;
  569.  
  570.  /***************************************************************************
  571.   * Return count of bytes needed for item.                                  *
  572.   ***************************************************************************/
  573.  
  574.   return ( p - PBYTE(pFEA) ) ;
  575. }
  576.  
  577. /****************************************************************************
  578.  *                                                                          *
  579.  *      Build Multi-Value Multi-Type EA Item's Value                        *
  580.  *                                                                          *
  581.  ****************************************************************************/
  582.  
  583. extern ULONG BuildMVMTValue ( PVOID Value, ULONG Count, MVMT_VALUE Table[] ) {
  584.  
  585.  /***************************************************************************
  586.   * Store the number of values.                                             *
  587.   ***************************************************************************/
  588.  
  589.   PBYTE p = PBYTE ( Value ) ;
  590.  
  591.   if ( Value )
  592.     *(PUSHORT(p)) = Count ;
  593.  
  594.   p += sizeof(USHORT) ;
  595.  
  596.  /***************************************************************************
  597.   * Store the multiple values.                                              *
  598.   ***************************************************************************/
  599.  
  600.   for ( int i=0; i<Count; i++ ) {
  601.  
  602.     if ( Value )
  603.       *(PUSHORT(p)) = Table[i].Type ;
  604.  
  605.     p += sizeof(USHORT) ;
  606.  
  607.     if ( Value )
  608.       *(PUSHORT(p)) = Table[i].Length ;
  609.  
  610.     p += sizeof(USHORT) ;
  611.  
  612.     if ( Value )
  613.       memcpy ( p, Table[i].Value, Table[i].Length ) ;
  614.  
  615.     p += Table[i].Length ;
  616.   }
  617.  
  618.  /***************************************************************************
  619.   * Return the total byte count.                                            *
  620.   ***************************************************************************/
  621.  
  622.   return ( p - PBYTE(Value) ) ;
  623. }
  624.  
  625. /****************************************************************************
  626.  *                                                                          *
  627.  *      Process Exit menu command.                                          *
  628.  *                                                                          *
  629.  ****************************************************************************/
  630.  
  631. extern MRESULT APIENTRY Exit ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  632.  
  633.  /***************************************************************************
  634.   * Send a WM_CLOSE message to the window.                                  *
  635.   ***************************************************************************/
  636.  
  637.   WinSendMsg ( hwnd, WM_CLOSE, 0L, 0L ) ;
  638.  
  639.  /***************************************************************************
  640.   * Done.                                                                   *
  641.   ***************************************************************************/
  642.  
  643.   return ( MRFROMSHORT ( 0 ) ) ;
  644. }
  645.  
  646. /****************************************************************************
  647.  *                                                                          *
  648.  *      Process Help For Help menu command.                                 *
  649.  *                                                                          *
  650.  ****************************************************************************/
  651.  
  652. extern MRESULT APIENTRY HelpForHelp ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  653.  
  654.  /***************************************************************************
  655.   * Get the help instance window handle, if any.                            *
  656.   ***************************************************************************/
  657.  
  658.   HWND hwndHelp = WinQueryHelpInstance ( hwnd ) ;
  659.  
  660.  /***************************************************************************
  661.   * If help is available, pass the request on to the help window.           *
  662.   ***************************************************************************/
  663.  
  664.   if ( hwndHelp ) {
  665.     WinSendMsg ( hwndHelp, HM_DISPLAY_HELP, 0L, 0L ) ;
  666.   }
  667.  
  668.  /***************************************************************************
  669.   * Done.                                                                   *
  670.   ***************************************************************************/
  671.  
  672.   return ( MRFROMSHORT ( 0 ) ) ;
  673. }
  674.  
  675. /****************************************************************************
  676.  *                                                                          *
  677.  *      Process Extended Help menu command.                                 *
  678.  *                                                                          *
  679.  ****************************************************************************/
  680.  
  681. extern MRESULT APIENTRY ExtendedHelp ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  682.  
  683.  /***************************************************************************
  684.   * Get the help instance window handle, if any.                            *
  685.   ***************************************************************************/
  686.  
  687.   HWND hwndHelp = WinQueryHelpInstance ( hwnd ) ;
  688.  
  689.  /***************************************************************************
  690.   * If help is available, pass the request on to the help window.           *
  691.   ***************************************************************************/
  692.  
  693.   if ( hwndHelp ) {
  694.     WinSendMsg ( hwndHelp, HM_EXT_HELP, 0L, 0L ) ;
  695.   }
  696.  
  697.  /***************************************************************************
  698.   * Done.                                                                   *
  699.   ***************************************************************************/
  700.  
  701.   return ( MRFROMSHORT ( 0 ) ) ;
  702. }
  703.  
  704. /****************************************************************************
  705.  *                                                                          *
  706.  *      Process Keys Help menu command.                                     *
  707.  *                                                                          *
  708.  ****************************************************************************/
  709.  
  710. extern MRESULT APIENTRY KeysHelp ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  711.  
  712.  /***************************************************************************
  713.   * Get the help instance window handle, if any.                            *
  714.   ***************************************************************************/
  715.  
  716.   HWND hwndHelp = WinQueryHelpInstance ( hwnd ) ;
  717.  
  718.  /***************************************************************************
  719.   * If help is available, pass the request on to the help window.           *
  720.   ***************************************************************************/
  721.  
  722.   if ( hwndHelp ) {
  723.     WinSendMsg ( hwndHelp, HM_KEYS_HELP, 0L, 0L ) ;
  724.   }
  725.  
  726.  /***************************************************************************
  727.   * Done.                                                                   *
  728.   ***************************************************************************/
  729.  
  730.   return ( MRFROMSHORT ( 0 ) ) ;
  731. }
  732.  
  733. /****************************************************************************
  734.  *                                                                          *
  735.  *      Process Help Index menu command.                                    *
  736.  *                                                                          *
  737.  ****************************************************************************/
  738.  
  739. extern MRESULT APIENTRY HelpIndex ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  740.  
  741.  /***************************************************************************
  742.   * Get the help instance window handle, if any.                            *
  743.   ***************************************************************************/
  744.  
  745.   HWND hwndHelp = WinQueryHelpInstance ( hwnd ) ;
  746.  
  747.  /***************************************************************************
  748.   * If help is available, pass the request on to the help window.           *
  749.   ***************************************************************************/
  750.  
  751.   if ( hwndHelp ) {
  752.     WinSendMsg ( hwndHelp, HM_HELP_INDEX, 0L, 0L ) ;
  753.   }
  754.  
  755.  /***************************************************************************
  756.   * Done.                                                                   *
  757.   ***************************************************************************/
  758.  
  759.   return ( MRFROMSHORT ( 0 ) ) ;
  760. }
  761.  
  762. /****************************************************************************
  763.  *                                                                          *
  764.  *      Copy Bitmap                                                         *
  765.  *                                                                          *
  766.  ****************************************************************************/
  767.  
  768. extern HBITMAP CopyBitmap ( HAB Anchor, HBITMAP Original ) {
  769.  
  770.    HBITMAP Copy = 0 ;
  771.    BITMAPINFOHEADER2 Header ;
  772.    Header.cbFix = 16 ;
  773.    GpiQueryBitmapInfoHeader ( Original, &Header ) ;
  774.    PSZ DeviceData [] = { PSZ(NULL), PSZ("Display"), PSZ(NULL), PSZ(NULL) } ;
  775.    HDC hdcMemory1 = DevOpenDC  ( Anchor, OD_MEMORY, PSZ("*"), 4, DeviceData, 0 ) ;
  776.    if ( hdcMemory1 ) {
  777.       HDC hdcMemory2 = DevOpenDC  ( Anchor, OD_MEMORY, PSZ("*"), 4, DeviceData, 0 ) ;
  778.       if ( hdcMemory2 ) {
  779.          SIZEL PageSize ;
  780.          PageSize.cx = Header.cx ;
  781.          PageSize.cy = Header.cy ;
  782.          HPS hpsMemory1 = GpiCreatePS ( Anchor, hdcMemory1, &PageSize, GPIA_ASSOC | PU_PELS ) ;
  783.          if ( hpsMemory1 ) {
  784.             HPS hpsMemory2 = GpiCreatePS ( Anchor, hdcMemory2, &PageSize, GPIA_ASSOC | PU_PELS ) ;
  785.             if ( hpsMemory2 ) {
  786.                Copy = GpiCreateBitmap ( hpsMemory2, &Header, FALSE, 0, 0 ) ;
  787.                if ( Copy ) {
  788.                   GpiSetBitmap ( hpsMemory1, Original ) ;
  789.                   GpiSetBitmap ( hpsMemory2, Copy ) ;
  790.                   POINTL Points [4] ;
  791.                   Points[0].x = Points[0].y = Points[2].x = Points[2].y = 0 ;
  792.                   Points[1].x = Points[3].x = Header.cx ;
  793.                   Points[1].y = Points[3].y = Header.cy ;
  794.                   GpiBitBlt ( hpsMemory2, hpsMemory1, 4L, Points, ROP_SRCCOPY, BBO_IGNORE ) ;
  795.                   GpiSetBitmap ( hpsMemory1, 0 ) ;
  796.                   GpiSetBitmap ( hpsMemory2, 0 ) ;
  797.                } else {
  798.                   ERRORID Error = WinGetLastError ( Anchor ) ;
  799.                   Log ( "CopyBitmap: ERROR: Unable to create bitmap.  Status %i.", Error ) ;
  800.                } /* endif */
  801.                GpiDestroyPS ( hpsMemory2 ) ;
  802.             } else {
  803.                ERRORID Error = WinGetLastError ( Anchor ) ;
  804.                Log ( "CopyBitmap: ERROR: Unable to open second memory presentation space.  Status %i.", Error ) ;
  805.             } /* endif */
  806.             GpiDestroyPS ( hpsMemory1 ) ;
  807.          } else {
  808.             ERRORID Error = WinGetLastError ( Anchor ) ;
  809.             Log ( "CopyBitmap: ERROR: Unable to open first memory presentation space.  Status %i.", Error ) ;
  810.          } /* endif */
  811.          DevCloseDC ( hdcMemory2 ) ;
  812.       } else {
  813.          ERRORID Error = WinGetLastError ( Anchor ) ;
  814.          Log ( "CopyBitmap: ERROR: Unable to open second memory device context.  Status %i.", Error ) ;
  815.       } /* endif */
  816.       DevCloseDC ( hdcMemory1 ) ;
  817.    } else {
  818.       ERRORID Error = WinGetLastError ( Anchor ) ;
  819.       Log ( "CopyBitmap: ERROR: Unable to open first memory device context.  Status %i.", Error ) ;
  820.    } /* endif */
  821.  
  822.    return ( Copy ) ;
  823. }
  824.