File:  [OS/2 SDKs] / os232sdk / toolkt20 / c / samples / semaph / sem_user.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 12:26:30 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: os2sdk-1990, HEAD
Microsoft OS/2 SDK 2.0 05-30-1990

/*==============================================================*\
 *  sem_user.c - routines for handling messages not processed	*
 *              by the standard message processing routine      *
 *      Created 1990, Microsoft, IBM Corp.                      *
 *--------------------------------------------------------------*
 *                                                              *
 *  This module contains the code for processing messages sent	*
 *  to the standard window that the standard window does not	*
 *  process.  The application developer need only modify this	*
 *  file in order to implement new menu items or process        *
 *  messages not handled by the standard message routine.       *
 *                                                              *
 *  This module also contains some routines that demonstate the *
 *  various dialog box controls and message box types that can	*
 *  be used.  The sample code should be deleted when this       *
 *  module is modified for an application.  The demonstration	*
 *  code is identified by comments.                             *
 *                                                              *
 *--------------------------------------------------------------*
 *                                                              *
 *  This source file contains the following functions:          *
 *                                                              *
 *	UserWndProc(hwnd, msg, mp1, mp2) - user window procedure*
 *      UserCommand(mp1, mp2) - user WM_COMMAND processor       *
 *      SetForegroundColor(hwnd)                                *
 *      SetBackgroundColor(hwnd, nMenuId)                       *
 *      SetWindowText(hwnd)                                     *
 *                                                              *
\*==============================================================*/

/*--------------------------------------------------------------*\
 *  Include files, macros, defined constants, and externs	*
\*--------------------------------------------------------------*/

#define  LINT_ARGS
#define  INCL_DOS
#define  INCL_WIN
#include <os2.h>
#include <dos.h>
#include "sem_pnt.h"
#include "semaph.h"
#include "sem_main.h"
#include "sem_dlg.h"
#include "sem_xtrn.h"


/*--------------------------------------------------------------*\
 *  Global variables                                            *
\*--------------------------------------------------------------*/


/* Variable used only by main thread for menu control. */

USHORT fSemaphoreStarted = FALSE;
USHORT fSemaphoreWasStarted = FALSE;
USHORT fAutoMode = FALSE;

/*--------------------------------------------------------------*\
 *  Entry point declarations					*
\*--------------------------------------------------------------*/


/****************************************************************\
 *  Non-standard window message processing routine              *
 *--------------------------------------------------------------*
 *                                                              *
 *  Name:   UserWndProc(hwnd, msg, mp1, mp2)                    *
 *                                                              *
 *  Purpose: Process any messages sent to hwndMain that         *
 *              are not processed by the standard window        *
 *              procedure                                       *
 *                                                              *
 *  Usage:  Routine is called for each message MainWndProc      *
 *          does not process                                    *
 *                                                              *
 *  Method: A switch statement branches control based upon      *
 *          the message passed.  Any messages not processed     *
 *          here must be passed onto WinDefWindowProc()         *
 *                                                              *
 *  Returns: Return value depended upon the message processed   *
\****************************************************************/
MRESULT UserWndProc(hwnd, msg, mp1, mp2)
HWND hwnd;	/* handle of window */
USHORT msg;	/* id of message */
MPARAM mp1;	/* first message parameter */
MPARAM mp2;	/* second message parameter */
{

    switch(msg)  {
        /*--------------------------------------------------------------*\
        *	Add case statements for message ids you wish to process     *
        \*--------------------------------------------------------------*/
	    default:    /* default must call WinDefWindowProc() */
	        return(WinDefWindowProc(hwnd, msg, mp1, mp2));
	        break;
    }

    return 0L;

}   /* UserWndProc() */


