home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / os2 / semaph / sem_user.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  10KB  |  241 lines

  1. /*static char *SCCSID = "@(#)sem_user.c    6.10 92/03/25";*/
  2. /*==============================================================*\
  3.  *  SEM_USER.C - routines for handling messages not processed   *
  4.  *              by the standard message processing routine      *
  5.  *      (C) Copyright IBM Corporation 1992.                     *
  6.  *--------------------------------------------------------------*
  7.  *                                                              *
  8.  *  This module contains the code for processing messages sent  *
  9.  *  to the standard window that the standard window does not    *
  10.  *  process.  The application developer need only modify this   *
  11.  *  file in order to implement new menu items or process        *
  12.  *  messages not handled by the standard message routine.       *
  13.  *                                                              *
  14.  *  This module also contains some routines that demonstate the *
  15.  *  various dialog box controls and message box types that can  *
  16.  *  be used.  The sample code should be deleted when this       *
  17.  *  module is modified for an application.  The demonstration   *
  18.  *  code is identified by comments.                             *
  19.  *                                                              *
  20.  *--------------------------------------------------------------*
  21.  *                                                              *
  22.  *  This source file contains the following functions:          *
  23.  *                                                              *
  24.  *      UserCommand(mp1, mp2) - user WM_COMMAND processor       *
  25.  *                                                              *
  26. \*==============================================================*/
  27.  
  28. /*--------------------------------------------------------------*\
  29.  *  Include files, macros, defined constants, and externs       *
  30. \*--------------------------------------------------------------*/
  31. #include "semaph.h"
  32.  
  33. /****************************************************************\
  34.  *  Non-standard menu item command processing procedure         *
  35.  *--------------------------------------------------------------*
  36.  *                                                              *
  37.  *  Name:   UserCommand(mp1, mp2)                               *
  38.  *                                                              *
  39.  *  Purpose: Process any WM_COMMAND messages send to hwndMain   *
  40.  *              that are not processed by MainCommand           *
  41.  *                                                              *
  42.  *  Usage:  Routine is called for each WM_COMMAND that is       *
  43.  *          not posted by a standard menu item                  *
  44.  *                                                              *
  45.  *  Method: A switch statement branches control based upon      *
  46.  *          the id of the control which posted the message      *
  47.  *                                                              *
  48.  *  Returns:                                                    *
  49. \****************************************************************/
  50. VOID UserCommand( MPARAM mp1, MPARAM mp2 )
  51. {
  52.     USHORT rc;
  53.     HWND hwndSemMenu;
  54.  
  55.     hwndSemMenu = WinWindowFromID(hwndMainFrame, FID_MENU);
  56.  
  57.     switch(SHORT1FROMMP(mp1))
  58.     {
  59.        case IDM_SEMSTART_MANUAL:
  60.            if (!fSemaphoreStarted)
  61.            {   /* should never get this message unless sample started*/
  62.  
  63.                fSemaphoreStarted = TRUE;
  64.                fSemaphoreWasStarted = TRUE;
  65.  
  66.                /* Turn on other menu items */
  67.                WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  68.                    MPFROM2SHORT(IDM_SEMSTOP,TRUE),
  69.                    MPFROM2SHORT(MIA_DISABLED,FALSE));
  70.  
  71.                WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  72.                    MPFROM2SHORT(IDM_POST,TRUE),
  73.                    MPFROM2SHORT(MIA_DISABLED,FALSE));
  74.  
  75.                WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  76.                    MPFROM2SHORT(IDM_SEM_RESUMEAUTO,TRUE),
  77.                    MPFROM2SHORT(MIA_DISABLED,FALSE));
  78.  
  79.                /* turn off menu items to configure demo */
  80.                WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  81.                    MPFROM2SHORT(IDM_OPTIONS_NTHRDS,TRUE),
  82.                    MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));
  83.  
  84.                WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  85.                    MPFROM2SHORT(IDM_OPTIONS_TIMEOUT ,TRUE),
  86.                    MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));
  87.  
  88.                WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  89.                    MPFROM2SHORT(IDM_SEMSTART,TRUE),
  90.                    MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));
  91.  
  92.                if (StartSemExample() == FALSE) {
  93.                    MessageBox (HWND_DESKTOP, IDMSG_CANNOTSTART, TRUE);
  94.                    WinSendMsg (hwndMain, WM_CLOSE, 0L, 0L);
  95.                }
  96.            }
  97.            break;
  98.  
  99.        case IDM_POST:
  100.            if (fSemaphoreStarted)
  101.            {   /* should never get this message unless sample started*/
  102.                if (fAutoMode)
  103.                {
  104.                     WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  105.                      MPFROM2SHORT(IDM_SEM_RESUMEAUTO,TRUE),
  106.                      MPFROM2SHORT(MIA_DISABLED,FALSE));
  107.                }
  108.                SignalUserEvent(&fAutoMode);
  109.            }
  110.            break;
  111.  
  112.        case IDM_SEM_RESUMEAUTO:
  113.        case IDM_SEMSTART_AUTO:
  114.            if (!fSemaphoreStarted)
  115.            {    /* should never get this message unless sample started*/
  116.                 fSemaphoreStarted = TRUE;
  117.                 fSemaphoreWasStarted = TRUE;
  118.  
  119.                 /* Turn on other menu items */
  120.                 WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  121.                     MPFROM2SHORT(IDM_SEMSTOP,TRUE),
  122.                     MPFROM2SHORT(MIA_DISABLED,FALSE));
  123.  
  124.                 WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  125.                     MPFROM2SHORT(IDM_POST,TRUE),
  126.                     MPFROM2SHORT(MIA_DISABLED,FALSE));
  127.  
  128.                 /* turn off menu items to configure demo */
  129.                 WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  130.                     MPFROM2SHORT(IDM_OPTIONS_NTHRDS,TRUE),
  131.                     MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));
  132.  
  133.                WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  134.                    MPFROM2SHORT(IDM_OPTIONS_TIMEOUT ,TRUE),
  135.                    MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));
  136.  
  137.                 StartSemExample();
  138.  
  139.            }
  140.  
  141.            if (fSemaphoreStarted && !fAutoMode)
  142.            {
  143.               rc = SetAutoMode();
  144.               if (!rc)
  145.               {
  146.                  fAutoMode = TRUE;
  147.                  /* disable menus */
  148.  
  149.                  WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  150.                      MPFROM2SHORT(IDM_SEM_RESUMEAUTO,TRUE),
  151.                      MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));
  152.  
  153.                  WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  154.                     MPFROM2SHORT(IDM_SEMSTART,TRUE),
  155.                     MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));
  156.               }
  157.            }
  158.            break;
  159.  
  160.        case  IDM_SEMSTOP:
  161.            if (fSemaphoreStarted)
  162.            {
  163.               BeginStop (&fAutoMode);
  164.  
  165.                /* don't allow them to select stop again */
  166.               WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  167.                   MPFROM2SHORT(IDM_SEMSTOP,TRUE),
  168.                   MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));
  169.  
  170.               WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  171.                   MPFROM2SHORT(IDM_SEM_RESUMEAUTO,TRUE),
  172.                   MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));
  173.  
  174.               WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  175.                   MPFROM2SHORT(IDM_POST,TRUE),
  176.                   MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));
  177.            }
  178.            break;
  179.        case  IDM_STOPFINISHED:
  180.            if (fSemaphoreStarted)
  181.            {
  182.               fSemaphoreStarted = FALSE;
  183.  
  184.               /* Reset option and semaphore/start menu items ... */
  185.               WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  186.                   MPFROM2SHORT(IDM_SEMSTART,TRUE),
  187.                   MPFROM2SHORT(MIA_DISABLED,FALSE));
  188.  
  189.               WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  190.                   MPFROM2SHORT(IDM_OPTIONS_NTHRDS,TRUE),
  191.                   MPFROM2SHORT(MIA_DISABLED,FALSE));
  192.  
  193.               WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  194.                   MPFROM2SHORT(IDM_OPTIONS_TIMEOUT ,TRUE),
  195.                   MPFROM2SHORT(MIA_DISABLED,FALSE));
  196.            }
  197.            break;
  198.  
  199.        case IDM_OPTIONS_NTHRDS_2:
  200.        case IDM_OPTIONS_NTHRDS_4:
  201.        case IDM_OPTIONS_NTHRDS_8:
  202.        case IDM_OPTIONS_NTHRDS_16:
  203.            if (!fSemaphoreStarted) {
  204.                INT oldNumUsers = cNumUsers;
  205.                WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  206.                    MPFROM2SHORT(IDM_OPTIONS_NTHRDS+cNumUsers,TRUE),
  207.                    MPFROM2SHORT(MIA_CHECKED,FALSE));
  208.                cNumUsers = SHORT1FROMMP(mp1) - IDM_OPTIONS_NTHRDS;
  209.                /* if we changed the number of threads to display */
  210.                if (cNumUsers != oldNumUsers)
  211.                    WinPostMsg (hwndMain, WM_USERCHANGED, (MPARAM)0, (MPARAM)0);
  212.  
  213.                WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
  214.                    MPFROM2SHORT(IDM_OPTIONS_NTHRDS+cNumUsers,TRUE),
  215.                    MPFROM2SHORT(MIA_CHECKED,MIA_CHECKED));
  216.            }
  217.            break;
  218.  
  219.        case IDM_OPTIONS_TIMEOUT:
  220.            if (!fSemaphoreStarted)
  221.            {
  222.                WinDlgBox (HWND_DESKTOP,
  223.                           hwndMain,
  224.                           TimeDlgProc,
  225.                           0,
  226.                           TIMERBOX,
  227.                           NULL);
  228.            }
  229.            break;
  230.  
  231.        default:
  232.                break;
  233.     }
  234.  
  235.     /* This routine currently doesn't use the mp2 parameter but       *\
  236.      *  it is referenced here to prevent an 'Unreferenced Parameter'  *
  237.     \*  warning at compile time.                                      */
  238.     return;
  239.  
  240. }                                                    /* UserCommand() */
  241.