home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / template.zip / USER.C < prev    next >
C/C++ Source or Header  |  1998-04-20  |  7KB  |  228 lines

  1. /**************************************************************************
  2.  *  File name  :  user.c
  3.  *
  4.  *  Description:  This module contains the code for processing messages
  5.  *                sent to the standard window that the standard window does
  6.  *                not process.  The application developer need only modify
  7.  *                this file in order to implement new menu items or process
  8.  *                messages not handled by the standard message routine.
  9.  *
  10.  *                This source file contains the following functions:
  11.  *
  12.  *                UserWndProc(hwnd, msg, mp1, mp2)
  13.  *                UserCommand(mp1, mp2)
  14.  *
  15.  *  Concepts   :  message processing
  16.  *
  17.  *  API's      :  WinDefWindowProc
  18.  *                WinSendMsg
  19.  *
  20.  *    Files    :  OS2.H, MAIN.H, DLG.H, XTRN.H
  21.  *
  22.  *  Copyright (C) 1991 IBM Corporation
  23.  *
  24.  *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  25.  *      sample code created by IBM Corporation. This sample code is not
  26.  *      part of any standard or IBM product and is provided to you solely
  27.  *      for  the purpose of assisting you in the development of your
  28.  *      applications.  The code is provided "AS IS", without
  29.  *      warranty of any kind.  IBM shall not be liable for any damages
  30.  *      arising out of your use of the sample code, even if they have been
  31.  *      advised of the possibility of such damages.                                                    *
  32.  *************************************************************************/
  33.  
  34. /*
  35.  *  Include files, macros, defined constants, and externs
  36.  */
  37.  
  38. #define INCL_WINMENUS
  39.  
  40. #include <os2.h>
  41. #include "main.h"
  42. #include "dlg.h"
  43. #include "xtrn.h"
  44.  
  45. /*
  46.  *  Global variables
  47.  */
  48.  
  49.  
  50. /*
  51.  *  Entry point declarations
  52.  */
  53.  
  54.  
  55. /**************************************************************************
  56.  *
  57.  *  Name       : UserWndProc(hwnd, msg, mp1, mp2)
  58.  *
  59.  *  Description: Process any messages sent to hwndMain that
  60.  *               are not processed by the standard window procedure.
  61.  *
  62.  *  Concepts:    Routine is called for each message MainWndProc
  63.  *               does not process.
  64.  *
  65.  *               A switch statement branches control based upon
  66.  *               the message passed.  Any messages not processed
  67.  *               here must be passed onto WinDefWindowProc().
  68.  *
  69.  *  API's      : WinDefWindowProc
  70.  *
  71.  *  Parameters :  hwnd = window handle
  72.  *                msg  = message i.d.
  73.  *                mp1  = first message parameter
  74.  *                mp2  = second message parameter
  75.  *
  76.  *  Return     :  Return value dependent upon the message processed
  77.  *
  78.  *************************************************************************/
  79. MRESULT UserWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  80. {
  81.    switch(msg)
  82.    {
  83.    /*
  84.     *  Add case statements for message ids you wish to process.
  85.     */
  86.  
  87.    default:    /* default must call WinDefWindowProc() */
  88.       return(WinDefWindowProc(hwnd, msg, mp1, mp2));
  89.       break;
  90.    }
  91.    return (MRESULT)0;
  92. }   /* End of UserWndProc   */
  93.  
  94.  
  95. /**************************************************************************
  96.  *
  97.  *  Name       : UserCommand(mp1, mp2)
  98.  *
  99.  *  Description: Process any WM_COMMAND messages sent to hwndMain
  100.  *               that are not processed by MainCommand.
  101.  *
  102.  *  Concepts:    Routine is called for each WM_COMMAND that is
  103.  *               not posted by a standard menu item.
  104.  *
  105.  *               A switch statement branches control based upon
  106.  *               the id of the control which posted the message.
  107.  *
  108.  *  API's      :  [none]
  109.  *
  110.  *  Parameters :  mp1  = first message parameter
  111.  *                mp2  = second message parameter
  112.  *
  113.  *  Return     :  [none]
  114.  *
  115.  *************************************************************************/
  116. VOID UserCommand(MPARAM mp1, MPARAM mp2)
  117. {
  118.    switch(SHORT1FROMMP(mp1))
  119.    {
  120.  
  121.    /*
  122.     *  Add case statements for menuitem ids you wish to process.
  123.     */
  124.  
  125.    default:
  126.       break;
  127.    }
  128.  
  129.    /* This routine currently doesn't use the mp2 parameter but
  130.     *  it is referenced here to prevent an 'Unreferenced Parameter'
  131.     *  warning at compile time.
  132.     */
  133.    mp2;
  134. }   /* End of UserCommand  */
  135.  
  136. /**************************************************************************
  137.  *
  138.  *  Name       : InitMenu()
  139.  *
  140.  *  Description: Processes the WM_INITMENU message for the main window,
  141.  *               disabling any menus that are not active.
  142.  *
  143.  *  Concepts:    Routine is called each time a menu is dropped.
  144.  *
  145.  *               A switch statement branches control based upon
  146.  *               the id of the menu that is being displayed.
  147.  *
  148.  *  API's      :  [none]
  149.  *
  150.  *  Parameters :  mp1  = first message parameter
  151.  *                mp2  = second message parameter
  152.  *
  153.  *  Return     :  [none]
  154.  *
  155.  *************************************************************************/
  156. VOID InitMenu(MPARAM mp1, MPARAM mp2)
  157. {
  158.               /* define a shorthand way of denoting the menu handle */
  159. #define hwndMenu        HWNDFROMMP(mp2)
  160.  
  161.    switch(SHORT1FROMMP(mp1))
  162.    {
  163.    case IDM_FILE:
  164.       break;
  165.  
  166.    case IDM_HELP:
  167.             /*
  168.              * Enable or disable the Help menu depending upon whether the
  169.              * help manager has been enabled
  170.              */
  171.         EnableMenuItem(hwndMenu, IDM_HELPUSINGHELP, fHelpEnabled);
  172.         EnableMenuItem(hwndMenu, IDM_HELPGENERAL, fHelpEnabled);
  173.         EnableMenuItem(hwndMenu, IDM_HELPKEYS, fHelpEnabled);
  174.         EnableMenuItem(hwndMenu, IDM_HELPINDEX, fHelpEnabled);
  175.  
  176.          /*  REMEMBER: add a case for IDM_HELPTUTORIAL if you include
  177.           *  the Tutorial menu item.
  178.           */
  179.  
  180.        break;
  181.  
  182.     default:
  183.        break;
  184.     }
  185.  
  186. #undef hwndMenu
  187. }   /* End of InitMenu   */
  188.  
  189. /**************************************************************************
  190.  *
  191.  *  Name       : EnableMenuItem(hwndMenu, idItem, fEnable)
  192.  *
  193.  *  Description: Enables or disables the menu item
  194.  *
  195.  *  Concepts:    Called whenever a menu item is to be enabled or
  196.  *               disabled
  197.  *
  198.  *               Sends a MM_SETITEMATTR to the menu with the
  199.  *               given item id.  Sets the MIA_DISABLED attribute
  200.  *               flag if the item is to be disabled, clears the flag
  201.  *               if enabling.
  202.  *
  203.  *  API's      : WinSendMsg
  204.  *
  205.  *  Parameters :  hwndmenu = menu window handle
  206.  *                idItem   = menu item i.d.
  207.  *                fEnable  = enable (yes) or disable (no)
  208.  *
  209.  *  Return     :  [none]
  210.  *
  211.  *************************************************************************/
  212. VOID EnableMenuItem(HWND hwndMenu, USHORT idItem, BOOL fEnable)
  213. {
  214.    SHORT fsFlag;
  215.  
  216.    if(fEnable)
  217.       fsFlag = 0;
  218.    else
  219.       fsFlag = MIA_DISABLED;
  220.  
  221.    WinSendMsg(hwndMenu,
  222.               MM_SETITEMATTR,
  223.               MPFROM2SHORT(idItem, TRUE),
  224.               MPFROM2SHORT(MIA_DISABLED, fsFlag));
  225.  
  226. }   /* End of EnableMenuItem() */
  227. /***************************  End of user.c  ****************************/
  228.