/****************************************************************\
 *  Non-standard menu item command processing procedure         *
 *--------------------------------------------------------------*
 *                                                              *
 *  Name:   UserCommand(mp1, mp2)                               *
 *                                                              *
 *  Purpose: Process any WM_COMMAND messages send to hwndMain   *
 *              that are not processed by MainCommand           *
 *                                                              *
 *  Usage:  Routine is called for each WM_COMMAND that is       *
 *          not posted by a standard menu item                  *
 *                                                              *
 *  Method: A switch statement branches control based upon      *
 *          the id of the control which posted the message      *
 *                                                              *
 *  Returns:                                                    *
\****************************************************************/
VOID UserCommand(mp1, mp2)
MPARAM mp1;	/* first message parameter */
MPARAM mp2;	/* second message parameter */
{
    USHORT rc;
    HWND hwndSemMenu;

    hwndSemMenu = WinWindowFromID(hwndMainFrame,FID_MENU);

    switch(SHORT1FROMMP(mp1))  {

        case IDM_SEMSTART_MANUAL:
            if (!fSemaphoreStarted)
            {   /* should never get this message unless sample started*/

                fSemaphoreStarted = TRUE;
                fSemaphoreWasStarted = TRUE;

                /* Turn on other menu items */
                WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
                    MPFROM2SHORT(IDM_SEMSTOP,TRUE),
                    MPFROM2SHORT(MIA_DISABLED,FALSE));

                WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
                    MPFROM2SHORT(IDM_POST,TRUE),
                    MPFROM2SHORT(MIA_DISABLED,FALSE));

                WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
                    MPFROM2SHORT(IDM_SEM_RESUMEAUTO,TRUE),
                    MPFROM2SHORT(MIA_DISABLED,FALSE));
                
                /* turn off menu items to configure demo */
                WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
                    MPFROM2SHORT(IDM_OPTIONS,TRUE),
                    MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));

                WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
                    MPFROM2SHORT(IDM_SEMSTART,TRUE),
                    MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));

                if (StartSemExample() == FALSE) {
                    MessageBox (HWND_DESKTOP, IDMSG_CANNOTSTART, TRUE);
                    WinSendMsg (hwndMain, WM_CLOSE, 0L, 0L);
                }
            }
            break;

        case IDM_POST:
            if (fSemaphoreStarted)
            {   /* should never get this message unless sample started*/
                if (fAutoMode)
                {
                     WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
                      MPFROM2SHORT(IDM_SEM_RESUMEAUTO,TRUE),
                      MPFROM2SHORT(MIA_DISABLED,FALSE));
                }
                SignalUserEvent(&fAutoMode);
            }
            break;

        case IDM_SEM_RESUMEAUTO:
        case IDM_SEMSTART_AUTO:
            if (!fSemaphoreStarted)
            {    /* should never get this message unless sample started*/
                 fSemaphoreStarted = TRUE;
                 fSemaphoreWasStarted = TRUE;

                 /* Turn on other menu items */
                 WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
                     MPFROM2SHORT(IDM_SEMSTOP,TRUE),
                     MPFROM2SHORT(MIA_DISABLED,FALSE));

                 WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
                     MPFROM2SHORT(IDM_POST,TRUE),
                     MPFROM2SHORT(MIA_DISABLED,FALSE));

                 /* turn off menu items to configure demo */
                 WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
                     MPFROM2SHORT(IDM_OPTIONS,TRUE),
                     MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));

                 StartSemExample();

            }

            if (fSemaphoreStarted && !fAutoMode) 
            {
               rc = SetAutoMode();
               if (!rc)
               {
                  fAutoMode = TRUE;
                  /* disable menus */

                  WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
                      MPFROM2SHORT(IDM_SEM_RESUMEAUTO,TRUE),
                      MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));

                  WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
                     MPFROM2SHORT(IDM_SEMSTART,TRUE),
                     MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));
               }
            }
            break;

        case  IDM_SEMSTOP:
            if (fSemaphoreStarted)
            {
               BeginStop (&fAutoMode);

                /* don't allow them to select stop again */
               WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
                   MPFROM2SHORT(IDM_SEMSTOP,TRUE),
                   MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));

               WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
                   MPFROM2SHORT(IDM_SEM_RESUMEAUTO,TRUE),
                   MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));
               
               WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
                   MPFROM2SHORT(IDM_POST,TRUE),
                   MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));
            }
            break;
        case  IDM_STOPFINISHED:
            if (fSemaphoreStarted)
            {
               fSemaphoreStarted = FALSE;

               /* Reset option and semaphore/start menu items ... */
               WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
                   MPFROM2SHORT(IDM_SEMSTART,TRUE),
                   MPFROM2SHORT(MIA_DISABLED,FALSE));
            
               /* turn on menu items to configure demo */
               WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
                   MPFROM2SHORT(IDM_OPTIONS,TRUE),
                   MPFROM2SHORT(MIA_DISABLED,FALSE));
            }
            break;

        case IDM_OPTIONS_NTHRDS_2:
        case IDM_OPTIONS_NTHRDS_4:
        case IDM_OPTIONS_NTHRDS_8:
        case IDM_OPTIONS_NTHRDS_16:
            if (!fSemaphoreStarted) {
                INT oldNumUsers = cNumUsers;
                WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
                    MPFROM2SHORT(IDM_OPTIONS_NTHRDS+cNumUsers,TRUE),
                    MPFROM2SHORT(MIA_CHECKED,FALSE));
                cNumUsers = SHORT1FROMMP(mp1) - IDM_OPTIONS_NTHRDS;
                /* if we changed the number of threads to display */
                if (cNumUsers != oldNumUsers)
                    WinPostMsg (hwndMain, WM_USERCHANGED, (MPARAM)0, (MPARAM)0);
                
                WinSendMsg(hwndSemMenu,MM_SETITEMATTR,
                    MPFROM2SHORT(IDM_OPTIONS_NTHRDS+cNumUsers,TRUE),
                    MPFROM2SHORT(MIA_CHECKED,MIA_CHECKED));
            }
            break;

        case IDM_OPTIONS_TIMEOUT:
            if (!fSemaphoreStarted) {
                WinDlgBox (HWND_DESKTOP, hwndMain, TimeDlgProc, NULL,
                TIMERBOX, (PVOID)ulTimeout);
            }
            break;

        default:
	        break;
    }

    /* This routine currently doesn't use the mp2 parameter but       *\
     *	it is referenced here to prevent an 'Unreferenced Parameter'  *
    \*	warning at compile time.				      */
    mp2;

}   /* UserCommand() */





unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.