home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / memsz331.zip / Source.zip / SUPPORT.CPP < prev    next >
Text File  |  1995-12-23  |  35KB  |  843 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 Frame, USHORT MenuID, USHORT ItemID, BOOL Enable ) {
  271.    EnableMenuItem ( WinWindowFromID(Frame,MenuID), ItemID, Enable ) ;
  272. }
  273.  
  274. extern VOID EnableMenuItem ( HWND Menu, USHORT ItemID, BOOL Enable ) {
  275.    WinSendMsg ( Menu, MM_SETITEMATTR, MPFROM2SHORT(ItemID,TRUE), MPFROM2SHORT(MIA_DISABLED,Enable?0:MIA_DISABLED) ) ;
  276. }
  277.  
  278. /****************************************************************************
  279.  *                                                                          *
  280.  *      Check/Uncheck menu item.                                            *
  281.  *                                                                          *
  282.  ****************************************************************************/
  283.  
  284. extern VOID CheckMenuItem ( HWND Frame, USHORT MenuID, USHORT ItemID, BOOL Check ) {
  285.    CheckMenuItem ( WinWindowFromID(Frame,MenuID), ItemID, Check ) ;
  286. }
  287.  
  288. extern VOID CheckMenuItem ( HWND Menu, USHORT ItemID, BOOL Check ) {
  289.    WinSendMsg ( Menu, MM_SETITEMATTR, MPFROM2SHORT(ItemID,TRUE), MPFROM2SHORT(MIA_CHECKED,Check?MIA_CHECKED:0) ) ;
  290. }
  291.  
  292. /****************************************************************************
  293.  *                                                                          *
  294.  *                        Add Program to Task List                          *
  295.  *                                                                          *
  296.  ****************************************************************************/
  297.  
  298. extern VOID Add2TaskList ( HWND hwnd, PSZ Name ) {
  299.  
  300.  /***************************************************************************
  301.   * Get the window's process ID.                                            *
  302.   ***************************************************************************/
  303.  
  304.   PID pid ;
  305.   WinQueryWindowProcess ( hwnd, &pid, PTID(NULL) ) ;
  306.  
  307.  /***************************************************************************
  308.   * Add an entry to the system task list.                                   *
  309.   ***************************************************************************/
  310.  
  311.   SWCNTRL swctl ;
  312.   swctl.hwnd = hwnd ;
  313.   swctl.hwndIcon = 0 ;
  314.   swctl.hprog = 0 ;
  315.   swctl.idProcess = pid ;
  316.   swctl.idSession = 0 ;
  317.   swctl.uchVisibility = SWL_VISIBLE ;
  318.   swctl.fbJump = SWL_JUMPABLE ;
  319.   strcpy ( swctl.szSwtitle, (PCHAR)Name ) ;
  320.  
  321.   WinAddSwitchEntry ( &swctl ) ;
  322. }
  323.  
  324. /****************************************************************************
  325.  *                                                                          *
  326.  *  Build Presentation Parameters                                           *
  327.  *                                                                          *
  328.  ****************************************************************************/
  329.  
  330. extern PPRESPARAMS BuildPresParams
  331. (
  332.   USHORT ParmCount,
  333.   PULONG Ids,
  334.   PULONG ByteCounts,
  335.   PBYTE *Parms
  336. )
  337. {
  338.  /***************************************************************************
  339.   * Determine final size of presentation parameter block.                   *
  340.   ***************************************************************************/
  341.  
  342.   ULONG Size = sizeof(ULONG) ;
  343.  
  344.   for ( int i=0; i<ParmCount; i++ ) {
  345.     Size += sizeof(ULONG) ;
  346.     Size += sizeof(ULONG) ;
  347.     Size += ByteCounts[i] ;
  348.   }
  349.  
  350.  /***************************************************************************
  351.   * Allocate memory for block.  Return if unable to do so.                  *
  352.   ***************************************************************************/
  353.  
  354.   PPRESPARAMS PresParams = (PPRESPARAMS) AllocateMemory ( (USHORT) Size ) ;
  355.  
  356.   if ( PresParams == NULL )
  357.     return ( PresParams ) ;
  358.  
  359.  /***************************************************************************
  360.   * Initialize the block header.                                            *
  361.   ***************************************************************************/
  362.  
  363.   PresParams->cb = Size - sizeof(PresParams->cb) ;
  364.  
  365.  /***************************************************************************
  366.   * Load the presentation parameters into the block.                        *
  367.   ***************************************************************************/
  368.  
  369.   PPARAM Param = PresParams->aparam ;
  370.  
  371.   for ( i=0; i<ParmCount; i++ ) {
  372.     Param->id = Ids[i] ;
  373.     Param->cb = ByteCounts[i] ;
  374.     memcpy ( Param->ab, Parms[i], (USHORT)ByteCounts[i] ) ;
  375.     PBYTE p = PBYTE ( Param ) ;
  376.     p += sizeof(Param->id) ;
  377.     p += sizeof(Param->cb) ;
  378.     p += ByteCounts[i] ;
  379.     Param = PPARAM ( p ) ;
  380.   }
  381.  
  382.  /***************************************************************************
  383.   * Return the pointer to the block.  It will need freeing by the caller.   *
  384.   ***************************************************************************/
  385.  
  386.   return ( PresParams ) ;
  387. }
  388.  
  389. /****************************************************************************
  390.  *                                                                          *
  391.  *      Build Extended Attributes                                           *
  392.  *                                                                          *
  393.  ****************************************************************************/
  394.  
  395. extern PEAOP2 BuildExtendedAttributes ( ULONG Count, EADATA Table[] ) {
  396.  
  397.  /***************************************************************************
  398.   * Find out how much memory will be needed for the block.                  *
  399.   ***************************************************************************/
  400.  
  401.   ULONG cbEA = sizeof(FEA2LIST) - sizeof(FEA2) ;
  402.  
  403.   for ( int i=0; i<Count; i++ ) {
  404.     cbEA += BuildExtendedAttributeItem ( PFEA2(NULL), &Table[i] ) ;
  405.     while ( cbEA % 4 ) {
  406.       cbEA ++ ;
  407.     }
  408.   }
  409.  
  410.  /***************************************************************************
  411.   * Allocate memory for the FEA2 list.                                      *
  412.   ***************************************************************************/
  413.  
  414.   PFEA2LIST pFEAList = PFEA2LIST ( AllocateMemory ( size_t(cbEA) ) ) ;
  415.  
  416.   if ( pFEAList == NULL ) {
  417.     return ( PEAOP2(NULL) ) ;
  418.   }
  419.  
  420.  /***************************************************************************
  421.   * Construct the extended attributes.                                      *
  422.   ***************************************************************************/
  423.  
  424.   PFEA2 pFEA = pFEAList->list ;
  425.  
  426.   for ( i=0; i<Count; i++ ) {
  427.     PFEA2 Start = PFEA2 ( pFEA ) ;
  428.     PBYTE p = PBYTE(pFEA) + BuildExtendedAttributeItem ( pFEA, &Table[i] ) ;
  429.     pFEA = PFEA2 ( p ) ;
  430.     while ( (PBYTE(pFEA)-PBYTE(pFEAList->list)) % 4 ) {
  431.       PBYTE p = PBYTE ( pFEA ) + 1 ;
  432.       pFEA = PFEA2 ( p ) ;
  433.     }
  434.     if ( i < Count-1 )
  435.       Start->oNextEntryOffset = PBYTE(pFEA) - PBYTE(Start) ;
  436.     else
  437.       Start->oNextEntryOffset = 0 ;
  438.   }
  439.  
  440.   pFEAList->cbList = PBYTE(pFEA) - PBYTE(pFEAList) ;
  441.  
  442.  /***************************************************************************
  443.   * Allocate memory for the EA header block.                                *
  444.   ***************************************************************************/
  445.  
  446.   PEAOP2 pExtendedAttributes = PEAOP2 ( AllocateMemory ( sizeof(EAOP2) ) ) ;
  447.  
  448.   if ( pExtendedAttributes == NULL ) {
  449.     FreeMemory ( pFEAList ) ;
  450.     return ( PEAOP2(NULL) ) ;
  451.   }
  452.  
  453.  /***************************************************************************
  454.   * Fill in the extended attribute header block and return its address.     *
  455.   ***************************************************************************/
  456.  
  457.   pExtendedAttributes->fpGEA2List = PGEA2LIST(NULL) ;
  458.   pExtendedAttributes->fpFEA2List = pFEAList ;
  459.   pExtendedAttributes->oError = 0 ;
  460.  
  461.   return ( pExtendedAttributes ) ;
  462. }
  463.  
  464. /****************************************************************************
  465.  *                                                                          *
  466.  *      Build Extended Attribute Item                                       *
  467.  *                                                                          *
  468.  ****************************************************************************/
  469.  
  470. static ULONG BuildExtendedAttributeItem ( PFEA2 pFEA, PEADATA Item ) {
  471.  
  472.  /***************************************************************************
  473.   * Store next entry's offset (set to zero at this point).                  *
  474.   ***************************************************************************/
  475.  
  476.   PBYTE p = PBYTE ( pFEA ) ;
  477.  
  478.   if ( pFEA ) {
  479.     *(PULONG(p)) = 0 ;
  480.   }
  481.  
  482.   p += sizeof(ULONG) ;
  483.  
  484.  /***************************************************************************
  485.   * Store flag byte.                                                        *
  486.   ***************************************************************************/
  487.  
  488.   if ( pFEA ) {
  489.     *p = 0 ;
  490.   }
  491.  
  492.   p ++ ;
  493.  
  494.  /***************************************************************************
  495.   * Store count of bytes in name.                                           *
  496.   ***************************************************************************/
  497.  
  498.   if ( pFEA ) {
  499.     *p = BYTE ( strlen ( PCHAR(Item->Name) ) ) ;
  500.   }
  501.  
  502.   p ++ ;
  503.  
  504.  /***************************************************************************
  505.   * Store count of bytes in value.                                          *
  506.   ***************************************************************************/
  507.  
  508.   if ( pFEA ) {
  509.     *(PUSHORT(p)) = USHORT ( Item->Length + 2 * sizeof(USHORT) ) ;
  510.   }
  511.  
  512.   p += sizeof(USHORT) ;
  513.  
  514.  /***************************************************************************
  515.   * Store name.                                                             *
  516.   ***************************************************************************/
  517.  
  518.   if ( pFEA ) {
  519.     strcpy ( PCHAR(p), PCHAR(Item->Name) ) ;
  520.   }
  521.  
  522.   p += strlen ( PCHAR(Item->Name) ) + 1 ;
  523.  
  524.  /***************************************************************************
  525.   * Store value's type.                                                     *
  526.   ***************************************************************************/
  527.  
  528.   if ( pFEA ) {
  529.     *(PUSHORT(p)) = Item->Type ;
  530.   }
  531.  
  532.   p += sizeof(USHORT) ;
  533.  
  534.  /***************************************************************************
  535.   * Store value's length.                                                   *
  536.   ***************************************************************************/
  537.  
  538.   if ( pFEA ) {
  539.     *(PUSHORT(p)) = Item->Length ;
  540.   }
  541.  
  542.   p += sizeof(USHORT) ;
  543.  
  544.  /***************************************************************************
  545.   * Store value.                                                            *
  546.   ***************************************************************************/
  547.  
  548.   if ( pFEA ) {
  549.     memcpy ( p, Item->Value, Item->Length ) ;
  550.   }
  551.  
  552.   p += Item->Length ;
  553.  
  554.  /***************************************************************************
  555.   * Return count of bytes needed for item.                                  *
  556.   ***************************************************************************/
  557.  
  558.   return ( p - PBYTE(pFEA) ) ;
  559. }
  560.  
  561. /****************************************************************************
  562.  *                                                                          *
  563.  *      Build Multi-Value Multi-Type EA Item's Value                        *
  564.  *                                                                          *
  565.  ****************************************************************************/
  566.  
  567. extern ULONG BuildMVMTValue ( PVOID Value, ULONG Count, MVMT_VALUE Table[] ) {
  568.  
  569.  /***************************************************************************
  570.   * Store the number of values.                                             *
  571.   ***************************************************************************/
  572.  
  573.   PBYTE p = PBYTE ( Value ) ;
  574.  
  575.   if ( Value )
  576.     *(PUSHORT(p)) = USHORT ( Count ) ;
  577.  
  578.   p += sizeof(USHORT) ;
  579.  
  580.  /***************************************************************************
  581.   * Store the multiple values.                                              *
  582.   ***************************************************************************/
  583.  
  584.   for ( int i=0; i<Count; i++ ) {
  585.  
  586.     if ( Value )
  587.       *(PUSHORT(p)) = Table[i].Type ;
  588.  
  589.     p += sizeof(USHORT) ;
  590.  
  591.     if ( Value )
  592.       *(PUSHORT(p)) = Table[i].Length ;
  593.  
  594.     p += sizeof(USHORT) ;
  595.  
  596.     if ( Value )
  597.       memcpy ( p, Table[i].Value, Table[i].Length ) ;
  598.  
  599.     p += Table[i].Length ;
  600.   }
  601.  
  602.  /***************************************************************************
  603.   * Return the total byte count.                                            *
  604.   ***************************************************************************/
  605.  
  606.   return ( p - PBYTE(Value) ) ;
  607. }
  608.  
  609. /****************************************************************************
  610.  *                                                                          *
  611.  *      Process Exit menu command.                                          *
  612.  *                                                                          *
  613.  ****************************************************************************/
  614.  
  615. extern MRESULT APIENTRY Exit ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  616.  
  617.  /***************************************************************************
  618.   * Send a WM_CLOSE message to the window.                                  *
  619.   ***************************************************************************/
  620.  
  621.   WinSendMsg ( hwnd, WM_CLOSE, 0L, 0L ) ;
  622.  
  623.  /***************************************************************************
  624.   * Done.                                                                   *
  625.   ***************************************************************************/
  626.  
  627.   return ( MRFROMSHORT ( 0 ) ) ;
  628. }
  629.  
  630. /****************************************************************************
  631.  *                                                                          *
  632.  *      Process Help For Help menu command.                                 *
  633.  *                                                                          *
  634.  ****************************************************************************/
  635.  
  636. extern MRESULT APIENTRY HelpForHelp ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  637.  
  638.  /***************************************************************************
  639.   * Get the help instance window handle, if any.                            *
  640.   ***************************************************************************/
  641.  
  642.   HWND hwndHelp = WinQueryHelpInstance ( hwnd ) ;
  643.  
  644.  /***************************************************************************
  645.   * If help is available, pass the request on to the help window.           *
  646.   ***************************************************************************/
  647.  
  648.   if ( hwndHelp ) {
  649.     WinSendMsg ( hwndHelp, HM_DISPLAY_HELP, 0L, 0L ) ;
  650.   }
  651.  
  652.  /***************************************************************************
  653.   * Done.                                                                   *
  654.   ***************************************************************************/
  655.  
  656.   return ( MRFROMSHORT ( 0 ) ) ;
  657. }
  658.  
  659. /****************************************************************************
  660.  *                                                                          *
  661.  *      Process Extended Help menu command.                                 *
  662.  *                                                                          *
  663.  ****************************************************************************/
  664.  
  665. extern MRESULT APIENTRY ExtendedHelp ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  666.  
  667.  /***************************************************************************
  668.   * Get the help instance window handle, if any.                            *
  669.   ***************************************************************************/
  670.  
  671.   HWND hwndHelp = WinQueryHelpInstance ( hwnd ) ;
  672.  
  673.  /***************************************************************************
  674.   * If help is available, pass the request on to the help window.           *
  675.   ***************************************************************************/
  676.  
  677.   if ( hwndHelp ) {
  678.     WinSendMsg ( hwndHelp, HM_EXT_HELP, 0L, 0L ) ;
  679.   }
  680.  
  681.  /***************************************************************************
  682.   * Done.                                                                   *
  683.   ***************************************************************************/
  684.  
  685.   return ( MRFROMSHORT ( 0 ) ) ;
  686. }
  687.  
  688. /****************************************************************************
  689.  *                                                                          *
  690.  *      Process Keys Help menu command.                                     *
  691.  *                                                                          *
  692.  ****************************************************************************/
  693.  
  694. extern MRESULT APIENTRY KeysHelp ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  695.  
  696.  /***************************************************************************
  697.   * Get the help instance window handle, if any.                            *
  698.   ***************************************************************************/
  699.  
  700.   HWND hwndHelp = WinQueryHelpInstance ( hwnd ) ;
  701.  
  702.  /***************************************************************************
  703.   * If help is available, pass the request on to the help window.           *
  704.   ***************************************************************************/
  705.  
  706.   if ( hwndHelp ) {
  707.     WinSendMsg ( hwndHelp, HM_KEYS_HELP, 0L, 0L ) ;
  708.   }
  709.  
  710.  /***************************************************************************
  711.   * Done.                                                                   *
  712.   ***************************************************************************/
  713.  
  714.   return ( MRFROMSHORT ( 0 ) ) ;
  715. }
  716.  
  717. /****************************************************************************
  718.  *                                                                          *
  719.  *      Process Help Index menu command.                                    *
  720.  *                                                                          *
  721.  ****************************************************************************/
  722.  
  723. extern MRESULT APIENTRY HelpIndex ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  724.  
  725.  /***************************************************************************
  726.   * Get the help instance window handle, if any.                            *
  727.   ***************************************************************************/
  728.  
  729.   HWND hwndHelp = WinQueryHelpInstance ( hwnd ) ;
  730.  
  731.  /***************************************************************************
  732.   * If help is available, pass the request on to the help window.           *
  733.   ***************************************************************************/
  734.  
  735.   if ( hwndHelp ) {
  736.     WinSendMsg ( hwndHelp, HM_HELP_INDEX, 0L, 0L ) ;
  737.   }
  738.  
  739.  /***************************************************************************
  740.   * Done.                                                                   *
  741.   ***************************************************************************/
  742.  
  743.   return ( MRFROMSHORT ( 0 ) ) ;
  744. }
  745.  
  746. /****************************************************************************
  747.  *                                                                          *
  748.  *      Copy Bitmap                                                         *
  749.  *                                                                          *
  750.  ****************************************************************************/
  751.  
  752. extern HBITMAP CopyBitmap ( HAB Anchor, HBITMAP Original ) {
  753.  
  754.    HBITMAP Copy = 0 ;
  755.    BITMAPINFOHEADER2 Header ;
  756.    Header.cbFix = 16 ;
  757.    GpiQueryBitmapInfoHeader ( Original, &Header ) ;
  758.    PSZ DeviceData [] = { PSZ(NULL), PSZ("Display"), PSZ(NULL), PSZ(NULL) } ;
  759.    HDC hdcMemory1 = DevOpenDC  ( Anchor, OD_MEMORY, PSZ("*"), 4, DeviceData, 0 ) ;
  760.    if ( hdcMemory1 ) {
  761.       HDC hdcMemory2 = DevOpenDC  ( Anchor, OD_MEMORY, PSZ("*"), 4, DeviceData, 0 ) ;
  762.       if ( hdcMemory2 ) {
  763.          SIZEL PageSize ;
  764.          PageSize.cx = Header.cx ;
  765.          PageSize.cy = Header.cy ;
  766.          HPS hpsMemory1 = GpiCreatePS ( Anchor, hdcMemory1, &PageSize, GPIA_ASSOC | PU_PELS ) ;
  767.          if ( hpsMemory1 ) {
  768.             HPS hpsMemory2 = GpiCreatePS ( Anchor, hdcMemory2, &PageSize, GPIA_ASSOC | PU_PELS ) ;
  769.             if ( hpsMemory2 ) {
  770.                Copy = GpiCreateBitmap ( hpsMemory2, &Header, FALSE, 0, 0 ) ;
  771.                if ( Copy ) {
  772.                   GpiSetBitmap ( hpsMemory1, Original ) ;
  773.                   GpiSetBitmap ( hpsMemory2, Copy ) ;
  774.                   POINTL Points [4] ;
  775.                   Points[0].x = Points[0].y = Points[2].x = Points[2].y = 0 ;
  776.                   Points[1].x = Points[3].x = Header.cx ;
  777.                   Points[1].y = Points[3].y = Header.cy ;
  778.                   GpiBitBlt ( hpsMemory2, hpsMemory1, 4L, Points, ROP_SRCCOPY, BBO_IGNORE ) ;
  779.                   GpiSetBitmap ( hpsMemory1, 0 ) ;
  780.                   GpiSetBitmap ( hpsMemory2, 0 ) ;
  781.                } else {
  782.                   ERRORID Error = WinGetLastError ( Anchor ) ;
  783.                   Log ( "CopyBitmap: ERROR: Unable to create bitmap.  Status %i.", Error ) ;
  784.                } /* endif */
  785.                GpiDestroyPS ( hpsMemory2 ) ;
  786.             } else {
  787.                ERRORID Error = WinGetLastError ( Anchor ) ;
  788.                Log ( "CopyBitmap: ERROR: Unable to open second memory presentation space.  Status %i.", Error ) ;
  789.             } /* endif */
  790.             GpiDestroyPS ( hpsMemory1 ) ;
  791.          } else {
  792.             ERRORID Error = WinGetLastError ( Anchor ) ;
  793.             Log ( "CopyBitmap: ERROR: Unable to open first memory presentation space.  Status %i.", Error ) ;
  794.          } /* endif */
  795.          DevCloseDC ( hdcMemory2 ) ;
  796.       } else {
  797.          ERRORID Error = WinGetLastError ( Anchor ) ;
  798.          Log ( "CopyBitmap: ERROR: Unable to open second memory device context.  Status %i.", Error ) ;
  799.       } /* endif */
  800.       DevCloseDC ( hdcMemory1 ) ;
  801.    } else {
  802.       ERRORID Error = WinGetLastError ( Anchor ) ;
  803.       Log ( "CopyBitmap: ERROR: Unable to open first memory device context.  Status %i.", Error ) ;
  804.    } /* endif */
  805.  
  806.    return ( Copy ) ;
  807. }
  808.  
  809. /****************************************************************************
  810.  *                                                                          *
  811.  *      Get Title-bar Rectangle (courtesy of Shinji Takasugi)               *
  812.  *                                                                          *
  813.  ****************************************************************************/
  814.  
  815. extern BOOL GetTitlebarRect ( HAB Anchor, HWND Window, RECTL &Rectangle ) {
  816.  
  817.    if ( WinQueryWindowRect ( Window, &Rectangle ) ) {
  818.  
  819.       HENUM henum = WinBeginEnumWindows ( Window ) ;
  820.       HWND hwndEnum = WinGetNextWindow ( henum ) ;  
  821.       while ( hwndEnum ) {
  822.  
  823.          RECTL rectEnum ;
  824.          WinQueryWindowRect ( hwndEnum, &rectEnum ) ;
  825.  
  826.          RECTL rectTemp ;
  827.          WinSubtractRect ( Anchor, &rectTemp, &Rectangle, &rectEnum ) ;
  828.  
  829.          Rectangle = rectTemp ;
  830.          hwndEnum = WinGetNextWindow ( henum ) ; 
  831.  
  832.       } /* endwhile */
  833.  
  834.       WinEndEnumWindows ( henum ) ;
  835.  
  836.       return ( TRUE ) ;
  837.  
  838.    } /* endif */
  839.  
  840.    return ( FALSE ) ;
  841. }
  842.  
  843.