|
|
1.1 root 1: #include "cardfile.h"
2:
3:
4: /*********************************************************************/
5: /* Windows/PM Cardfile Shared Code */
6: /* */
7: /* (c) Copyright Microsoft Corp. 1987,1988 - All Rights Reserved */
8: /*********************************************************************/
9:
10: /*********************************************************************/
11: /* The following shared code was developed from the original */
12: /* Cardfile application. This code can be compiled to run under */
13: /* either the Windows or the PM manager environment. All */
14: /* functionality associated with bitmaps or printing has been */
15: /* deleted. Some comments refering to these functions may still be */
16: /* present in the code and should be disregarded. jw. */
17: /*********************************************************************/
18:
19:
20: /*********************************************************************/
21: /* CardfileWndProc - */
22: /* This routine processes messages to the main card window in */
23: /* both Cardfile and Phonebook mode. */
24: /* */
25: /* Substantially different in PM and Windows */
26: /*********************************************************************/
27:
28: /* this is the main Window Procedure for cardfile's window */
29: long far PASCAL CardfileWndProc(hwnd, message, wParam, lParam)
30: HWND hwnd;
31: unsigned message;
32: WINWORD wParam;
33: DWORD lParam;
34: {
35: PAINTSTRUCT ps;
36: LPCARDHEADER lpCards;
37: int range;
38: HMENU hMenu;
39: char buf[30];
40: HDC hDC;
41: MSG msg;
42: RECT rect;
43: int y;
44:
45: switch (message)
46: {
47: case WM_CREATE:
48: /* save the window handle */
49: hCardfileWnd = hwnd;
50:
51: #ifdef IN_WINDOWS
52: /* In PM, the style for the about box is to have the about */
53: /* Command separated from the last item in the first menu */
54: /* In other words, using ChangeMenu is unneccessary in PM */
55:
56: /* add "About" to the system menu */
57: hMenu = GetSystemMenu(hwnd, FALSE);
58: ChangeMenu(hMenu, 0, (LPSTR)NULL, -1, MF_APPEND | MF_SEPARATOR);
59: LoadString(hCardfileInstance, IDS_ABOUT, (LPSTR)buf, 30);
60: ChangeMenu(hMenu, 0, (LPSTR)buf, IDM_ABOUT, MF_APPEND | MF_STRING);
61: #endif
62:
63: /* set the caption */
64: SetCaption();
65:
66: /* initialize the scroll bars */
67: /* Use macro which sets Range and Pos all at once */
68: SCROLL_RANGE(hwnd, SB_HORZ, 0, 0, cCards-1);
69: SCROLL_RANGE(hwnd, SB_VERT, 0, 0, 0);
70: break;
71:
72: case WM_LBUTTONDOWN:
73: case WM_LBUTTONDBLCLK:
74: /* handle mouse input */
75: #ifndef IN_WINDOWS
76: /* In PM, mouse point comes in wParam, just move to lParam */
77: lParam = wParam;
78: #endif
79: CardfileMouse(hwnd, message, MAKEPOINT(lParam));
80: break;
81:
82: #ifdef IN_WINDOWS
83: /* In PM, ignore EndSession stuff. In PM, application will */
84: /* receive close message and can prompt user whether to close */
85: /* or not */
86:
87: case WM_ENDSESSION:
88: /* windows is about to close down */
89: if (wParam)
90: /* make sure temp file goes away */
91: Fdelete(TmpFile);
92: break;
93:
94: case WM_QUERYENDSESSION:
95: /* windows is asking if it is ok to close down */
96: /* if there are changes in cardfile, ask if user wants to */
97: /* save them, and give user a chance to cancel end session */
98: if (MaybeSaveFile())
99: {
100: /* user says it's ok to end session. make sure that */
101: /* cardfile is in a position to continue in case user */
102: /* cancels end session from some other application */
103: SetCurCard(iFirstCard);
104: return(TRUE);
105: }
106: else
107: /* user cancelled. Tell windows not to end session */
108: return(FALSE);
109: break;
110:
111: #endif
112: case WM_CLOSE:
113:
114: /* user is trying to close cardfile's window */
115: /* if changes in cardfile, ask user if he wants to save, or */
116: /* wants to cancel close */
117: if (MaybeSaveFile())
118: {
119: /* everything is ok to close */
120: /* ok, time to quit */
121:
122: /* The PostQuitMessage doesn't haven't enough information, */
123: /* i.e. the window handle, to remap it into WinPostMsg. */
124: /* Therefore, use separate compilation. */
125:
126: #ifdef IN_WINDOWS
127: PostQuitMessage(0);
128: #else
129: WinPostMsg(hwnd, WM_QUIT, 0L, 0L);
130: #endif
131: }
132: return(TRUE);
133:
134: case WM_DESTROY:
135: /* cardfile's window is going away: clean up */
136: /* get rid of temp file */
137: Fdelete(TmpFile);
138:
139: /* if last instance of cardfile, get rid of brushes */
140: /* if not last instance, then other's will still use them */
141:
142: /* The idea of the last instance and shared data between */
143: /* instances are windows concepts only. Also, for PM, this */
144: /* application doesn't allocate memory for brushes */
145:
146: #ifdef IN_WINDOWS
147: if (GetModuleUsage(hCardfileInstance) == 1)
148: {
149: DeleteObject(hbrGray);
150: DeleteObject(hbrBack);
151: DeleteObject(hbrLine);
152: }
153: #endif
154: return(TRUE);
155:
156: case WM_INITMENU:
157: /* the user has clicked on a menu. Enable and check everything*/
158: /* that should be, before the menu is actually brought up */
159: UpdateMenu();
160: break;
161:
162: case WM_COMMAND:
163: /* one of three things */
164: /* the edit control may be reporting that it has run out of */
165: /* memory and can't accept any more input */
166:
167: /* For Windows version, check lParam in if statement */
168: /* For PM version, don't worry about check, just compile */
169: /* statement in else clause */
170:
171: #ifdef IN_WINDOWS
172: if (LOWORD(lParam) == hCardWnd && HIWORD(lParam) == EN_ERRSPACE)
173: CardfileOkError(IDS_EINSMEMORY);
174: else
175: #endif
176: /* or, the common thing, the user has executed a menu command */
177: CardfileInput(hwnd, LOUSHORT(wParam));
178: break;
179:
180: /* In PM version, don't worry about background color of */
181: /* edit control. It should always be white anyway. */
182:
183: #ifdef IN_WINDOWS
184: case WM_CTLCOLOR:
185: /* this message gives cardfile a chance to set the background */
186: /* color of the edit control, which should always be white */
187: if (LOWORD(lParam) == hCardWnd)
188: {
189: SetBkColor((HDC)wParam, 0x00ffffff);
190: SetTextColor((HDC)wParam, 0L);
191: return((long)hbrWhite);
192: }
193: /* if not edit control, pass message on */
194: goto CallDefProc;
195: #endif
196:
197: /* In Windows, process erase background message. In PM, */
198: /* the 'equivalent' message really isn't the same. The */
199: /* PM message is sent when the frame window needs to be */
200: /* erased; in response to the repainting of any of the */
201: /* control windows, not just the client area. In PM, */
202: /* it's easier (safer) to erase the client area when a */
203: /* WM_PAINT message comes. */
204:
205: #ifdef IN_WINDOWS
206: case WM_ERASEBKGND:
207: /* paint the background, which will be BLUE or GRAY */
208: CardfileEraseBkGnd(hwnd, (HDC)wParam);
209: break;
210: #endif
211:
212: case WM_PAINT:
213: /* Time to paint, either a phonebook paint, */
214: /* or a cardfile paint */
215: BeginPaint(hwnd, (LPPAINTSTRUCT)&ps);
216:
217: /* See comment for WM_ERASEBKGND message. In PM, erase */
218: /* client area background when WM_PAINT message comes */
219: #ifndef IN_WINDOWS
220: CardfileEraseBkGnd(hwnd, ps.hdc);
221: #endif
222:
223: if (CardPhone == IDM_PHONEBOOK)
224: PhonePaint(hwnd, ps.hdc);
225: else
226: CardfilePaint(hwnd, ps.hdc);
227:
228: EndPaint(hwnd, (LPPAINTSTRUCT)&ps);
229: break;
230:
231: case WM_SIZE:
232:
233: /* the main window has changed size */
234: CardfileSize(hwnd, LOWORD(lParam), HIWORD(lParam));
235: break;
236:
237: case WM_HSCROLL:
238: /* there is a horizontal scroll bar only in cardfile mode */
239:
240: /* In PM, Scroll message is similar except that command is */
241: /* the low word of lParam instead of wParam */
242: #ifndef IN_WINDOWS
243: wParam = (long) HIUSHORT(lParam);
244: #endif
245: CardfileScroll(hwnd, LOUSHORT(wParam), LOWORD(lParam));
246: break;
247:
248: case WM_VSCROLL:
249: /* the vertical scroll bar only appears in phonebook mode */
250:
251: /* In PM, Scroll message is similar except that command is */
252: /* the low word of lParam instead of wParam */
253: #ifndef IN_WINDOWS
254: wParam = (long) HIUSHORT(lParam);
255: #endif
256: PhoneScroll(hwnd, LOUSHORT(wParam), LOWORD(lParam));
257: break;
258:
259: case WM_CHAR:
260: /* handle character input for phonebook mode. */
261:
262: if(CardPhone != IDM_PHONEBOOK)
263: break;
264:
265: /* In Windows, the WM_CHAR message contains only valid */
266: /* characters, so just send the message to the char */
267: /* routine. */
268: #ifdef IN_WINDOWS
269: if (GetKeyState(VK_CTRL))
270: CardChar(wParam);
271: #else
272: /* In PM, WM_CHAR message may contain a ascii char, system */
273: /* char, key up or key down message. Need to distinguish */
274: /* between the cases. */
275:
276: /* If key up or dead key, ignore */
277: if (wParam & (KC_KEYUP | KC_DEADKEY))
278: break;
279:
280: /* If virtual key is valid, check if arrow or PGUP */
281: if (wParam & KC_VIRTUALKEY)
282: if (PhoneKey(hwnd, HIUSHORT(lParam)))
283: return( TRUE );
284:
285: /* If ctrl-char valid, check if first letter in index line */
286: if ((wParam & KC_CHAR) && (wParam & KC_CTRL))
287: if (CardChar(LOUSHORT(lParam)))
288: return( TRUE );
289: #endif
290: break;
291:
292: /* WM_KEYDOWN message is handled through WM_CHAR message in */
293: /* PM. */
294:
295: #ifdef IN_WINDOWS
296: case WM_KEYDOWN:
297: /* handle keys. Again, this will only come through when */
298: /* cardfile is in phonebook mode */
299: PhoneKey(hwnd, wParam);
300: break;
301: #endif
302:
303: case WM_ACTIVATE:
304: /* activate, and set focus to either edit control, or main window*/
305: /* depending upon which mode we are in */
306:
307: if (LOUSHORT(wParam))
308: if (CardPhone == IDM_CARDFILE)
309: SetFocus(hCardWnd);
310: else
311: SetFocus(hCardfileWnd);
312: break;
313:
314: /* In PM, KillFocus message is incorporated in SetFocus message. */
315: /* Because all that is done for the SetFocus or KillFocus message is */
316: /* to toggle the hilight state, just add extra case for Windows */
317: /* version */
318:
319: case WM_SETFOCUS:
320: #ifdef IN_WINDOWS
321: case WM_KILLFOCUS:
322: #endif
323: /* if in phonebook, take down highlighting */
324: if(CardPhone == IDM_PHONEBOOK)
325: {
326: hDC = GetDC(hCardfileWnd);
327: y = (iFirstCard - iTopCard) * CharFixHeight;
328: TRANSLATE_COORDS( cyMainWindow );
329:
330: SetRect((LPRECT)&rect, 0, y, (LINELENGTH+2) * CharFixWidth,
331: y+CharFixHeight);
332:
333: TRANSLATE_RECT( rect );
334:
335: InvertRect(hDC, (LPRECT)&rect);
336: ReleaseDC(hCardfileWnd, hDC);
337:
338: TRANSLATE_COORDS( 0 );
339: }
340: break;
341:
342: /* In PM, the about box is not in the system menu so ignore this */
343: #ifdef IN_WINDOWS
344: case WM_SYSCOMMAND:
345: /* user has chosen ABOUT, put up dialog */
346: if (wParam == IDM_ABOUT)
347: {
348: CardfileInput(hwnd, wParam);
349: break;
350: }
351: #endif
352:
353: default:
354: /* some other message, let default handler take care of it */
355: CallDefProc:
356: return(DefWindowProc(hwnd, message, wParam, lParam));
357: break;
358: }
359: return(0L);
360: }
361:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.