home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / startapp.zip / USER.C < prev    next >
Text File  |  1998-09-10  |  8KB  |  242 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.  *  (c) Copyright IBM Corp. 1991, 1998  All rights reserved.
  23.  *
  24.  *  These sample programs are owned by International Business Machines
  25.  *  Corporation or one of its subsidiaries ("IBM") and are copyrighted and
  26.  *  licensed, not sold.
  27.  *
  28.  *  You may copy, modify, and distribute these sample programs in any
  29.  *  form without payment to IBM, for any purpose including developing,
  30.  *  using, marketing or distributing programs that include or are
  31.  *  derivative works of the sample programs.
  32.  *
  33.  *  The sample programs are provided to you on an "AS IS" basis, without
  34.  *  warranty of any kind.  IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES,
  35.  *  EITHER EXPRESS OR IMPLIED, INCLUDING , BUT NOT LIMITED TO, THE IMPLIED
  36.  *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  37.  *  Some jurisdictions do not allow for the exclusion or limitation of
  38.  *  implied warranties, so the above limitations or exclusions may not
  39.  *  apply to you.  IBM shall not be liable for any damages you suffer
  40.  *  as a result of using, modifying or distributing the sample programs
  41.  *  or their derivatives.
  42.  *************************************************************************/
  43.  
  44. /*
  45.  *  Include files, macros, defined constants, and externs
  46.  */
  47.  
  48. #define INCL_WINMENUS
  49. #define INCL_WIN  /* (come back and limit to listbox LM..)*/
  50.  
  51. #include <os2.h>
  52. #include "main.h"
  53. #include "dlg.h"
  54. #include "xtrn.h"
  55.  
  56. /*
  57.  *  Global variables
  58.  */
  59. /**************************************************************************
  60.  *
  61.  *  Name       : UserWndProc(hwnd, msg, mp1, mp2)
  62.  *
  63.  *  Description: Process any messages sent to hwndMain that
  64.  *               are not processed by the standard window procedure.
  65.  *
  66.  *  Concepts:    Routine is called for each message MainWndProc
  67.  *               does not process.
  68.  *
  69.  *               A switch statement branches control based upon
  70.  *               the message passed.  Any messages not processed
  71.  *               here must be passed onto WinDefWindowProc().
  72.  *
  73.  *  API's      : WinDefWindowProc
  74.  *
  75.  *  Parameters :  hwnd = window handle
  76.  *                msg  = message i.d.
  77.  *                mp1  = first message parameter
  78.  *                mp2  = second message parameter
  79.  *
  80.  *  Return     :  Return value dependent upon the message processed
  81.  *
  82.  *************************************************************************/
  83. MRESULT UserWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  84. {
  85.    switch(msg)
  86.    {
  87.    /*
  88.     When the program specified by the application handle terminates, the window
  89.     specified by the hwndNotify parameter (if the window still exists and is valid)
  90.     has a WM_APPTERMINATENOTIFY message posted to it to notify it of the
  91.     application termination.
  92.    */
  93.  
  94.    case WM_APPTERMINATENOTIFY:
  95.         WinSendMsg(hwndList, LM_INSERTITEM,
  96.              MPFROMSHORT(LIT_END),
  97.              "Application was Terminated by User");
  98.         fStarted=FALSE;  /* set the started flag for menu controls */
  99.       break;
  100.  
  101.    default:    /* default must call WinDefWindowProc() */
  102.       return(WinDefWindowProc(hwnd, msg, mp1, mp2));
  103.       break;
  104.    }
  105.    return (MRESULT)0;
  106. }   /* End of UserWndProc   */
  107. /**************************************************************************
  108.  *
  109.  *  Name       : UserCommand(mp1, mp2)
  110.  *
  111.  *  Description: Process any WM_COMMAND messages sent to hwndMain
  112.  *               that are not processed by MainCommand.
  113.  *
  114.  *  Concepts:    Routine is called for each WM_COMMAND that is
  115.  *               not posted by a standard menu item.
  116.  *
  117.  *               A switch statement branches control based upon
  118.  *               the id of the control which posted the message.
  119.  *
  120.  *  API's      :  [none]
  121.  *
  122.  *  Parameters :  mp1  = first message parameter
  123.  *                mp2  = second message parameter
  124.  *
  125.  *  Return     :  [none]
  126.  *
  127.  *************************************************************************/
  128. VOID UserCommand(MPARAM mp1, MPARAM mp2)
  129. {
  130.    switch(SHORT1FROMMP(mp1))
  131.    {
  132.  
  133.    /*
  134.     *  Reserved for future enhancements.
  135.     */
  136.  
  137.    default:
  138.       break;
  139.    }
  140.  
  141.    /* This routine currently doesn't use the mp2 parameter but
  142.     *  it is referenced here to prevent an 'Unreferenced Parameter'
  143.     *  warning at compile time.
  144.     */
  145.    mp2;
  146. }   /* End of UserCommand  */
  147.  
  148. /**************************************************************************
  149.  *
  150.  *  Name       : InitMenu()
  151.  *
  152.  *  Description: Processes the WM_INITMENU message for the main window,
  153.  *               disabling any menus that are not active.
  154.  *
  155.  *  Concepts:    Routine is called each time a menu is dropped.
  156.  *
  157.  *               A switch statement branches control based upon
  158.  *               the id of the menu that is being displayed.
  159.  *
  160.  *  API's      :  [none]
  161.  *
  162.  *  Parameters :  mp1  = first message parameter
  163.  *                mp2  = second message parameter
  164.  *
  165.  *  Return     :  [none]
  166.  *
  167.  *************************************************************************/
  168. VOID InitMenu(MPARAM mp1, MPARAM mp2)
  169. {
  170. /* define a shorthand way of denoting the menu handle */
  171. #define hwndMenu        HWNDFROMMP(mp2)
  172.  
  173.    switch(SHORT1FROMMP(mp1))
  174.    {
  175.  
  176.    case IDM_CTRL:
  177.         EnableMenuItem(hwndMenu, IDM_STARTDATA, FALSE);
  178.         EnableMenuItem(hwndMenu, IDM_LASTPMERR, FALSE);
  179.         if(fStarted) { /* if application is started disable Start menu item */
  180.            EnableMenuItem(hwndMenu, IDM_START, FALSE);
  181.            EnableMenuItem(hwndMenu, IDM_TERMIN8, TRUE);
  182.            }
  183.         else {         /* if application is not started disable Terminate item */
  184.            EnableMenuItem(hwndMenu, IDM_START, TRUE);
  185.            EnableMenuItem(hwndMenu, IDM_TERMIN8, FALSE);
  186.            }
  187.         break;
  188.  
  189.    case IDM_HELP:
  190.         EnableMenuItem(hwndMenu, IDM_HELPUSINGHELP, fHelpEnabled);
  191.         EnableMenuItem(hwndMenu, IDM_HELPGENERAL, fHelpEnabled);
  192.         EnableMenuItem(hwndMenu, IDM_HELPKEYS, fHelpEnabled);
  193.         EnableMenuItem(hwndMenu, IDM_HELPINDEX, fHelpEnabled);
  194.         break;
  195.  
  196.    default:
  197.         break;
  198.     }
  199.  
  200. #undef hwndMenu
  201. }   /* End of InitMenu   */
  202.  
  203. /**************************************************************************
  204.  *
  205.  *  Name       : EnableMenuItem(hwndMenu, idItem, fEnable)
  206.  *
  207.  *  Description: Enables or disables the menu item
  208.  *
  209.  *  Concepts:    Called whenever a menu item is to be enabled or
  210.  *               disabled
  211.  *
  212.  *               Sends a MM_SETITEMATTR to the menu with the
  213.  *               given item id.  Sets the MIA_DISABLED attribute
  214.  *               flag if the item is to be disabled, clears the flag
  215.  *               if enabling.
  216.  *
  217.  *  API's      : WinSendMsg
  218.  *
  219.  *  Parameters :  hwndmenu = menu window handle
  220.  *                idItem   = menu item i.d.
  221.  *                fEnable  = enable (yes) or disable (no)
  222.  *
  223.  *  Return     :  [none]
  224.  *
  225.  *************************************************************************/
  226. VOID EnableMenuItem(HWND hwndMenu, USHORT idItem, BOOL fEnable)
  227. {
  228.    SHORT fsFlag;
  229.  
  230.    if(fEnable)
  231.       fsFlag = 0;
  232.    else
  233.       fsFlag = MIA_DISABLED;
  234.  
  235.    WinSendMsg(hwndMenu,
  236.               MM_SETITEMATTR,
  237.               MPFROM2SHORT(idItem, TRUE),
  238.               MPFROM2SHORT(MIA_DISABLED, fsFlag));
  239.  
  240. }   /* End of EnableMenuItem() */
  241. /***************************  End of user.c  ****************************/
  242.