home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / drgmon.zip / menu.c < prev    next >
C/C++ Source or Header  |  1993-08-11  |  10KB  |  212 lines

  1. /*********************************************************************
  2.  *                                                                   *
  3.  * MODULE NAME :  menu.c                 AUTHOR:  Rick Fishman       *
  4.  * DATE WRITTEN:  07-22-93                                           *
  5.  *                                                                   *
  6.  * MODULE DESCRIPTION:                                               *
  7.  *                                                                   *
  8.  *  Part of the 'DRGDROP' drag/drop sample program.                  *
  9.  *                                                                   *
  10.  *  This module takes care of creating and destroying the container  *
  11.  *  context menu.                                                    *
  12.  *                                                                   *
  13.  * NOTES:                                                            *
  14.  *                                                                   *
  15.  *                                                                   *
  16.  * FUNCTIONS AVALABLE TO OTHER MODULES:                              *
  17.  *                                                                   *
  18.  *   menuCreate                                                      *
  19.  *   menuEnd                                                         *
  20.  *                                                                   *
  21.  *                                                                   *
  22.  * HISTORY:                                                          *
  23.  *                                                                   *
  24.  *  07-22-93 - Program coded.                                        *
  25.  *                                                                   *
  26.  *  Rick Fishman                                                     *
  27.  *  Code Blazers, Inc.                                               *
  28.  *  4113 Apricot                                                     *
  29.  *  Irvine, CA. 92720                                                *
  30.  *  CIS ID: 72251,750                                                *
  31.  *                                                                   *
  32.  *********************************************************************/
  33.  
  34. #pragma strings(readonly)   // used for debug version of memory mgmt routines
  35.  
  36. /*********************************************************************/
  37. /*------- Include relevant sections of the OS/2 header files --------*/
  38. /*********************************************************************/
  39.  
  40. #define  INCL_WINERRORS
  41. #define  INCL_WINFRAMEMGR
  42. #define  INCL_WINMENUS
  43. #define  INCL_WINPOINTERS
  44. #define  INCL_WINSTDCNR
  45. #define  INCL_WINSTDDRAG
  46. #define  INCL_WINWINDOWMGR
  47.  
  48. /**********************************************************************/
  49. /*----------------------------- INCLUDES -----------------------------*/
  50. /**********************************************************************/
  51.  
  52. #include <os2.h>
  53. #include <stdio.h>
  54. #include <stdlib.h>
  55. #include <string.h>
  56. #include "drgdrop.h"
  57.  
  58. /*********************************************************************/
  59. /*------------------- APPLICATION DEFINITIONS -----------------------*/
  60. /*********************************************************************/
  61.  
  62.  
  63. /**********************************************************************/
  64. /*---------------------------- STRUCTURES ----------------------------*/
  65. /**********************************************************************/
  66.  
  67.  
  68. /**********************************************************************/
  69. /*----------------------- FUNCTION PROTOTYPES ------------------------*/
  70. /**********************************************************************/
  71.  
  72.  
  73. /**********************************************************************/
  74. /*------------------------ GLOBAL VARIABLES --------------------------*/
  75. /**********************************************************************/
  76.  
  77. HWND hwndMenu;
  78.  
  79. /**********************************************************************/
  80. /*--------------------------- menuCreate -----------------------------*/
  81. /*                                                                    */
  82. /*  CREATE AND POSITION THE CONTEXT MENU.                             */
  83. /*                                                                    */
  84. /*  PARMS: frame window handle                                        */
  85. /*                                                                    */
  86. /*  NOTES:                                                            */
  87. /*                                                                    */
  88. /*  RETURNS: nothing                                                  */
  89. /*                                                                    */
  90. /*--------------------------------------------------------------------*/
  91. /**********************************************************************/
  92. void menuCreate( HWND hwndFrame )
  93. {
  94.     if( !hwndMenu || !WinIsWindow( ANCHOR( hwndFrame ), hwndMenu ) )
  95.         hwndMenu = WinLoadMenu( hwndFrame, 0, ID_CONTEXT_MENU );
  96.  
  97.     if( hwndMenu )
  98.     {
  99.         POINTL ptl;
  100.  
  101.         // Get the position of the mouse pointer
  102.  
  103.         if( WinQueryPointerPos( HWND_DESKTOP, &ptl ) )
  104.         {
  105.             // Convert the position of the mouse pointer to coordinates with
  106.             // respect to the frame window.
  107.  
  108.             if( WinMapWindowPoints( HWND_DESKTOP, hwndFrame, &ptl, 1 ) )
  109.             {
  110.                 if( WinPopupMenu( hwndFrame, hwndFrame, hwndMenu, ptl.x, ptl.y,
  111.                                   0, PU_HCONSTRAIN | PU_VCONSTRAIN |
  112.                                   PU_KEYBOARD | PU_MOUSEBUTTON1 |
  113.                                   PU_MOUSEBUTTON2 | PU_NONE ) )
  114.                 {
  115.                     // If you don't do this PM will assign a menu id of
  116.                     // FID_MENU.
  117.  
  118.                     WinSetWindowUShort( hwndMenu, QWS_ID, ID_CONTEXT_MENU );
  119.                 }
  120.                 else
  121.                     Msg( "menuCreate WinPopupMenu failed! RC(%X)",
  122.                          HWNDERR( hwndFrame ) );
  123.             }
  124.             else
  125.                 Msg( "menuCreate WinMapWindowPoints failed! RC(%X)",
  126.                      HWNDERR( hwndFrame ) );
  127.         }
  128.         else
  129.             Msg( "menuCreate WinQueryPointerPos failed! RC(%X)",
  130.                  HWNDERR( hwndFrame ) );
  131.     }
  132.     else
  133.         Msg( "menuCreate could not load the context menu. RC(%X)",
  134.              HWNDERR( hwndFrame ) );
  135. }
  136.  
  137. /**********************************************************************/
  138. /*----------------------------- menuEnd ------------------------------*/
  139. /*                                                                    */
  140. /*  DESTROY THE MENU ON A WM_MENUEND MESSAGE.                         */
  141. /*                                                                    */
  142. /*  PARMS: frame window handle,                                       */
  143. /*         menu id                                                    */
  144. /*         menu window handle                                         */
  145. /*                                                                    */
  146. /*  NOTES:                                                            */
  147. /*                                                                    */
  148. /*  RETURNS: nothing                                                  */
  149. /*                                                                    */
  150. /*--------------------------------------------------------------------*/
  151. /**********************************************************************/
  152. void menuEnd( HWND hwndFrame, ULONG idMenu, HWND hwndMenu )
  153. {
  154.     if( idMenu == ID_CONTEXT_MENU && hwndMenu )
  155.     {
  156.         // After the menu is gone the container no longer has the focus so we
  157.         // have to reset it.
  158.  
  159.         WinSetFocus( HWND_DESKTOP, WinWindowFromID( hwndFrame, FID_CLIENT ) );
  160.     }
  161. }
  162.  
  163. /**********************************************************************/
  164. /*--------------------------- menuCommand ----------------------------*/
  165. /*                                                                    */
  166. /*  PROCESS A WM_COMMAND MESSAGE GENERATED FROM THE MENU.             */
  167. /*                                                                    */
  168. /*  PARMS: frame window handle,                                       */
  169. /*         command id                                                 */
  170. /*                                                                    */
  171. /*  NOTES:                                                            */
  172. /*                                                                    */
  173. /*  RETURNS: nothing                                                  */
  174. /*                                                                    */
  175. /*--------------------------------------------------------------------*/
  176. /**********************************************************************/
  177. void menuCommand( HWND hwndFrame, ULONG idCommand )
  178. {
  179.     switch( idCommand )
  180.     {
  181.         case IDM_DRAGINFO_SETTINGS:
  182.             bookSetup( NBPID_DRAGINFO );
  183.             break;
  184.  
  185.         case IDM_RMF_SETTINGS:
  186.             bookSetup( NBPID_RMF );
  187.             break;
  188.  
  189.         case IDM_REPLY_SETTINGS:
  190.             bookSetup( NBPID_REPLY );
  191.             break;
  192.  
  193.         case IDM_MISC_SETTINGS:
  194.             bookSetup( NBPID_MISC );
  195.             break;
  196.  
  197.         case IDM_SURFACE_LISTBOX:
  198.             WinSetActiveWindow( HWND_DESKTOP,
  199.                                 INSTDATA( hwndFrame )->hwndDebug );
  200.             break;
  201.  
  202.         case IDM_EXIT:
  203.             WinPostMsg( hwndFrame, WM_SYSCOMMAND, MPFROMSHORT( SC_CLOSE ),
  204.                         MPFROM2SHORT( CMDSRC_ACCELERATOR, FALSE ) );
  205.             break;
  206.     }
  207. }
  208.  
  209. /*************************************************************************
  210.  *                     E N D     O F     S O U R C E                     *
  211.  *************************************************************************/
  212.