|
|
1.1 root 1: /*==============================================================*\
2: * User.c - routines for handling messages not processed
3: * by the standard message processing routine
4: * Created 1989, 1990 Microsoft 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: *--------------------------------------------------------------
14: *
15: * This source file contains the following functions:
16: *
17: * UserWndProc(hwnd, msg, mp1, mp2) - user window procedure
18: * UserCommand(mp1, mp2) - user WM_COMMAND processor
19: *
20: \*==============================================================*/
21:
22: /*--------------------------------------------------------------*\
23: * Include files, macros, defined constants, and externs
24: \*--------------------------------------------------------------*/
25:
26: #define INCL_WINMENUS
27:
28: #include <os2.h>
29: #include "main.h"
30: #include "dlg.h"
31: #include "xtrn.h"
32:
33: /*--------------------------------------------------------------*\
34: * Global variables
35: \*--------------------------------------------------------------*/
36:
37:
38: /*--------------------------------------------------------------*\
39: * Entry point declarations
40: \*--------------------------------------------------------------*/
41:
42:
43: /****************************************************************\
44: * Non-standard window message processing routine
45: *--------------------------------------------------------------
46: *
47: * Name: UserWndProc(hwnd, msg, mp1, mp2)
48: *
49: * Purpose: Process any messages sent to hwndMain that
50: * are not processed by the standard window
51: * procedure
52: *
53: * Usage: Routine is called for each message MainWndProc
54: * does not process
55: *
56: * Method: A switch statement branches control based upon
57: * the message passed. Any messages not processed
58: * here must be passed onto WinDefWindowProc()
59: *
60: * Returns: Return value dependent upon the message processed
61: *
62: \****************************************************************/
63: MRESULT UserWndProc(hwnd, msg, mp1, mp2)
64: HWND hwnd; /* handle of window */
65: USHORT msg; /* id of message */
66: MPARAM mp1; /* first message parameter */
67: MPARAM mp2; /* second message parameter */
68: {
69:
70: switch(msg) {
71:
72: /*--------------------------------------------------------------*\
73: * Add case statements for message ids you wish to process
74: \*--------------------------------------------------------------*/
75:
76:
77: default: /* default must call WinDefWindowProc() */
78: return(WinDefWindowProc(hwnd, msg, mp1, mp2));
79: break;
80: }
81:
82: return (MRESULT)0;
83:
84: } /* UserWndProc() */
85:
86:
87: /****************************************************************\
88: * Non-standard menu item command processing procedure
89: *--------------------------------------------------------------
90: *
91: * Name: UserCommand(mp1, mp2)
92: *
93: * Purpose: Process any WM_COMMAND messages sent to hwndMain
94: * that are not processed by MainCommand
95: *
96: * Usage: Routine is called for each WM_COMMAND that is
97: * not posted by a standard menu item
98: *
99: * Method: A switch statement branches control based upon
100: * the id of the control which posted the message
101: *
102: * Returns:
103: \****************************************************************/
104: VOID UserCommand(mp1, mp2)
105: MPARAM mp1; /* first message parameter */
106: MPARAM mp2; /* second message parameter */
107: {
108:
109: switch(SHORT1FROMMP(mp1)) {
110:
111: /*--------------------------------------------------------------*\
112: * Add case statements for menuitem ids you wish to process
113: \*--------------------------------------------------------------*/
114:
115:
116:
117: default:
118: break;
119: }
120:
121: /* This routine currently doesn't use the mp2 parameter but *\
122: * it is referenced here to prevent an 'Unreferenced Parameter'
123: \* warning at compile time. */
124: mp2;
125:
126: } /* UserCommand() */
127:
128: /****************************************************************\
129: * Menu item intialization routine
130: *--------------------------------------------------------------
131: *
132: * Name: InitMenu(mp1, mp2)
133: *
134: * Purpose: Processes the WM_INITMENU message for the main window,
135: * disabling any menus that are not active
136: *
137: * Usage: Routine is called each time a menu is dropped
138: *
139: * Method: A switch statement branches control based upon
140: * the id of the menu that is being displayed
141: *
142: * Returns:
143: \****************************************************************/
144: VOID InitMenu(mp1, mp2)
145: MPARAM mp1; /* first message parameter */
146: MPARAM mp2; /* second message parameter */
147: {
148:
149: /* define a shorthand way of denoting the menu handle */
150: #define hwndMenu HWNDFROMMP(mp2)
151:
152: switch(SHORT1FROMMP(mp1)) {
153: case IDM_FILE:
154: /*
155: * The Print, Print Setup, and Page Setup menu items of the
156: * File menu will be enabled if printing is enabled, otherwise
157: * they will be disabled
158: */
159:
160: EnableMenuItem(hwndMenu, IDM_FILEPRINT, fPrintEnabled);
161: EnableMenuItem(hwndMenu, IDM_FILEPRINTSETUP, fPrintEnabled);
162: EnableMenuItem(hwndMenu, IDM_FILEPAGESETUP, fPrintEnabled);
163:
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_HELPHELPFORHELP, fHelpEnabled);
172: EnableMenuItem(hwndMenu, IDM_HELPEXTENDED, 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: break;
180:
181: default:
182: break;
183: }
184:
185: #undef hwndMenu
186:
187: } /* InitMenu() */
188:
189: /****************************************************************\
190: * Enables/Disables the menu item of the given menu
191: *--------------------------------------------------------------
192: *
193: * Name: EnableMenuItem(hwndMenu, idItem, fEnable)
194: *
195: * Purpose: Enables or disables the menu item
196: *
197: * Usage: Called whenever a menu item is to be enabled or
198: * disabled
199: *
200: * Method: Sends a MM_SETITEMATTR to the menu with the
201: * given item id. Sets the MIA_DISABLED attribute
202: * flag if the item is to be disabled, clears the flag
203: * if enabling
204: *
205: * Returns:
206: *
207: \****************************************************************/
208: VOID EnableMenuItem(hwndMenu, idItem, fEnable)
209: HWND hwndMenu; /* Handle to the menu */
210: SHORT idItem; /* Id of the menu item to be enabled/disabled */
211: BOOL fEnable; /* flag to set enable or disable bit */
212: {
213: SHORT fsFlag;
214:
215: if(fEnable)
216: fsFlag = 0;
217: else
218: fsFlag = MIA_DISABLED;
219:
220: WinSendMsg(hwndMenu,
221: MM_SETITEMATTR,
222: MPFROM2SHORT(idItem, TRUE),
223: MPFROM2SHORT(MIA_DISABLED, fsFlag));
224:
225: } /* EnableMenuItem() */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.