|
|
1.1 root 1: /***************************************************************************\
2: * app.c - MDI Sample application
3: *
4: * Created by Microsoft Corporation, 1989
5: *
6: \***************************************************************************/
7:
8: #define INCL_WINSYS
9: #define INCL_WINCOMMON
10: #define INCL_WINMESSAGEMGR
11: #define INCL_WINPOINTERS
12: #define INCL_WININPUT
13: #define INCL_WINMENUS
14: #define INCL_WINFRAMEMGR
15: #define INCL_WINWINDOWMGR
16: #define INCL_WINRECTANGLES
17: #define INCL_WINHEAP
18: #define INCL_WINSCROLLBARS
19: #define INCL_GPIPRIMITIVES
20:
21: #include <os2.h>
22: #include "app.h"
23: #include "appdata.h"
24: #include "mdi.h"
25: #include "mdidata.h"
26:
27: /*
28: Function prototypes
29: */
30: BOOL AppInit(VOID);
31: BOOL MDIInit(VOID);
32: VOID AppTerminate(VOID);
33: VOID MDITerminate(VOID);
34: BOOL AppNewDocument(USHORT, PSZ);
35: VOID TrackSplitbars(HWND, USHORT, SHORT, SHORT);
36: VOID MDIDesktopSize(HWND, MPARAM, MPARAM);
37: VOID MDIDesktopSetFocus(HWND, MPARAM);
38: VOID MDIDesktopActivateDoc(SHORT idMenuitem);
39: BOOL AppNewDocument(USHORT, PSZ);
40: NPDOC MDINewDocument(USHORT fsStyle, PSZ pszClassName);
41: VOID MDISetInitialDocPos(HWND hwndNewFrame);
42:
43: int cdecl main(void)
44: {
45: QMSG qmsg;
46: /*
47: * Initialize the application globals
48: * and create the main window.
49: */
50: if (AppInit() == FALSE) {
51: WinAlarm(HWND_DESKTOP, WA_ERROR);
52: return(0);
53: }
54:
55: /*
56: * Initialize the MDI globals etc..
57: */
58: if (MDIInit() == FALSE) {
59: WinAlarm(HWND_DESKTOP, WA_ERROR);
60: WinAlarm(HWND_DESKTOP, WA_ERROR);
61: return(0);
62: }
63:
64: /*
65: * Create an initial, untitled document.
66: */
67: AppNewDocument(DS_HORZSPLITBAR | DS_VERTSPLITBAR, szDocClass);
68:
69: while (WinGetMsg(NULL, (PQMSG)&qmsg, NULL, 0, 0)) {
70: WinDispatchMsg(NULL, (PQMSG)&qmsg);
71: }
72:
73: /*
74: * Do the clean-up of the MDI code.
75: */
76: MDITerminate();
77:
78: /*
79: * Do the clean-up of the Application.
80: */
81: AppTerminate();
82:
83: DosExit(EXIT_PROCESS, 0);
84: }
85:
86:
87: MRESULT CALLBACK MDIWndProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
88: {
89: HPS hps;
90: RECTL rclPaint, rclWindow;
91: POINTL ptlPatternRef;
92:
93: switch (msg) {
94:
95: case WM_PAINT:
96: hps = WinBeginPaint(hwnd, (HPS)NULL, &rclPaint);
97:
98: /*
99: * Set the pattern to be at the top-left
100: * since we're top-left aligning the bits.
101: */
102: WinQueryWindowRect(hwnd, (PRECTL)&rclWindow);
103: ptlPatternRef.x = rclWindow.xLeft;
104: ptlPatternRef.y = rclWindow.yTop;
105: GpiSetPatternRefPoint(hps, &ptlPatternRef);
106:
107: WinFillRect(hps, &rclPaint, SYSCLR_APPWORKSPACE);
108:
109: WinEndPaint(hps);
110: break;
111:
112: case WM_SIZE:
113: MDIDesktopSize(hwnd, mp1, mp2);
114: break;
115:
116: case WM_SETFOCUS:
117: MDIDesktopSetFocus(hwnd, mp2);
118: break;
119:
120: case WM_COMMAND:
121: switch (SHORT1FROMMP(mp1)) {
122:
123: /*
124: * Pass these accelerators onto the active document's
125: * frame so it can process it.
126: *
127: * These are the CMD_ values from the document system
128: * menu.
129: */
130: case CMD_DOCRESTORE:
131: WinSendMsg(hwndActiveDoc, WM_SYSCOMMAND, (MPARAM)SC_RESTORE, mp2);
132: break;
133:
134: case CMD_DOCNEXT:
135: WinSendMsg(hwndActiveDoc, WM_SYSCOMMAND, (MPARAM)SC_NEXT, mp2);
136: break;
137:
138: case CMD_DOCMINIMIZE:
139: WinSendMsg(hwndActiveDoc, WM_SYSCOMMAND, (MPARAM)SC_MINIMIZE, mp2);
140: break;
141:
142: case CMD_DOCCLOSE:
143: WinSendMsg(hwndActiveDoc, WM_SYSCOMMAND, (MPARAM)SC_CLOSE, mp2);
144: break;
145:
146: case CMD_DOCSPLIT:
147: /*
148: * Call TrackSplitbars() with -1 for xMouse to tell
149: * it to reposition the pointer to where the
150: * splitbars currently are.
151: */
152: WinSetPointer(HWND_DESKTOP, hptrHVSplit);
153: TrackSplitbars(WinWindowFromID(hwndActiveDoc, FID_CLIENT),
154: SPS_VERT | SPS_HORZ, -1, -1);
155: WinSetPointer(HWND_DESKTOP, hptrArrow);
156: break;
157:
158: case CMD_NEW:
159: if (AppNewDocument(DS_HORZSPLITBAR | DS_VERTSPLITBAR, szDocClass) == FALSE)
160: WinAlarm(HWND_DESKTOP, WA_ERROR);
161: break;
162:
163: case CMD_CLOSE:
164: /*
165: * Close the active document.
166: */
167: if (hwndActiveDoc)
168: WinSendMsg(hwndActiveDoc, WM_CLOSE, 0L, 0L);
169: break;
170:
171: case CMD_ABOUT:
172: /*
173: * Put up the About... dialog box
174: */
175: WinDlgBox(HWND_DESKTOP, hwnd, AboutDlgProc, NULL, IDD_ABOUT, NULL);
176: break;
177:
178: case CMD_EXIT:
179: WinPostMsg(hwnd, WM_QUIT, 0L, 0L);
180: break;
181:
182: case CMD_ARRANGETILED:
183: ArrangeWindows(AWP_TILED);
184: break;
185:
186: case CMD_ARRANGECASCADED:
187: ArrangeWindows(AWP_CASCADED);
188: break;
189:
190: default:
191: /*
192: * The means a window title was selected from
193: * the window menu. Have the MDI code activate
194: * the correct window based on the menuitem ID.
195: *
196: * WARNING: Be sure to keep you applications
197: * menuitem IDs < CMD_WINDOWITEMS.
198: */
199: if (SHORT1FROMMP(mp1) >= CMD_WINDOWITEMS)
200: MDIDesktopActivateDoc(SHORT1FROMMP(mp1));
201: break;
202: }
203: break;
204:
205: default:
206: return(WinDefWindowProc(hwnd, msg, mp1, mp2));
207: break;
208: }
209:
210: return (0L);
211: }
212:
213:
214: BOOL AppNewDocument(USHORT fsStyle, PSZ pszClassName)
215: {
216: register NPDOC npdocNew;
217: HWND hwndFrame, hwndClient;
218: HWND hwndHScroll, hwndVScroll;
219:
220: npdocNew = MDINewDocument(fsStyle, pszClassName);
221:
222: npdocNew->clrBackground = clrNext++;
223: if (clrNext > CLR_PALEGRAY)
224: clrNext = CLR_BACKGROUND;
225:
226: hwndFrame = npdocNew->hwndFrame;
227: hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
228:
229: /*
230: * Setup the scrollbars.
231: */
232: hwndHScroll = WinWindowFromID(hwndFrame, FID_HORZSCROLL);
233: WinSendMsg(hwndHScroll, SBM_SETSCROLLBAR, MPFROMSHORT(0),
234: MPFROM2SHORT(0, 600));
235: hwndHScroll = WinWindowFromID(hwndFrame, ID_HORZSCROLL2);
236: WinSendMsg(hwndHScroll, SBM_SETSCROLLBAR, MPFROMSHORT(0),
237: MPFROM2SHORT(0, 600));
238:
239: hwndVScroll = WinWindowFromID(hwndFrame, FID_VERTSCROLL);
240: WinSendMsg(hwndVScroll, SBM_SETSCROLLBAR, MPFROMSHORT(0),
241: MPFROM2SHORT(0, 600));
242: hwndVScroll = WinWindowFromID(hwndFrame, ID_VERTSCROLL2);
243: WinSendMsg(hwndVScroll, SBM_SETSCROLLBAR, MPFROMSHORT(0),
244: MPFROM2SHORT(0, 600));
245:
246: /*
247: * Set the focus the client so the new window will be
248: * active when we show it.
249: */
250: WinSetFocus(HWND_DESKTOP, hwndClient);
251:
252: /*
253: * Set the initial position of the frame window and make it visible.
254: */
255: MDISetInitialDocPos(hwndFrame);
256:
257: return (TRUE);
258: }
259:
260: MRESULT CALLBACK AboutDlgProc(HWND hDlg, USHORT msg, MPARAM mp1, MPARAM mp2)
261: /*
262: About... dialog procedure
263: */
264: {
265: switch(msg) {
266: case WM_COMMAND:
267: switch(COMMANDMSG(&msg)->cmd) {
268: case DID_OK: WinDismissDlg(hDlg, TRUE); break;
269: default: break;
270: }
271: default: return WinDefDlgProc(hDlg, msg, mp1, mp2);
272: }
273: return FALSE;
274: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.