|
|
1.1 ! root 1: /*==============================================================*\ ! 2: * sem_user.c - routines for handling messages not processed * ! 3: * by the standard message processing routine * ! 4: * Created 1990, Microsoft, IBM Corp. * ! 5: *--------------------------------------------------------------* ! 6: * * ! 7: * This module contains the code for processing messages sent * ! 8: * to the standard window that the standard window does not * ! 9: * process. The application developer need only modify this * ! 10: * file in order to implement new menu items or process * ! 11: * messages not handled by the standard message routine. * ! 12: * * ! 13: * This module also contains some routines that demonstate the * ! 14: * various dialog box controls and message box types that can * ! 15: * be used. The sample code should be deleted when this * ! 16: * module is modified for an application. The demonstration * ! 17: * code is identified by comments. * ! 18: * * ! 19: *--------------------------------------------------------------* ! 20: * * ! 21: * This source file contains the following functions: * ! 22: * * ! 23: * UserWndProc(hwnd, msg, mp1, mp2) - user window procedure* ! 24: * UserCommand(mp1, mp2) - user WM_COMMAND processor * ! 25: * SetForegroundColor(hwnd) * ! 26: * SetBackgroundColor(hwnd, nMenuId) * ! 27: * SetWindowText(hwnd) * ! 28: * * ! 29: \*==============================================================*/ ! 30: ! 31: /*--------------------------------------------------------------*\ ! 32: * Include files, macros, defined constants, and externs * ! 33: \*--------------------------------------------------------------*/ ! 34: ! 35: #define LINT_ARGS ! 36: #define INCL_DOS ! 37: #define INCL_WIN ! 38: #include <os2.h> ! 39: #include <dos.h> ! 40: #include "sem_pnt.h" ! 41: #include "semaph.h" ! 42: #include "sem_main.h" ! 43: #include "sem_dlg.h" ! 44: #include "sem_xtrn.h" ! 45: ! 46: ! 47: /*--------------------------------------------------------------*\ ! 48: * Global variables * ! 49: \*--------------------------------------------------------------*/ ! 50: ! 51: ! 52: /* Variable used only by main thread for menu control. */ ! 53: ! 54: USHORT fSemaphoreStarted = FALSE; ! 55: USHORT fSemaphoreWasStarted = FALSE; ! 56: USHORT fAutoMode = FALSE; ! 57: ! 58: /*--------------------------------------------------------------*\ ! 59: * Entry point declarations * ! 60: \*--------------------------------------------------------------*/ ! 61: ! 62: ! 63: /****************************************************************\ ! 64: * Non-standard window message processing routine * ! 65: *--------------------------------------------------------------* ! 66: * * ! 67: * Name: UserWndProc(hwnd, msg, mp1, mp2) * ! 68: * * ! 69: * Purpose: Process any messages sent to hwndMain that * ! 70: * are not processed by the standard window * ! 71: * procedure * ! 72: * * ! 73: * Usage: Routine is called for each message MainWndProc * ! 74: * does not process * ! 75: * * ! 76: * Method: A switch statement branches control based upon * ! 77: * the message passed. Any messages not processed * ! 78: * here must be passed onto WinDefWindowProc() * ! 79: * * ! 80: * Returns: Return value depended upon the message processed * ! 81: \****************************************************************/ ! 82: MRESULT UserWndProc(hwnd, msg, mp1, mp2) ! 83: HWND hwnd; /* handle of window */ ! 84: USHORT msg; /* id of message */ ! 85: MPARAM mp1; /* first message parameter */ ! 86: MPARAM mp2; /* second message parameter */ ! 87: { ! 88: ! 89: switch(msg) { ! 90: /*--------------------------------------------------------------*\ ! 91: * Add case statements for message ids you wish to process * ! 92: \*--------------------------------------------------------------*/ ! 93: default: /* default must call WinDefWindowProc() */ ! 94: return(WinDefWindowProc(hwnd, msg, mp1, mp2)); ! 95: break; ! 96: } ! 97: ! 98: return 0L; ! 99: ! 100: } /* UserWndProc() */ ! 101: ! 102: ! 103: /****************************************************************\ ! 104: * Non-standard menu item command processing procedure * ! 105: *--------------------------------------------------------------* ! 106: * * ! 107: * Name: UserCommand(mp1, mp2) * ! 108: * * ! 109: * Purpose: Process any WM_COMMAND messages send to hwndMain * ! 110: * that are not processed by MainCommand * ! 111: * * ! 112: * Usage: Routine is called for each WM_COMMAND that is * ! 113: * not posted by a standard menu item * ! 114: * * ! 115: * Method: A switch statement branches control based upon * ! 116: * the id of the control which posted the message * ! 117: * * ! 118: * Returns: * ! 119: \****************************************************************/ ! 120: VOID UserCommand(mp1, mp2) ! 121: MPARAM mp1; /* first message parameter */ ! 122: MPARAM mp2; /* second message parameter */ ! 123: { ! 124: USHORT rc; ! 125: HWND hwndSemMenu; ! 126: ! 127: hwndSemMenu = WinWindowFromID(hwndMainFrame,FID_MENU); ! 128: ! 129: switch(SHORT1FROMMP(mp1)) { ! 130: ! 131: case IDM_SEMSTART_MANUAL: ! 132: if (!fSemaphoreStarted) ! 133: { /* should never get this message unless sample started*/ ! 134: ! 135: fSemaphoreStarted = TRUE; ! 136: fSemaphoreWasStarted = TRUE; ! 137: ! 138: /* Turn on other menu items */ ! 139: WinSendMsg(hwndSemMenu,MM_SETITEMATTR, ! 140: MPFROM2SHORT(IDM_SEMSTOP,TRUE), ! 141: MPFROM2SHORT(MIA_DISABLED,FALSE)); ! 142: ! 143: WinSendMsg(hwndSemMenu,MM_SETITEMATTR, ! 144: MPFROM2SHORT(IDM_POST,TRUE), ! 145: MPFROM2SHORT(MIA_DISABLED,FALSE)); ! 146: ! 147: WinSendMsg(hwndSemMenu,MM_SETITEMATTR, ! 148: MPFROM2SHORT(IDM_SEM_RESUMEAUTO,TRUE), ! 149: MPFROM2SHORT(MIA_DISABLED,FALSE)); ! 150: ! 151: /* turn off menu items to configure demo */ ! 152: WinSendMsg(hwndSemMenu,MM_SETITEMATTR, ! 153: MPFROM2SHORT(IDM_OPTIONS,TRUE), ! 154: MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED)); ! 155: ! 156: WinSendMsg(hwndSemMenu,MM_SETITEMATTR, ! 157: MPFROM2SHORT(IDM_SEMSTART,TRUE), ! 158: MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED)); ! 159: ! 160: if (StartSemExample() == FALSE) { ! 161: MessageBox (HWND_DESKTOP, IDMSG_CANNOTSTART, TRUE); ! 162: WinSendMsg (hwndMain, WM_CLOSE, 0L, 0L); ! 163: } ! 164: } ! 165: break; ! 166: ! 167: case IDM_POST: ! 168: if (fSemaphoreStarted) ! 169: { /* should never get this message unless sample started*/ ! 170: if (fAutoMode) ! 171: { ! 172: WinSendMsg(hwndSemMenu,MM_SETITEMATTR, ! 173: MPFROM2SHORT(IDM_SEM_RESUMEAUTO,TRUE), ! 174: MPFROM2SHORT(MIA_DISABLED,FALSE)); ! 175: } ! 176: SignalUserEvent(&fAutoMode); ! 177: } ! 178: break; ! 179: ! 180: case IDM_SEM_RESUMEAUTO: ! 181: case IDM_SEMSTART_AUTO: ! 182: if (!fSemaphoreStarted) ! 183: { /* should never get this message unless sample started*/ ! 184: fSemaphoreStarted = TRUE; ! 185: fSemaphoreWasStarted = TRUE; ! 186: ! 187: /* Turn on other menu items */ ! 188: WinSendMsg(hwndSemMenu,MM_SETITEMATTR, ! 189: MPFROM2SHORT(IDM_SEMSTOP,TRUE), ! 190: MPFROM2SHORT(MIA_DISABLED,FALSE)); ! 191: ! 192: WinSendMsg(hwndSemMenu,MM_SETITEMATTR, ! 193: MPFROM2SHORT(IDM_POST,TRUE), ! 194: MPFROM2SHORT(MIA_DISABLED,FALSE)); ! 195: ! 196: /* turn off menu items to configure demo */ ! 197: WinSendMsg(hwndSemMenu,MM_SETITEMATTR, ! 198: MPFROM2SHORT(IDM_OPTIONS,TRUE), ! 199: MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED)); ! 200: ! 201: StartSemExample(); ! 202: ! 203: } ! 204: ! 205: if (fSemaphoreStarted && !fAutoMode) ! 206: { ! 207: rc = SetAutoMode(); ! 208: if (!rc) ! 209: { ! 210: fAutoMode = TRUE; ! 211: /* disable menus */ ! 212: ! 213: WinSendMsg(hwndSemMenu,MM_SETITEMATTR, ! 214: MPFROM2SHORT(IDM_SEM_RESUMEAUTO,TRUE), ! 215: MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED)); ! 216: ! 217: WinSendMsg(hwndSemMenu,MM_SETITEMATTR, ! 218: MPFROM2SHORT(IDM_SEMSTART,TRUE), ! 219: MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED)); ! 220: } ! 221: } ! 222: break; ! 223: ! 224: case IDM_SEMSTOP: ! 225: if (fSemaphoreStarted) ! 226: { ! 227: BeginStop (&fAutoMode); ! 228: ! 229: /* don't allow them to select stop again */ ! 230: WinSendMsg(hwndSemMenu,MM_SETITEMATTR, ! 231: MPFROM2SHORT(IDM_SEMSTOP,TRUE), ! 232: MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED)); ! 233: ! 234: WinSendMsg(hwndSemMenu,MM_SETITEMATTR, ! 235: MPFROM2SHORT(IDM_SEM_RESUMEAUTO,TRUE), ! 236: MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED)); ! 237: ! 238: WinSendMsg(hwndSemMenu,MM_SETITEMATTR, ! 239: MPFROM2SHORT(IDM_POST,TRUE), ! 240: MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED)); ! 241: } ! 242: break; ! 243: case IDM_STOPFINISHED: ! 244: if (fSemaphoreStarted) ! 245: { ! 246: fSemaphoreStarted = FALSE; ! 247: ! 248: /* Reset option and semaphore/start menu items ... */ ! 249: WinSendMsg(hwndSemMenu,MM_SETITEMATTR, ! 250: MPFROM2SHORT(IDM_SEMSTART,TRUE), ! 251: MPFROM2SHORT(MIA_DISABLED,FALSE)); ! 252: ! 253: /* turn on menu items to configure demo */ ! 254: WinSendMsg(hwndSemMenu,MM_SETITEMATTR, ! 255: MPFROM2SHORT(IDM_OPTIONS,TRUE), ! 256: MPFROM2SHORT(MIA_DISABLED,FALSE)); ! 257: } ! 258: break; ! 259: ! 260: case IDM_OPTIONS_NTHRDS_2: ! 261: case IDM_OPTIONS_NTHRDS_4: ! 262: case IDM_OPTIONS_NTHRDS_8: ! 263: case IDM_OPTIONS_NTHRDS_16: ! 264: if (!fSemaphoreStarted) { ! 265: INT oldNumUsers = cNumUsers; ! 266: WinSendMsg(hwndSemMenu,MM_SETITEMATTR, ! 267: MPFROM2SHORT(IDM_OPTIONS_NTHRDS+cNumUsers,TRUE), ! 268: MPFROM2SHORT(MIA_CHECKED,FALSE)); ! 269: cNumUsers = SHORT1FROMMP(mp1) - IDM_OPTIONS_NTHRDS; ! 270: /* if we changed the number of threads to display */ ! 271: if (cNumUsers != oldNumUsers) ! 272: WinPostMsg (hwndMain, WM_USERCHANGED, (MPARAM)0, (MPARAM)0); ! 273: ! 274: WinSendMsg(hwndSemMenu,MM_SETITEMATTR, ! 275: MPFROM2SHORT(IDM_OPTIONS_NTHRDS+cNumUsers,TRUE), ! 276: MPFROM2SHORT(MIA_CHECKED,MIA_CHECKED)); ! 277: } ! 278: break; ! 279: ! 280: case IDM_OPTIONS_TIMEOUT: ! 281: if (!fSemaphoreStarted) { ! 282: WinDlgBox (HWND_DESKTOP, hwndMain, TimeDlgProc, NULL, ! 283: TIMERBOX, (PVOID)ulTimeout); ! 284: } ! 285: break; ! 286: ! 287: default: ! 288: break; ! 289: } ! 290: ! 291: /* This routine currently doesn't use the mp2 parameter but *\ ! 292: * it is referenced here to prevent an 'Unreferenced Parameter' * ! 293: \* warning at compile time. */ ! 294: mp2; ! 295: ! 296: } /* UserCommand() */ ! 297: ! 298: ! 299: ! 300:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.