|
|
1.1 root 1: /***************************************************************************\
2: * message.c - procecures to process the message dialog
3: *
4: * Created by Microsoft Corporation, 1989
5: \***************************************************************************/
6:
7: #define INCL_WINBUTTONS
8: #define INCL_WINDIALOGS
9: #define INCL_WINFRAMEMGR
10: #define INCL_WINHEAP /* needed for spy.h */
11: #define INCL_WININPUT
12: #define INCL_WINLISTBOXES
13: #define INCL_WINMESSAGEMGR
14: #define INCL_WINMENUS
15: #define INCL_WINPOINTERS
16: #define INCL_WINWINDOWMGR
17: #include <os2.h>
18: #include <spyhook.h>
19: #include <stdio.h>
20: #include <stdlib.h>
21: #include <string.h>
22: #include <time.h>
23: #include "spy.h"
24:
25: #define SIZEOFWND 34
26: #define MAXMSGBYTES 100
27:
28: /* Procedure prototypes */
29: void UpdMsgsLBSels (USHORT, BOOL);
30: void UpdMsgTblFromLB (HWND);
31: void ProcessQueueMsg(QMSGSPY *);
32: void SelOrDeselWithMouse(BOOL);
33: void UpdateMsgBoxCurMsgText(HWND);
34: void SelectMessageFromText(HWND);
35: MRESULT CALLBACK SpyMsgDlgProc(HWND, USHORT, MPARAM, MPARAM);
36:
37: /***************************************************************************\
38: * MRESULT CALLBACK SpyMsgDlgProc (hwnd, msg, mp1, mp2)
39: *
40: * Message List dialog procedure
41: \***************************************************************************/
42: MRESULT CALLBACK SpyMsgDlgProc(hwnd, msg, mp1, mp2)
43: HWND hwnd;
44: USHORT msg;
45: MPARAM mp1;
46: MPARAM mp2;
47: {
48: SHORT i;
49: MSGI *pmsgi;
50: USHORT item;
51: SHORT bHooksNew;
52: USHORT iItemFocus; /* Index to item that has the focus */
53:
54: switch (msg) {
55:
56: case WM_INITDLG:
57: /*
58: * Initialize the list box with the list of messages that are
59: * defined in our message table
60: */
61: iCurItemFocus = -1;
62: pmsgi = rgmsgi; /* Point to start of list */
63: hwndMessageLB = WinWindowFromID(hwnd, DID_OMSGLIST);
64: for (i = 0; i < cmsgi; i++) {
65: pmsgi->iListBox = item = (USHORT)WinSendMsg(hwndMessageLB,
66: LM_INSERTITEM,
67: (MPARAM)(spyopt.fAlphaSortMsgList? LIT_SORTASCENDING : LIT_END),
68: (MPARAM)(PSZ)pmsgi->szMsg);
69: WinSendMsg(hwndMessageLB, LM_SETITEMHANDLE, (MPARAM)item,
70: (MPARAM)i);
71: if (pmsgi->wOptions & MSGI_ENABLED) {
72: WinSendMsg(hwndMessageLB, LM_SELECTITEM, (MPARAM)item,
73: (MPARAM)TRUE);
74: }
75: pmsgi++;
76: }
77:
78: /* Initialize the Hook type record */
79: WinSendDlgItemMsg(hwnd, DID_OINPUT, BM_SETCHECK,
80: (MPARAM)(spyopt.bHooks & SPYH_INPUT)?1 : 0, 0L);
81:
82: WinSendDlgItemMsg(hwnd, DID_OSENDMSG, BM_SETCHECK,
83: (MPARAM)(spyopt.bHooks & SPYH_SENDMSG)?1 : 0, 0L);
84:
85: WinSendDlgItemMsg(hwnd, DID_OTHERMSGS, BM_SETCHECK,
86: (MPARAM)(spyopt.fDispOtherMsgs), 0L);
87:
88: WinSetFocus(HWND_DESKTOP, hwndMessageLB);
89: fTrackingListBox = TRUE;
90: return (TRUE); /* We set the focus */
91:
92: break;
93:
94: case WM_CHAR:
95: /*
96: * Handle VK_ENTER and VK_NEWLINE if our Edit control has
97: * the focus and it is a keydown
98: */
99: if (!(SHORT1FROMMP(mp1) & KC_KEYUP) &&
100: (SHORT1FROMMP(mp1) & KC_VIRTUALKEY) &&
101: ( (SHORT2FROMMP(mp2) == VK_ENTER) ||
102: (SHORT2FROMMP(mp2) == VK_NEWLINE) )) {
103:
104:
105: if (WinQueryFocus(HWND_DESKTOP, FALSE) ==
106: WinWindowFromID(hwnd, DID_MSGEDIT)) {
107: SelectMessageFromText(hwnd);
108: break;
109: }
110: }
111:
112: /* Normaly pass to dialog procedure to handle message */
113: return(WinDefDlgProc(hwnd, msg, mp1, mp2));
114: break;
115:
116: case WM_COMMAND:
117: switch (SHORT1FROMMP(mp1)) {
118: case DID_OK:
119:
120: /*
121: * Call to update the Message table select bits
122: */
123:
124: UpdMsgTblFromLB (hwnd);
125:
126: /* Setup new hook options */
127: bHooksNew = 0;
128:
129: if ((BOOL)WinSendDlgItemMsg(hwnd,
130: DID_OINPUT, BM_QUERYCHECK, 0L, 0L))
131: bHooksNew = SPYH_INPUT;
132:
133: if ((BOOL)WinSendDlgItemMsg(hwnd,
134: DID_OSENDMSG, BM_QUERYCHECK, 0L, 0L))
135: bHooksNew |= SPYH_SENDMSG;
136:
137: if (bHooksNew != spyopt.bHooks) {
138: SpyReleaseHook (FALSE); /* Dont clear queue */
139: spyopt.bHooks = bHooksNew;
140: SpyInstallHook(hab, hmqSpy, spyopt.bHooks); /* Install hook again */
141: WinSendMsg(WinWindowFromID(hwndSpyFrame, FID_MENU),
142: MM_SETITEMATTR, MPFROM2SHORT(CMD_INPUTHOOK, TRUE),
143: MPFROM2SHORT(MIA_CHECKED,
144: (spyopt.bHooks & SPYH_INPUT) ? MIA_CHECKED : 0));
145: WinSendMsg(WinWindowFromID(hwndSpyFrame, FID_MENU),
146: MM_SETITEMATTR, MPFROM2SHORT(CMD_SENDMSGHOOK, TRUE),
147: MPFROM2SHORT(MIA_CHECKED,
148: (spyopt.bHooks & SPYH_SENDMSG) ? MIA_CHECKED : 0));
149: }
150:
151: /* Fall through to DID_CANCEL */
152: case DID_CANCEL:
153: /* Now dismiss the dialog */
154: hwndMessageLB = NULL; /* Not here anymore to process */
155: fTrackingListBox = FALSE;
156: WinDismissDlg(hwnd, SHORT1FROMMP(mp1));
157: break;
158:
159: /*
160: * These case simply update the listbox with which messages are
161: * enabled
162: */
163: case DID_MALL:
164: UpdMsgsLBSels (0, TRUE);
165: break;
166: case DID_MNONE:
167: UpdMsgsLBSels (0, FALSE);
168: break;
169: case DID_MCON:
170: UpdMsgsLBSels (MSGI_KEY, TRUE);
171: break;
172: case DID_MCOFF:
173: UpdMsgsLBSels (MSGI_KEY, FALSE);
174: break;
175: case DID_MMON:
176: UpdMsgsLBSels (MSGI_MOUSE, TRUE);
177: break;
178: case DID_MMOFF:
179: UpdMsgsLBSels (MSGI_MOUSE, FALSE);
180: break;
181: case DID_MFON:
182: UpdMsgsLBSels (MSGI_FREQ, TRUE);
183: break;
184: case DID_MFOFF:
185: UpdMsgsLBSels (MSGI_FREQ, FALSE);
186: break;
187: }
188: break;
189:
190: default:
191: /*
192: * Default is to see if the listbox has changed its focus
193: * item number. If it has, then we want to display the information
194: * about the window that the listbox cursor is over. There is no
195: * legal way to do this, except to temporarily put the listbox into
196: * single selection mode and query the selection.
197: */
198: if (fTrackingListBox && (hwndMessageLB != NULL)) {
199: WinSetWindowBits(hwndMessageLB, QWL_STYLE, 0L, LS_MULTIPLESEL);
200: iItemFocus = (USHORT)WinSendMsg(hwndMessageLB, LM_QUERYSELECTION,
201: (MPARAM)LIT_FIRST, 0L);
202: WinSetWindowBits(hwndMessageLB, QWL_STYLE, LS_MULTIPLESEL,
203: LS_MULTIPLESEL);
204: if (iItemFocus != iCurItemFocus) {
205: iCurItemFocus = iItemFocus;
206: UpdateMsgBoxCurMsgText(hwnd);
207: }
208: }
209: return(WinDefDlgProc(hwnd, msg, mp1, mp2));
210: break;
211: }
212: return 0L;
213: }
214:
215:
216:
217: /***************************************************************************\
218: * void UpdateMsgBoxCurMsgText()
219: *
220: * Updates the text that is displayed in the message text line
221: \***************************************************************************/
222: void UpdateMsgBoxCurMsgText(hwndDlg)
223: HWND hwndDlg;
224: {
225: SHORT sMsgI;
226: char szTemp[80];
227:
228:
229: if (iCurItemFocus >= 0) {
230: /* Get the messge index */
231: sMsgI = (SHORT)WinSendMsg(hwndMessageLB, LM_QUERYITEMHANDLE,
232: (MPARAM)iCurItemFocus, 0L);
233: sprintf(szTemp, "0x%04x - %s", rgmsgi[sMsgI].msg,
234: rgmsgi[sMsgI].szMsg);
235: WinSetDlgItemText(hwndDlg, DID_MSGEDIT, (PSZ)szTemp);
236: } else {
237: WinSetDlgItemText(hwndDlg, DID_MSGEDIT, (PSZ)"");
238: }
239:
240: }
241:
242:
243:
244:
245: /***************************************************************************\
246: * void SelectMessageFromText(hwndDlg)
247: *
248: * Updates the text that is displayed in the message text line
249: \***************************************************************************/
250: void SelectMessageFromText(hwndDlg)
251: HWND hwndDlg;
252: {
253: char szTemp[80];
254: USHORT msg;
255: MSGI *pmsgi;
256: int i;
257:
258:
259: /* First get the edit text from the string */
260: WinQueryDlgItemText(hwndDlg, DID_MSGEDIT, sizeof(szTemp),
261: (PSZ)szTemp);
262:
263: if ((msg = UConvertStringToNum(szTemp)) != 0xffff) {
264:
265: /* We have a number, now try to find message in message table */
266: pmsgi = PmsgiFromMsg(msg);
267:
268: } else {
269: /* Assume String, Try to locate string in our table */
270: pmsgi = rgmsgi; /* Start at beginning of table */
271: /*
272: * This does simple string compares, it does not map case, nor
273: * does it trim the string.
274: */
275: for (i=0; i < cmsgi; i++) {
276: if (strcmpi(pmsgi->szMsg, szTemp) == 0)
277: break;
278: pmsgi++;
279: };
280:
281: if (i >= cmsgi)
282: pmsgi = NULL;
283: }
284:
285: /*
286: * Have a pointer to MSGI of message, or NULL if not in list.
287: */
288: if(pmsgi != NULL) {
289: /* First make sure it is visible */
290: WinSendMsg(hwndMessageLB, LM_SETTOPINDEX,
291: MPFROMSHORT(pmsgi->iListBox), (MPARAM)0L);
292:
293: /* Always set it on */
294: WinSendMsg(hwndMessageLB, LM_SELECTITEM,
295: MPFROMSHORT(pmsgi->iListBox), MPFROMSHORT(TRUE));
296:
297: } else {
298: WinAlarm(HWND_DESKTOP, WA_WARNING);
299: WinSetDlgItemText(hwndDlg, DID_MSGEDIT, (PSZ)"");
300: }
301: }
302:
303:
304:
305:
306:
307: /***************************************************************************\
308: * void UpdMsgsLBSels (USHORT uMask, fOnOrOff);
309: *
310: * Will update the selected items in the message listbox, that is
311: * displayed in the options dialog
312: \***************************************************************************/
313: void UpdMsgsLBSels (uMask, fOnOrOff)
314: USHORT uMask;
315: BOOL fOnOrOff;
316: {
317:
318: SHORT i;
319: MSGI *pmsgi;
320:
321: /*
322: * Loop through all of the items in our list, if the mask is 0 or
323: * the bit is on in the item, then update the select state in listbox
324: * defined in our message table
325: */
326: fTrackingListBox = FALSE;
327: pmsgi = rgmsgi; /* Point to start of list */
328: for (i = 0; i < cmsgi; i++) {
329: if ((uMask == 0) || (pmsgi->wOptions & uMask)) {
330: WinSendMsg(hwndMessageLB, LM_SELECTITEM,
331: (MPARAM)pmsgi->iListBox, (MPARAM)fOnOrOff);
332: }
333: pmsgi++;
334: }
335: fTrackingListBox = TRUE;
336: }
337:
338:
339:
340: /***************************************************************************\
341: * void UpdMsgTblFromLB (HWND hwndDialog);
342: *
343: * Will update the selected items in the message listbox, that is
344: * displayed in the options dialog
345: \***************************************************************************/
346: void UpdMsgTblFromLB (hwndDialog)
347: HWND hwndDialog;
348: {
349:
350: USHORT i;
351: register MSGI *pmsgi;
352: USHORT itemSel;
353:
354: /*
355: * Loop through all of the items in the list and update the selection
356: * status depending of if the item is selected in the list box or
357: * not.
358: */
359: /* First simply turn off all of the bits */
360: pmsgi = rgmsgi;
361: for (i = 0; i < cmsgi; i++) {
362: pmsgi->wOptions &= ~MSGI_ENABLED;
363: pmsgi++;
364: }
365:
366: /* Then turn on all of the selected items */
367: itemSel = (USHORT)LIT_FIRST;
368:
369: while ((itemSel = (USHORT)WinSendMsg(hwndMessageLB, LM_QUERYSELECTION,
370: (MPARAM)itemSel, 0L)) != (USHORT)LIT_NONE) {
371:
372: /* The item handle contains index in our array */
373: i = (USHORT)WinSendMsg(hwndMessageLB, LM_QUERYITEMHANDLE,
374: (MPARAM)itemSel, 0L);
375:
376: rgmsgi[i].wOptions |= MSGI_ENABLED;
377: }
378:
379: /* Get the Other message option from checkmark */
380: spyopt.fDispOtherMsgs = ((BOOL)WinSendDlgItemMsg(hwndDialog, DID_OTHERMSGS,
381: BM_QUERYCHECK, 0L, 0L));
382:
383: /* Now call function to update the hooks message list */
384: UpdateHooksMsgTable();
385: }
386:
387:
388:
389:
390: /***************************************************************************\
391: * void UpdateHooksMsgTable(void)
392: *
393: * Send the message bitmask to the hook, for interesting messages.
394: \***************************************************************************/
395: void UpdateHooksMsgTable()
396: {
397: MSGI *pmsgi;
398: UCHAR rgb[MAXMSGFILTERBYTES];
399: int i;
400: UCHAR *prgb;
401: unsigned char mask;
402:
403: /*
404: * First zero the bitmask
405: */
406: memset(rgb,'\0', MAXMSGFILTERBYTES);
407: mask = 1;
408: prgb = rgb;
409:
410: /*
411: * Loop to set the bits
412: */
413: pmsgi = rgmsgi;
414: for (i = 0; i <= MAXMSGFILTER; i++) {
415: /* If enabled, set bit in bit table */
416:
417: if (pmsgi->msg == i) {
418: if (pmsgi->wOptions & MSGI_ENABLED)
419: *prgb = pmsgi->bMPTypes | MP_ENABLED;
420:
421: pmsgi++;
422: } else {
423: /* Hole in range, set it true */
424: *prgb |= mask;
425: }
426:
427: prgb++;
428: }
429:
430: /* Now call the hook function with the new mask */
431: SpySetMessageList((char far *)rgb, spyopt.fDispOtherMsgs);
432: }
433:
434:
435:
436:
437: /***************************************************************************\
438: * EnableOrDisableMsg(BOOL fEnable)
439: *
440: * Fast way to enable or disable a particular message code. The one
441: * that is currently selected in the output listbox.
442: \***************************************************************************/
443:
444: void EnableOrDisableMsg(fEnable)
445: BOOL fEnable;
446: {
447: USHORT itemSel;
448: char szTemp[100];
449: char *psz;
450: MSGI *pmsgi;
451: SHORT i;
452:
453: itemSel = (USHORT)WinSendMsg(hwndSpyList, LM_QUERYSELECTION,
454: (MPARAM)LIT_FIRST, 0L);
455: if (itemSel == (USHORT)LIT_NONE)
456: return; /* None to process */
457:
458: /* Get the message text */
459: WinSendMsg(hwndSpyList, LM_QUERYITEMTEXT,
460: MPFROM2SHORT(itemSel, sizeof(szTemp)), (MPARAM)(PSZ)szTemp);
461:
462: /* Now lets extract the messgae string from the line */
463: psz = &szTemp[3];
464: while (*psz != ' ')
465: psz++; /* locate first blank */
466: *psz = '\0'; /* Zero terminate string */
467:
468:
469: /*
470: * Loop through all of the items in our list, until we find a
471: * string that matches our string.
472: */
473: pmsgi = rgmsgi; /* Point to start of list */
474: for (i = 0; i < cmsgi; i++) {
475: if (strcmpi(&szTemp[2], pmsgi->szMsg) == 0) {
476: /*
477: * Found our message, update the bit of the message, and
478: * call the function to let the hook know the new results
479: */
480: if (fEnable)
481: pmsgi->wOptions |= MSGI_ENABLED;
482: else
483: pmsgi->wOptions &= ~MSGI_ENABLED;
484:
485: UpdateHooksMsgTable(); /* Set Spy's Msg table */
486: return;
487: }
488: pmsgi++;
489: }
490: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.