|
|
1.1 root 1: /****************************** Module Header ******************************\
2: * Module Name: memory.c
3: *
4: * Copyright (c) 1991, Microsoft Corporation
5: *
6: *
7: *
8: * History:
1.1.1.3 ! root 9: * 09-17-91 Petrus Wong Created.
1.1 root 10: *
11: \***************************************************************************/
12:
13: #include <stdlib.h>
14:
15: #include "memory.h"
16: #include <stdarg.h>
17:
18: extern CreateMapFile();
19: extern CreateMap();
20: extern MapView();
21: extern OpenMap();
22:
23:
24: HANDLE ghModule;
25: HWND ghwndMain = NULL;
26:
27: HMENU hMenu, hMenuWindow;
28: HMENU hServerMenu, hServerMenuWindow;
29: HMENU hClientMenu, hClientMenuWindow;
30:
31: CHAR gszFile[20];
32: CHAR gszMapName[20];
33:
34:
35: typedef struct _PerWndInfo {
36: // HWND hMainFrame;
37: HWND hParent;
38: HWND hThisWnd; // CR! used in locating the node
39: // LPVOID pShrMem1; // LATER! create more clients/servers
40: RECT rcClient;
41: char CaptionBarText[SIZEOFCAPTIONTEXT];
42: } PERWNDINFO, *PPERWNDINFO;
43:
44:
45: typedef struct _node {
46: PERWNDINFO ChildWnd;
47: HANDLE hNext;
48: } NODE, *PNODE;
49:
50:
51: /*
52: * Forward declarations.
53: */
54: BOOL InitializeApp (void);
1.1.1.3 ! root 55: LONG APIENTRY MainWndProc (HWND, UINT, DWORD, LONG);
! 56: LONG APIENTRY ServerWndProc (HWND, UINT, DWORD, LONG);
! 57: LONG APIENTRY ClientWndProc (HWND, UINT, DWORD, LONG);
! 58: LONG APIENTRY About (HWND, UINT, DWORD, LONG);
1.1 root 59: LONG FileType (HWND, UINT, DWORD, LONG);
60: LONG MapFileName (HWND, UINT, DWORD, LONG);
1.1.1.3 ! root 61: LONG APIENTRY TextWndProc (HWND, UINT, DWORD, LONG);
! 62: extern int FAR PASCAL ShellAbout(HWND, LPCSTR, LPCSTR, HICON);
1.1 root 63:
64: /***************************************************************************\
65: * main
66: *
67: *
68: * History:
1.1.1.3 ! root 69: * 04-17-91 ???? Created.
1.1 root 70: \***************************************************************************/
71:
1.1.1.3 ! root 72: int WINAPI WinMain(
1.1 root 73: HANDLE hInstance,
74: HANDLE hPrevInstance,
75: LPSTR lpCmdLine,
76: int nShowCmd)
77: {
78: MSG msg;
79:
80: // this will change to something more reasonable
81:
82: ghModule = GetModuleHandle(NULL);
83: if (!InitializeApp()) {
84: MessageBox(ghwndMain, "memory: InitializeApp failure!", "Error", MB_OK);
85: return 0;
86: }
87:
88: while (GetMessage(&msg, NULL, 0, 0)) {
89: TranslateMessage(&msg);
90: DispatchMessage(&msg);
91: }
92:
93: if (hMenuWindow && IsWindow(hMenuWindow))
94: DestroyMenu(hMenuWindow);
95: if (hClientMenuWindow && IsWindow(hClientMenuWindow))
96: DestroyMenu(hClientMenuWindow);
97: if (hServerMenuWindow && IsWindow(hServerMenuWindow))
98: DestroyMenu(hServerMenuWindow);
99: if (hMenu && IsWindow(hMenu))
100: DestroyMenu(hMenu);
101: if (hClientMenu && IsWindow(hClientMenu))
102: DestroyMenu(hClientMenu);
103: if (hServerMenu && IsWindow(hServerMenu))
104: DestroyMenu(hServerMenu);
105:
106: return 1;
107:
108: UNREFERENCED_PARAMETER(lpCmdLine);
109: UNREFERENCED_PARAMETER(nShowCmd);
110: UNREFERENCED_PARAMETER(hInstance);
111: UNREFERENCED_PARAMETER(hPrevInstance);
112: }
113:
114:
115: /***************************************************************************\
116: * InitializeApp
117: *
118: * History:
1.1.1.3 ! root 119: * 09-09-91 Petrus Wong Created.
1.1 root 120: \***************************************************************************/
121:
122: BOOL InitializeApp(void)
123: {
124: WNDCLASS wc;
125:
126: wc.style = CS_OWNDC;
1.1.1.2 root 127: wc.lpfnWndProc = (WNDPROC)MainWndProc;
1.1 root 128: wc.cbClsExtra = 0;
129: wc.cbWndExtra = sizeof(LONG);
130: wc.hInstance = ghModule;
131: wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
132: wc.hCursor = LoadCursor(NULL, IDC_ARROW);
133: wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE);
134: wc.lpszMenuName = "MainMenu";
135: wc.lpszClassName = "MemoryClass";
136:
137: if (!RegisterClass(&wc))
138: return FALSE;
139:
140: wc.style = CS_OWNDC;
1.1.1.2 root 141: wc.lpfnWndProc = (WNDPROC)ServerWndProc;
1.1 root 142: wc.cbClsExtra = 0;
143: wc.cbWndExtra = 0; // LATER sizeof(LONG);
144: wc.hInstance = ghModule;
145: wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
146: wc.hCursor = LoadCursor(NULL, IDC_ARROW);
147: wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE);
148: wc.lpszMenuName = NULL;
149: wc.lpszClassName = "ServerClass";
150:
151: if (!RegisterClass(&wc))
152: return FALSE;
153:
154: wc.style = CS_OWNDC;
1.1.1.2 root 155: wc.lpfnWndProc = (WNDPROC)ClientWndProc;
1.1 root 156: wc.cbClsExtra = 0;
157: wc.cbWndExtra = 0; // LATER sizeof(LONG);
158: wc.hInstance = ghModule;
159: wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
160: wc.hCursor = LoadCursor(NULL, IDC_ARROW);
161: wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE);
162: wc.lpszMenuName = NULL;
163: wc.lpszClassName = "ClientClass";
164:
165: if (!RegisterClass(&wc))
166: return FALSE;
167:
168: wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
1.1.1.2 root 169: wc.lpfnWndProc = (WNDPROC)TextWndProc;
1.1 root 170: wc.cbClsExtra = 0;
171: wc.cbWndExtra = 0;
172: wc.hInstance = ghModule;
173: wc.hIcon = NULL;
174: wc.hCursor = LoadCursor(NULL, IDC_ARROW);
175: wc.hbrBackground = (HBRUSH)(COLOR_BTNSHADOW);
176: wc.lpszMenuName = NULL;
177: wc.lpszClassName = "Text";
178:
179: if (!RegisterClass(&wc))
180: return FALSE;
181:
182:
183:
184: hMenu = LoadMenu(ghModule, "MainMenu");
185: hServerMenu = LoadMenu(ghModule, "ServerMenu");
186: hClientMenu = LoadMenu(ghModule, "ClientMenu");
187: hMenuWindow = GetSubMenu(hMenu, 1);
188: hServerMenuWindow = GetSubMenu(hServerMenu, 2);
189: hClientMenuWindow = GetSubMenu(hClientMenu, 2);
190:
191: ghwndMain = CreateWindowEx(0L, "MemoryClass", "Memory",
192: WS_OVERLAPPED | WS_CAPTION | WS_BORDER |
193: WS_THICKFRAME | WS_MAXIMIZEBOX | WS_MINIMIZEBOX |
194: WS_CLIPCHILDREN | WS_VISIBLE | WS_SYSMENU,
195: 80, 70, 400, 300,
196: NULL, hMenu, ghModule, NULL);
197:
198: if (ghwndMain == NULL)
199: return FALSE;
200:
201: SetWindowLong(ghwndMain, GWL_USERDATA, 0L);
202:
1.1.1.3 ! root 203: //SetFocus(ghwndMain); /* set initial focus */
1.1 root 204:
205: return TRUE;
206: }
207:
208:
209: /***************************************************************************\
210: * MainWndProc
211: *
212: * History:
1.1.1.3 ! root 213: * 09-09-91 Petrus Wong Created.
1.1 root 214: \***************************************************************************/
215:
1.1.1.3 ! root 216: long APIENTRY MainWndProc(
1.1 root 217: HWND hwnd,
218: UINT message,
219: DWORD wParam,
220: LONG lParam)
221: {
222: static int iSvrCount=1;
223: static int iCltCount=1;
224: CLIENTCREATESTRUCT clientcreate;
225: HWND hwndChildWindow;
226:
227:
228: switch (message) {
229:
230: case WM_CREATE:
231: SetWindowLong(hwnd, 0, (LONG)NULL);
232:
233: clientcreate.hWindowMenu = hMenuWindow;
234: clientcreate.idFirstChild = 1;
235:
1.1.1.3 ! root 236: ghwndClient = CreateWindow("MDICLIENT", NULL,
1.1 root 237: WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
238: 0,0,0,0,
239: hwnd, NULL, ghModule, (LPVOID)&clientcreate);
240: return 0L;
241:
242: case WM_DESTROY: {
243: PostQuitMessage(0);
244: return 0L;
245: }
246:
247: case WM_COMMAND:
248:
249: switch (LOWORD(wParam)) {
250: case IDM_TILE:
1.1.1.3 ! root 251: SendMessage(ghwndClient, WM_MDITILE, 0L, 0L);
1.1 root 252: return 0L;
253: case IDM_CASCADE:
1.1.1.3 ! root 254: SendMessage(ghwndClient, WM_MDICASCADE, 0L, 0L);
1.1 root 255: return 0L;
256: case IDM_ARRANGE:
1.1.1.3 ! root 257: SendMessage(ghwndClient, WM_MDIICONARRANGE, 0L, 0L);
1.1 root 258: return 0L;
259:
260: case MM_SERVER: {
261: HANDLE hNode, hHead;
262: PNODE pNode;
263: MDICREATESTRUCT mdicreate;
264:
265: hNode = LocalAlloc(LHND, (WORD) sizeof(NODE));
266: if (hNode) {
267: if ((pNode = (PNODE)LocalLock(hNode)) == NULL)
268: MessageBox(ghwndMain, "Failed in LocalLock, hNode", "Error", MB_OK);
269:
270: wsprintf((LPSTR) &(pNode->ChildWnd.CaptionBarText),
271: "Server %d", iSvrCount);
272:
273: mdicreate.szClass = "ServerClass";
274: mdicreate.szTitle = (LPTSTR)&(pNode->ChildWnd.CaptionBarText);
275: mdicreate.hOwner = ghModule;
276: mdicreate.x =
277: mdicreate.y =
278: mdicreate.cx =
279: mdicreate.cy = CW_USEDEFAULT;
280: mdicreate.style = 0l;
281: mdicreate.lParam = 0L;
282:
283: /*Create Child Window*/
284: hwndChildWindow =
1.1.1.3 ! root 285: (HANDLE) SendMessage(ghwndClient, WM_MDICREATE,
1.1 root 286: 0L,
287: (LONG)(LPMDICREATESTRUCT)&mdicreate);
288:
289: if (hwndChildWindow == NULL) {
290: MessageBox(ghwndMain, "Failed in Creating Child Window", "Error", MB_OK);
291: return 0L;
292: }
293:
1.1.1.3 ! root 294: pNode->ChildWnd.hParent = ghwndClient;
1.1 root 295: pNode->ChildWnd.hThisWnd = hwndChildWindow;
296: hHead = (HANDLE)GetWindowLong(hwnd, 0);
297: pNode->hNext = hHead;
298: SetWindowLong(hwnd, 0, (LONG) hNode);
299:
300: iSvrCount++;
301:
302:
303: LocalUnlock(hNode);
304: } else {
305: MessageBox(ghwndMain, "Failed to Allocate Node!", "Error", MB_OK);
306: }
307: return 0L;
308: }
309:
310: case MM_CLIENT: {
311: HANDLE hNode, hHead;
312: PNODE pNode;
313: MDICREATESTRUCT mdicreate;
314:
315: hNode = LocalAlloc(LHND, (WORD) sizeof(NODE));
316: if (hNode) {
317: if ((pNode = (PNODE)LocalLock(hNode))==NULL)
318: MessageBox(ghwndMain, "Failed in LocalLock, hNode!", "Error", MB_OK);
319:
320: wsprintf((LPSTR) &(pNode->ChildWnd.CaptionBarText),
321: "Client %d", iCltCount);
322:
323: mdicreate.szClass = "ClientClass";
324: mdicreate.szTitle = (LPSTR) &(pNode->ChildWnd.CaptionBarText);
325: mdicreate.hOwner = ghModule;
326: mdicreate.x =
327: mdicreate.y =
328: mdicreate.cx =
329: mdicreate.cy = CW_USEDEFAULT;
330: mdicreate.style = 0l;
331: mdicreate.lParam = 0L;
332:
333: /*Create Child Window*/
334: hwndChildWindow =
1.1.1.3 ! root 335: (HANDLE) SendMessage(ghwndClient, WM_MDICREATE,
1.1 root 336: 0L,
337: (LONG)(LPMDICREATESTRUCT)&mdicreate);
338:
339: if (hwndChildWindow == NULL) {
340: MessageBox(ghwndMain, "Failed in Creating Child Window!", "Error", MB_OK);
341: return 0L;
342: }
343:
1.1.1.3 ! root 344: pNode->ChildWnd.hParent = ghwndClient;
1.1 root 345: pNode->ChildWnd.hThisWnd = hwndChildWindow;
346: hHead = (HANDLE)GetWindowLong(hwnd, 0);
347: pNode->hNext = hHead;
348: SetWindowLong(hwnd, 0, (LONG) hNode);
349:
350: iCltCount++;
351:
352: LocalUnlock(hNode);
353:
354: } else {
355: MessageBox(ghwndMain, "Failed to Allocate Node!", "Error", MB_OK);
356: }
357: return 0L;
358: }
359:
360: case MM_ABOUT:
1.1.1.3 ! root 361: ShellAbout(ghwndMain, "Memory", "Microsoft Developer Support", NULL);
! 362:
! 363: //if (DialogBox(ghModule, "AboutBox", ghwndMain, (DLGPROC)About) == -1)
! 364: // MessageBox(ghwndMain, "DEMO: About Dialog Creation Error!", "Error", MB_OK);
1.1 root 365: return 0L;
366:
367: case MM_OPT_1:
368: case MM_OPT_2:
369: case MM_OPT_3:
370: case MM_OPT_4:
371: case MM_OPT_5:
372: case MM_OPT_6:
373: case MM_OPT_7:
374: case MM_OPT_8: {
375: HWND hActiveChild;
376:
1.1.1.3 ! root 377: hActiveChild = (HANDLE) SendMessage(ghwndClient, WM_MDIGETACTIVE, 0L, 0L);
1.1 root 378: if (hActiveChild)
379: SendMessage(hActiveChild, WM_COMMAND, wParam, lParam);
380: return 0L;
381: }
382:
383: default:
1.1.1.3 ! root 384: return DefFrameProc(hwnd, ghwndClient, message, wParam, lParam);
1.1 root 385: }
386:
387: default:
388:
1.1.1.3 ! root 389: return DefFrameProc(hwnd, ghwndClient, message, wParam, lParam);
1.1 root 390: }
391: }
392:
393: /********************************************************************\
394: * ServerWndProc
395: *
396: * History:
1.1.1.3 ! root 397: * 04-17-91 ???? Created.
! 398: * 09-09-91 Petrus Wong Rewrote.
1.1 root 399: \***************************************************************************/
400:
1.1.1.3 ! root 401: long APIENTRY ServerWndProc(
1.1 root 402: HWND hwnd,
403: UINT message,
404: DWORD wParam,
405: LONG lParam)
406: {
407: static HANDLE MapFileHandle = NULL;
408: static HANDLE hMem1 = NULL;
409: static LPVOID pShrMem1 = NULL;
410: static HANDLE hEdit;
411: static BOOL bDirty = FALSE;
412: static HWND hTextWnd;
413:
414: switch (message) {
415: case WM_COMMAND: {
416:
417: switch (LOWORD(wParam)) {
418: case MM_OPT_1: { //Create File
419:
420: SetWindowText(hTextWnd, "Creating Map File");
1.1.1.2 root 421: switch (DialogBox(ghModule, "FileType", hwnd, (DLGPROC)FileType)) {
1.1 root 422: case -1:
423: MessageBox(ghwndMain, "Server: File dialog box creation failed!", "Error", MB_OK);
424: SetWindowText(hTextWnd, "File dialog box creation failed");
425: break;
426: case IDBTN_MAP:
427: if ((MapFileHandle = (HANDLE) CreateMapFile(gszFile)) == (HANDLE)NULL) {
428: MessageBox(ghwndMain, "Server: CreateMapFile() failed!", "Error", MB_OK);
429: SetWindowText(hTextWnd, "Map File creation failed");
430: }
431: else {
432: SetWindowText(hTextWnd, "Select 'Create File Mapping...'");
433: }
434: break;
435: default:
436: MapFileHandle = (HANDLE) 0xFFFFFFFF;
437: EnableMenuItem(hServerMenu, MM_OPT_2, MF_ENABLED);
438: break;
439: }
440: return 0L;
441: }
442: case MM_OPT_2: { //Create File Mapping
443:
444: SetWindowText(hTextWnd, "Creating File Mapping");
445: if (MapFileHandle != NULL ) {
1.1.1.2 root 446: switch (DialogBox(ghModule, "MapName", hwnd, (DLGPROC)MapFileName)) {
1.1 root 447: case -1:
448: MessageBox(ghwndMain, "Server: Map dialog box creation failed!", "Error", MB_OK);
449: SetWindowText(hTextWnd, "Map dialog box creation failed");
450: break;
451: case IDBTN_OK:
452: if ((hMem1 = (HANDLE) CreateMap((HANDLE *) &MapFileHandle, gszMapName) ) == (HANDLE)NULL) {
453: MessageBox(ghwndMain, "Server: CreateMap() failed!", "Error", MB_OK);
454: SetWindowText(hTextWnd, "File Mapping creation failed");
455: }
456: else {
457: EnableMenuItem(hServerMenu, MM_OPT_3, MF_ENABLED);
458: SetWindowText(hTextWnd, "Select 'Map View of File'");
459: }
460: break;
461: default:
462: break;
463: }
464: } else {
465: MessageBox(ghwndMain, "Server: MapFileHandle is NULL!", "Error", MB_OK);
466: SetWindowText(hTextWnd, "Advice: Create server file first");
467: }
468: return 0L;
469: }
470: case MM_OPT_3: { //Map View of File
471: SetWindowText(hTextWnd, "Mapping view of File");
472: if (hMem1) {
473: if ((pShrMem1 = (LPVOID)MapView(&hMem1)) == (LPVOID)NULL) {
474: MessageBox(ghwndMain, "Server: MapView() failed!", "Error", MB_OK);
475: SetWindowText(hTextWnd, "Map view of File failed");
476: }
477: else {
478: EnableMenuItem(hServerMenu, MM_OPT_4, MF_ENABLED);
479: SetWindowText(hTextWnd, "Select 'Access' to enter text");
480: }
481: } else {
482: MessageBox(ghwndMain, "Server: Mapping view of File Failed!", "Error", MB_OK);
483: SetWindowText(hTextWnd, "Advice: Create File Mapping First");
484: }
485: return 0L;
486: }
487: case MM_OPT_4: { //Access
488: RECT rcl;
489:
490: SetWindowText(hTextWnd, "Accessing Server for writing");
491:
492: if (pShrMem1) {
493: GetClientRect(hwnd, &rcl);
494: hEdit = CreateWindow("edit", (LPSTR) NULL,
495: WS_CHILD | WS_VISIBLE | WS_HSCROLL |
496: WS_VSCROLL | WS_BORDER | ES_LEFT |
497: ES_MULTILINE | ES_AUTOHSCROLL |
498: ES_AUTOVSCROLL,
499: 0,0, rcl.right-rcl.left,
500: rcl.bottom-rcl.top-GetWindowLong(hTextWnd, GWL_USERDATA),
501: hwnd, (HMENU)1, ghModule, (LPVOID)NULL);
502: if (hEdit) {
503: SetFocus(hEdit);
504: } else {
505: MessageBox(ghwndMain, "Server: Create MLE failed!", "Error", MB_OK);
506: SetWindowText(hTextWnd, "Failed to create MLE");
507: }
508: } else {
509: MessageBox(ghwndMain, "Server: Accessing for writing Failed!", "Error", MB_OK);
510: SetWindowText(hTextWnd, "Advice: Map view of File First");
511: }
512:
513: return 0L;
514: }
515:
516: }
517:
518: switch (HIWORD(wParam)) {
519: case EN_UPDATE: {
520: if ((hEdit != NULL) && (hEdit == (HANDLE)lParam) ) {
521: bDirty = TRUE;
522: }
523: return 0L;
524: }
525: }
526:
527: }
528: case WM_TIMER:
529: if (bDirty && hEdit) {
530: HANDLE hBuf;
531: BYTE * pBuf;
532:
533: hBuf = (HANDLE) SendMessage(hEdit, EM_GETHANDLE, 0L, 0L);
534: if (hBuf) {
535: if ((pBuf = (BYTE *)LocalLock(hBuf)) == NULL) {
536: MessageBox(ghwndMain, "Can't get at Edit Control's data!", "Error", MB_OK);
537: } else {
538: strncpy(pShrMem1, pBuf, strlen(pBuf)+1);
539: bDirty = FALSE;
540: }
541: LocalUnlock(hBuf);
542: } else {
543: MessageBox(ghwndMain, "Failed in SendMessage EM_GETHANDLE!", "Error", MB_OK);
544: }
545:
546:
547: }
548: return 0L;
549:
550: case WM_SETFOCUS:
1.1.1.3 ! root 551: //if (hEdit)
! 552: //SetFocus(hEdit);
1.1 root 553: return DefMDIChildProc(hwnd, message, wParam, lParam);
554:
555: case WM_MDIACTIVATE:
556: if ((HWND) lParam == hwnd) {
557: SendMessage(GetParent(hwnd), WM_MDISETMENU,
558: (DWORD) hServerMenu,
559: (LONG) hServerMenuWindow) ;
560: DrawMenuBar(GetParent(GetParent(hwnd))) ;
1.1.1.3 ! root 561: //SetFocus(hEdit);
1.1 root 562: }
563: return 0;
564:
565: case WM_SIZE:
566: if (hEdit)
567: MoveWindow(hEdit, 0, 0,
568: LOWORD(lParam),
569: HIWORD(lParam)-GetWindowLong(hTextWnd, GWL_USERDATA),
570: TRUE);
571: MoveWindow(hTextWnd,
572: 0,
573: HIWORD(lParam) - GetWindowLong(hTextWnd, GWL_USERDATA),
574: LOWORD(lParam),
575: HIWORD(lParam), TRUE);
576:
577: return DefMDIChildProc(hwnd, message, wParam, lParam);
578:
579: case WM_CREATE: {
580: PPERWNDINFO pWndInfo;
581: PNODE pHead;
582: HANDLE hHead, hTmp;
583: RECT rect;
584:
585: GetClientRect(hwnd, &rect);
586: hTextWnd = CreateWindow("Text", NULL,
587: WS_BORDER | SS_LEFT | WS_CHILD | WS_VISIBLE,
588: 0, 0, 0, 0,
589: hwnd,
590: (HMENU) 2,
591: ghModule,
592: NULL);
593:
594: SetWindowText(hTextWnd, "Select 'Create File...'");
595:
596: // now find match
597: hHead = (HANDLE) GetWindowLong(ghwndMain, 0);
598: if (hHead) {
599: if ((pHead = (PNODE)LocalLock(hHead))==NULL)
600: MessageBox(ghwndMain, "Failed in LocalLock!", "Error", MB_OK);
601:
602: while ((pHead->ChildWnd.hThisWnd != hwnd) &&
603: (pHead->hNext != NULL)) {
604: hTmp = hHead;
605: hHead = pHead->hNext;
606: LocalUnlock(hTmp);
607: if ((pHead = (PNODE) LocalLock(hHead))==NULL)
608: MessageBox(ghwndMain, "Failed in LocalLock!", "Error", MB_OK);
609: }
610: if (pHead->ChildWnd.hThisWnd == hwnd) {
611: pWndInfo = &pHead->ChildWnd;
612: goto Wnd_Found;
613: } else {
614: //MessageBox(ghwndMain, "Trouble - Can't find the node!", "Error", MB_OK);
615: goto Wnd_Out;
616: }
617:
618: Wnd_Found:
619: if (!GetClientRect(pWndInfo->hThisWnd,
620: &pWndInfo->rcClient))
621: MessageBox(ghwndMain, "Failed in GetClientRect!", "Error", MB_OK);
622: Wnd_Out:
623: LocalUnlock(hHead);
624: return DefMDIChildProc(hwnd, message, wParam, lParam);
625: } else {
626: //MessageBox(ghwndMain, "Can't GetWindowLong(ghwndMain,0)!", "Error", MB_OK);
627: } return DefMDIChildProc(hwnd, message, wParam, lParam);
628:
629: }
630:
631: case WM_CLOSE: {
632: PPERWNDINFO pWndInfo;
633: PNODE pHead, pTrail;
634: HANDLE hHead, hTmp;
635:
636: SendMessage(GetParent(hwnd), WM_MDISETMENU,
637: (DWORD) hMenu,
638: (LONG) hMenuWindow) ;
639: DrawMenuBar(GetParent(GetParent(hwnd))) ;
640:
641:
642: // now find match
643: hHead = (HANDLE) GetWindowLong(ghwndMain, 0);
644: if (hHead) {
645: if ((pHead = (PNODE)LocalLock(hHead))==NULL)
646: MessageBox(ghwndMain, "Failed in LocalLock!", "Error", MB_OK);
647:
648: pTrail = pHead;
649: while ((pHead->ChildWnd.hThisWnd != hwnd) &&
650: (pHead->hNext != NULL)) {
651: hTmp = hHead;
652: pTrail = pHead;
653: hHead = pHead->hNext;
654: LocalUnlock(hTmp);
655: if ((pHead = (PNODE) LocalLock(hHead))==NULL)
656: MessageBox(ghwndMain, "Failed in LocalLock!", "Error", MB_OK);
657: }
658: if (pHead->ChildWnd.hThisWnd == hwnd) {
659: pWndInfo = &pHead->ChildWnd;
660: goto Wnd_Found1;
661: } else {
662: //MessageBox(ghwndMain, "Trouble - Can't find the thread node!", "Error", MB_OK);
663: goto Wnd_Out1;
664: }
665:
666: Wnd_Found1: if (pTrail == pHead)
667: SetWindowLong(ghwndMain, 0, (LONG) pHead->hNext);
668: else
669: pTrail->hNext = pHead->hNext;
670:
671: // BUG! The lock count returned is always > 0
672: //if (!LocalUnlock(hHead)) {
673: LocalFree(hHead);
674: return DefMDIChildProc(hwnd, message, wParam, lParam);
675: //}
676: Wnd_Out1:
677: LocalUnlock(hHead);
678: } else {
679: //MessageBox(ghwndMain, "Can't GetWindowLong(ghwndMain,0) !", "Error", MB_OK);
680: }
681: return DefMDIChildProc(hwnd, message, wParam, lParam);
682:
683: }
684:
685: case WM_DESTROY:
686: KillTimer(hwnd, 1);
687: return 0L;
688:
689: case WM_PAINT:
690: return DefMDIChildProc(hwnd, message, wParam, lParam);
691:
692: default:
693: return DefMDIChildProc(hwnd, message, wParam, lParam);
694: }
695:
696: }
697:
698: /********************************************************************\
699: * ClientWndProc
700: *
701: * History:
1.1.1.3 ! root 702: * 04-17-91 ???? Created.
! 703: * 09-09-91 Petrus Wong Rewrote.
1.1 root 704: \***************************************************************************/
705:
1.1.1.3 ! root 706: long APIENTRY ClientWndProc(
1.1 root 707: HWND hwnd,
708: UINT message,
709: DWORD wParam,
710: LONG lParam)
711: {
712: static HANDLE hMem1 = NULL;
713: static LPVOID pShrMem1 = NULL;
714: static HANDLE hEdit;
715: static HANDLE hTextWnd;
716:
717: switch (message) {
718: case WM_COMMAND: {
719:
720: switch (LOWORD(wParam)) {
721: case MM_OPT_5: { //Open File Mapping
722: SetWindowText(hTextWnd, "Opening Mapping File");
1.1.1.2 root 723: switch (DialogBox(ghModule, "MapName", hwnd, (DLGPROC)MapFileName)) {
1.1 root 724: case -1:
725: MessageBox(ghwndMain, "Client: Map dialog box creation failed!", "Error", MB_OK);
726: break;
727: case IDBTN_OK:
728: if ((hMem1 = (HANDLE) OpenMap(gszMapName)) == (HANDLE)NULL) {
729: MessageBox(ghwndMain, "Client: Open File Mapping failed!", "Error", MB_OK);
730: SetWindowText(hTextWnd, "Advice: Make sure Map file is created on Server");
731: } else {
732: EnableMenuItem(hClientMenu, MM_OPT_6, MF_ENABLED);
733: SetWindowText(hTextWnd, "Select 'Map View of File'");
734: }
735: break;
736: default:
737: break;
738: }
739: return 0L;
740: }
741: case MM_OPT_6: { //Map View of File
742: SetWindowText(hTextWnd, "Mapping view of File");
743: if (hMem1) {
744: if ((pShrMem1 = (LPVOID) MapView(&hMem1)) == (LPVOID)NULL)
745: MessageBox(ghwndMain, "Client: MapView() failed!", "Error", MB_OK);
746: else {
747: EnableMenuItem(hClientMenu, MM_OPT_7, MF_ENABLED);
748: SetWindowText(hTextWnd, "Select 'Access' for reading Server ");
749: }
750: } else {
751: MessageBox(ghwndMain, "Client: Mapping view of File Failed!", "Error", MB_OK);
752: SetWindowText(hTextWnd, "Advice: Open File Mapping first");
753: }
754: return 0L;
755: }
756: case MM_OPT_7: { //Access
757: RECT rcl;
758:
759: SetWindowText(hTextWnd, "Accessing Server for reading");
760: if (pShrMem1) {
761: GetClientRect(hwnd, &rcl);
762:
763: hEdit = CreateWindow("edit", NULL,
764: WS_CHILD | WS_VISIBLE | WS_HSCROLL |
765: WS_VSCROLL | WS_BORDER | ES_LEFT |
766: ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY |
767: ES_AUTOVSCROLL,
768: 0,0, rcl.right-rcl.left,
769: rcl.bottom-rcl.top-GetWindowLong(hTextWnd, GWL_USERDATA),
770: hwnd, (HMENU) 1, ghModule, NULL);
771: if (hEdit) {
1.1.1.3 ! root 772: //SetFocus(hEdit);
1.1 root 773: SendMessage(hEdit, WM_SETTEXT, 0L, (LONG)pShrMem1);
774: SetTimer(hwnd, 2, 10000, NULL);
775: EnableMenuItem(hClientMenu, MM_OPT_8, MF_ENABLED);
776: } else {
777: MessageBox(ghwndMain, "Client: Create MLE failed!", "Error", MB_OK);
778: }
779: } else {
780: MessageBox(ghwndMain, "Client: Accessing for reading Failed!", "Error", MB_OK);
781: SetWindowText(hTextWnd, "Advice: Map View of File first");
782: }
783:
784: return 0L;
785: }
786:
787: case MM_OPT_8: { // refresh now
788: HANDLE hActive;
789:
790: hActive = (HANDLE) SendMessage(GetParent(hwnd), WM_MDIGETACTIVE, 0L, 0L);
791: SendMessage(hEdit, WM_SETTEXT, 0L, (LONG)pShrMem1);
1.1.1.3 ! root 792: //SetFocus(hActive);
1.1 root 793: return 0L;
794: }
795: }
796: }
797: case WM_SETFOCUS:
1.1.1.3 ! root 798: //if (hEdit)
! 799: //SetFocus(hEdit);
1.1 root 800: return DefMDIChildProc(hwnd, message, wParam, lParam);
801:
802: case WM_TIMER: {
803: HANDLE hActive;
804:
805: if (hEdit) {
806: hActive = (HANDLE) SendMessage(GetParent(hwnd), WM_MDIGETACTIVE, 0L, 0L);
807: SendMessage(hEdit, WM_SETTEXT, 0L, (LONG)pShrMem1);
1.1.1.3 ! root 808: //SetFocus(hActive);
1.1 root 809: }
810: return 0L;
811: }
812:
813: case WM_MDIACTIVATE:
814: if ((HWND) lParam == hwnd) {
815: SendMessage(GetParent(hwnd), WM_MDISETMENU,
816: (DWORD) hClientMenu,
817: (LONG) hClientMenuWindow) ;
818: DrawMenuBar(GetParent(GetParent(hwnd))) ;
1.1.1.3 ! root 819: //SetFocus(hEdit);
1.1 root 820: }
821: return 0;
822:
823: case WM_SIZE:
824: if (hEdit)
825: MoveWindow(hEdit, 0, 0,
826: LOWORD(lParam),
827: HIWORD(lParam)-GetWindowLong(hTextWnd, GWL_USERDATA),
828: TRUE);
829: MoveWindow(hTextWnd,
830: 0,
831: HIWORD(lParam) - GetWindowLong(hTextWnd, GWL_USERDATA),
832: LOWORD(lParam),
833: HIWORD(lParam), TRUE);
834: return DefMDIChildProc(hwnd, message, wParam, lParam);
835:
836: case WM_CREATE: {
837: PPERWNDINFO pWndInfo;
838: PNODE pHead;
839: HANDLE hHead, hTmp;
840: RECT rect;
841:
842: GetClientRect(hwnd, &rect);
843: hTextWnd = CreateWindow("Text", NULL,
844: WS_BORDER | SS_LEFT | WS_CHILD | WS_VISIBLE,
845: 0, 0, 0, 0,
846: hwnd,
847: (HMENU) 2,
848: ghModule,
849: NULL);
850:
851: SetWindowText(hTextWnd, "Select 'Open File...'");
852:
853: // now find match
854: hHead = (HANDLE) GetWindowLong(ghwndMain, 0);
855: if (hHead) {
856: if ((pHead = (PNODE)LocalLock(hHead))==NULL)
857: MessageBox(ghwndMain, "Failed in LocalLock!", "Error", MB_OK);
858:
859: while ((pHead->ChildWnd.hThisWnd != hwnd) &&
860: (pHead->hNext != NULL)) {
861: hTmp = hHead;
862: hHead = pHead->hNext;
863: LocalUnlock(hTmp);
864: if ((pHead = (PNODE) LocalLock(hHead))==NULL)
865: MessageBox(ghwndMain, "Failed in LocalLock!", "Error", MB_OK);
866: }
867: if (pHead->ChildWnd.hThisWnd == hwnd) {
868: pWndInfo = &pHead->ChildWnd;
869: goto Wnd_Found;
870: } else {
871: //MessageBox(ghwndMain, "Trouble - Can't find the node!", "Error", MB_OK);
872: goto Wnd_Out;
873: }
874:
875: Wnd_Found:
876: if (!GetClientRect(pWndInfo->hThisWnd,
877: &pWndInfo->rcClient))
878: MessageBox(ghwndMain, "Failed in GetClientRect!", "Error", MB_OK);
879: Wnd_Out:
880: LocalUnlock(hHead);
881: return DefMDIChildProc(hwnd, message, wParam, lParam);
882: } else {
883: //MessageBox(ghwndMain, "Can't GetWindowLong(ghwndMain,0) !", "Error", MB_OK);
884: } return DefMDIChildProc(hwnd, message, wParam, lParam);
885:
886: }
887:
888: case WM_CLOSE: {
889: PPERWNDINFO pWndInfo;
890: PNODE pHead, pTrail;
891: HANDLE hHead, hTmp;
892:
893: SendMessage(GetParent(hwnd), WM_MDISETMENU,
894: (DWORD) hMenu,
895: (LONG) hMenuWindow) ;
896: DrawMenuBar(GetParent(GetParent(hwnd))) ;
897:
898:
899: // now find match
900: hHead = (HANDLE) GetWindowLong(ghwndMain, 0);
901: if (hHead) {
902: if ((pHead = (PNODE)LocalLock(hHead))==NULL)
903: MessageBox(ghwndMain, "Failed in LocalLock!", "Error", MB_OK);
904:
905: pTrail = pHead;
906: while ((pHead->ChildWnd.hThisWnd != hwnd) &&
907: (pHead->hNext != NULL)) {
908: hTmp = hHead;
909: pTrail = pHead;
910: hHead = pHead->hNext;
911: LocalUnlock(hTmp);
912: if ((pHead = (PNODE) LocalLock(hHead))==NULL)
913: MessageBox(ghwndMain, "Failed in LocalLock!", "Error", MB_OK);
914: }
915: if (pHead->ChildWnd.hThisWnd == hwnd) {
916: pWndInfo = &pHead->ChildWnd;
917: goto Wnd_Found1;
918: } else {
919: //MessageBox(ghwndMain, "Trouble - Can't find the thread node!", "Error", MB_OK);
920: goto Wnd_Out1;
921: }
922:
923: Wnd_Found1: if (pTrail == pHead)
924: SetWindowLong(ghwndMain, 0, (LONG) pHead->hNext);
925: else
926: pTrail->hNext = pHead->hNext;
927:
928: // BUG! The lock count returned is always > 0
929: //if (!LocalUnlock(hHead)) {
930: LocalFree(hHead);
931: return DefMDIChildProc(hwnd, message, wParam, lParam);
932: //}
933: Wnd_Out1:
934: LocalUnlock(hHead);
935: } else {
936: //MessageBox(ghwndMain, "Can't GetWindowLong(ghwndMain,0)!", "Error", MB_OK);
937: }
938: return DefMDIChildProc(hwnd, message, wParam, lParam);
939:
940: }
941:
942: case WM_DESTROY:
943: KillTimer(hwnd, 2);
944: return 0l;
945:
946: default:
947: return DefMDIChildProc(hwnd, message, wParam, lParam);
948: }
949:
950: }
951:
952: /***************************************************************************\
953: * About
954: *
955: * About dialog proc.
956: *
957: * History:
1.1.1.3 ! root 958: * 04-13-91 ???? Created.
! 959: * 09-09-91 Petrus Wong Rewrote.
1.1 root 960: \***************************************************************************/
961:
1.1.1.3 ! root 962: long APIENTRY About(
1.1 root 963: HWND hDlg,
964: UINT message,
965: DWORD wParam,
966: LONG lParam)
967: {
968: switch (message) {
969: case WM_INITDIALOG:
970: return TRUE;
971:
972: case WM_COMMAND:
973: if (wParam == IDOK)
974: EndDialog(hDlg, wParam);
975: break;
976: }
977:
978: return FALSE;
979:
980: UNREFERENCED_PARAMETER(lParam);
981: UNREFERENCED_PARAMETER(hDlg);
982: }
983:
984: /***************************************************************************\
985: * MapFileName
986: *
987: * MapFileName dialog proc.
988: *
989: * History:
1.1.1.3 ! root 990: * 09-09-91 Petrus Wong Created.
1.1 root 991: \***************************************************************************/
992:
993: long MapFileName(
994: HWND hDlg,
995: UINT message,
996: DWORD wParam,
997: LONG lParam)
998: {
999:
1000: switch (message) {
1001: case WM_INITDIALOG:
1002: return TRUE;
1003:
1004: case WM_COMMAND:
1005: switch (wParam) {
1006: case IDBTN_OK: {
1007:
1008: if ((GetDlgItemText(hDlg, IDEDIT_MAPNAME, gszMapName, 20)) == 0) {
1009: MessageBox(ghwndMain, "MapFileName: Can't get edit text!", "Error", MB_OK);
1010: strncpy(gszMapName, "MapName1", 10); // default name
1011: }
1012: EndDialog(hDlg, IDBTN_OK);
1013: break;
1014: }
1015:
1016: }
1017:
1018: }
1019:
1020: return FALSE;
1021:
1022: UNREFERENCED_PARAMETER(lParam);
1023: UNREFERENCED_PARAMETER(hDlg);
1024: }
1025:
1026: /***************************************************************************\
1027: * FileType
1028: *
1029: * FileType dialog proc.
1030: *
1031: * History:
1.1.1.3 ! root 1032: * 09-09-91 Petrus Wong Created.
1.1 root 1033: \***************************************************************************/
1034:
1035: long FileType(
1036: HWND hDlg,
1037: UINT message,
1038: DWORD wParam,
1039: LONG lParam)
1040: {
1041:
1042: switch (message) {
1043: case WM_INITDIALOG:
1044: return TRUE;
1045:
1046: case WM_COMMAND:
1047: switch (wParam) {
1048: case IDBTN_PAGE: {
1049: EndDialog(hDlg, IDBTN_PAGE);
1050: break;
1051: }
1052:
1053: case IDBTN_MAP: {
1054: if ((GetDlgItemText(hDlg, IDEDIT_MAPFILE, gszFile, 20)) == 0)
1055: EndDialog(hDlg, IDBTN_PAGE); // default to use PAGE file
1056: else
1057: EndDialog(hDlg, IDBTN_MAP);
1058:
1059: break;
1060: }
1061: }
1062:
1063: }
1064:
1065: return FALSE;
1066:
1067: UNREFERENCED_PARAMETER(lParam);
1068: UNREFERENCED_PARAMETER(hDlg);
1069: }
1070:
1071:
1072: /*************************************************************************
1073: *
1074: * TextWndProc
1075: *
1076: * Text Window proc.
1077: *
1078: * History:
1.1.1.3 ! root 1079: * 10-07-91 Petrus Wong Created.
1.1 root 1080: *
1081: \***************************************************************************/
1082:
1.1.1.3 ! root 1083: LONG APIENTRY TextWndProc (HWND hwnd, UINT message, DWORD wParam, LONG lParam)
1.1 root 1084: {
1085: static HFONT hFont = (HFONT) NULL;
1086:
1087: switch (message)
1088: {
1089: case WM_CREATE:
1090: {
1091: LOGFONT lf;
1092: HDC hDC;
1093: HFONT hOldFont;
1094: TEXTMETRIC tm;
1095: RECT rect;
1096: LONG lHeight;
1097:
1.1.1.2 root 1098: SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, FALSE);
1.1 root 1099:
1100: hDC = GetDC(hwnd);
1101: // this is the height for 8 point size font in pixels
1102: lf.lfHeight = 8 * GetDeviceCaps(hDC, LOGPIXELSY) / 72;
1103:
1104: hFont = CreateFontIndirect(&lf);
1105: hOldFont = SelectObject(hDC, hFont);
1106: GetTextMetrics(hDC, &tm);
1107: GetClientRect(GetParent(hwnd), &rect);
1108:
1109: // base the height of the window on size of text
1110: lHeight = tm.tmHeight+6*GetSystemMetrics(SM_CYBORDER)+2;
1111: // saved the height for later reference
1112: SetWindowLong(hwnd, GWL_USERDATA, lHeight);
1113: SetWindowPos(hwnd, NULL,
1114: 0,
1115: rect.bottom-lHeight,
1116: rect.right-rect.left,
1117: lHeight,
1118: SWP_NOZORDER | SWP_NOMOVE);
1119:
1120: ReleaseDC(hwnd, hDC);
1121: break;
1122: }
1123:
1124: case WM_DESTROY:
1125: if (hFont)
1126: DeleteObject(hFont);
1127: break;
1128:
1129: case WM_SETTEXT:
1130: DefWindowProc(hwnd, message, wParam, lParam);
1131: InvalidateRect(hwnd,NULL,FALSE);
1132: UpdateWindow(hwnd);
1133: return 0L;
1134:
1135: case WM_PAINT:
1136: {
1137: PAINTSTRUCT ps;
1138: RECT rc;
1139: char ach[128];
1140: int len, nxBorder, nyBorder;
1141: HFONT hOldFont = NULL;
1142:
1143: BeginPaint(hwnd, &ps);
1144:
1145: GetClientRect(hwnd,&rc);
1146:
1147: nxBorder = GetSystemMetrics(SM_CXBORDER);
1148: rc.left += 9*nxBorder;
1149: rc.right -= 9*nxBorder;
1150:
1151: nyBorder = GetSystemMetrics(SM_CYBORDER);
1152: rc.top += 3*nyBorder;
1153: rc.bottom -= 3*nyBorder;
1154:
1155: // 3D Text
1156: len = GetWindowText(hwnd, ach, sizeof(ach));
1157: SetBkColor(ps.hdc, GetSysColor(COLOR_BTNFACE));
1158:
1159: SetBkMode(ps.hdc, TRANSPARENT);
1160: SetTextColor(ps.hdc, RGB(64,96,96));
1161: if (hFont)
1162: hOldFont = SelectObject(ps.hdc, hFont);
1163: ExtTextOut(ps.hdc, rc.left+2*nxBorder+2, rc.top+2, ETO_OPAQUE | ETO_CLIPPED,
1164: &rc, ach, len, NULL);
1165:
1166: SetTextColor(ps.hdc, RGB(128,128,128));
1167: if (hFont)
1168: hOldFont = SelectObject(ps.hdc, hFont);
1169: ExtTextOut(ps.hdc, rc.left+2*nxBorder+1, rc.top+1, ETO_CLIPPED,
1170: &rc, ach, len, NULL);
1171:
1172: SetTextColor(ps.hdc, RGB(255,255,255));
1173: if (hFont)
1174: hOldFont = SelectObject(ps.hdc, hFont);
1175: ExtTextOut(ps.hdc, rc.left+2*nxBorder, rc.top, ETO_CLIPPED,
1176: &rc, ach, len, NULL);
1177:
1178: SetBkMode(ps.hdc, OPAQUE);
1179:
1180: if (hOldFont)
1181: SelectObject(ps.hdc, hOldFont);
1182:
1183: EndPaint(hwnd, &ps);
1184: return 0L;
1185: }
1186: }
1187: return DefWindowProc(hwnd, message, wParam, lParam);
1188: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.