|
|
1.1 ! root 1: /****************************** Module Header ******************************\ ! 2: * Module Name: queues.c - Spy code to manager the queue list dialog. ! 3: * ! 4: * Created: Microsoft, IBM Corporation 1990 ! 5: * ! 6: \***************************************************************************/ ! 7: ! 8: #define INCL_WIN ! 9: #define INCL_WINSYS ! 10: #define INCL_DOSPROCESS ! 11: #include <os2.h> ! 12: #include <stdio.h> ! 13: #include <string.h> ! 14: #include "spy.h" ! 15: #include "spyhk32.h" ! 16: #include <time.h> ! 17: #include <stdlib.h> ! 18: ! 19: /* This is a real hack, estimate size of WND Structure */ ! 20: #define SIZEOFWND 34 ! 21: #define MAXMSGBYTES 100 ! 22: ! 23: /************* GLOBAL VARIABLES */ ! 24: HMQ hmqDlgDisp; ! 25: SHORT chmqWatched = 0; ! 26: SHORT chmqInList = 0; ! 27: ! 28: ! 29: ! 30: /************* PROCEDURE DECLARATIONS */ ! 31: MRESULT EXPENTRY SpyQueuesDlgProc(); ! 32: ! 33: void InitQueueList(void); ! 34: void DisplayQueueInfoForWindow(HWND, HWND); ! 35: void DisplayQueueInfo(HWND, HMQ); ! 36: void SelectQueueFromText(HWND hwndDlg); ! 37: void BuildQueueWatchList(void); ! 38: ! 39: ! 40: ! 41: /**************************** Public Function ******************************\ ! 42: * MRESULT EXPENTRY SpyQueuesDlgProc(hwnd, msg, mp1, mp2) ! 43: * ! 44: * Effects: The Spy Windows Dialog procedure ! 45: * ! 46: * Return value: none ! 47: \***************************************************************************/ ! 48: MRESULT EXPENTRY SpyQueuesDlgProc(hwnd, msg, mp1, mp2) ! 49: HWND hwnd; ! 50: USHORT msg; ! 51: MPARAM mp1; ! 52: MPARAM mp2; ! 53: { ! 54: BOOL fSelect = TRUE; ! 55: SHORT cQueues; ! 56: HWND hwndPoint; ! 57: HMQ hmqDisp; ! 58: HMQ hmqItem; /* from handle of list item */ ! 59: USHORT iItemFocus; /* Index to item that has the focus */ ! 60: ! 61: switch (msg) { ! 62: ! 63: case WM_INITDLG: ! 64: /* Initialize the dialog items */ ! 65: hwndWindowLB = WinWindowFromID(hwnd, DID_WINDOWLIST); ! 66: InitQueueList(); ! 67: hmqDlgDisp = NULL; ! 68: fTrackingListBox = TRUE; ! 69: break; ! 70: ! 71: case WM_CHAR: ! 72: /* ! 73: * Handle VK_ENTER and VK_NEWLINE if our Edit control has ! 74: * the focus and it is a keydown ! 75: */ ! 76: if (!(SHORT1FROMMP(mp1) & KC_KEYUP) && ! 77: (SHORT1FROMMP(mp1) & KC_VIRTUALKEY) && ! 78: ( (SHORT2FROMMP(mp2) == VK_ENTER) || ! 79: (SHORT2FROMMP(mp2) == VK_NEWLINE) )) { ! 80: ! 81: ! 82: if (WinQueryFocus(HWND_DESKTOP, FALSE) == ! 83: WinWindowFromID(hwnd, DID_WHANDLE)) { ! 84: SelectQueueFromText(hwnd); ! 85: break; ! 86: } ! 87: } ! 88: ! 89: /* Normaly pass to dialog procedure to handle message */ ! 90: return(WinDefDlgProc(hwnd, msg, mp1, mp2)); ! 91: break; ! 92: ! 93: case WM_COMMAND: ! 94: switch (SHORT1FROMMP(mp1)) { ! 95: case DID_OK: ! 96: BuildQueueWatchList(); ! 97: ! 98: case DID_CANCEL: ! 99: /* Now dismiss the dialog */ ! 100: WinDismissDlg(hwnd, SHORT1FROMMP(mp1)); ! 101: break; ! 102: case DID_WUNSELALL: ! 103: fSelect = FALSE; ! 104: case DID_WSELALL: ! 105: cQueues = (SHORT) WinSendMsg(hwndWindowLB, LM_QUERYITEMCOUNT, ! 106: 0L, 0L); ! 107: ! 108: fTrackingListBox = FALSE; ! 109: while (cQueues) { ! 110: /* Loop through all windows, selecting or unselcting all */ ! 111: WinSendMsg(hwndWindowLB, LM_SELECTITEM, (MPARAM)--cQueues, ! 112: (MPARAM)fSelect); ! 113: } ! 114: fTrackingListBox = TRUE; ! 115: break; ! 116: ! 117: case DID_WSELMOUSE: ! 118: /* Call function to track mouse, returns window handle */ ! 119: hwndPoint = HwndSelWinWithMouse(hwnd, DisplayQueueInfoForWindow, ! 120: FALSE); ! 121: if (hwndPoint == NULL) ! 122: break; /* No window to process */ ! 123: ! 124: /* ! 125: * Now find the window in the list, Make the item visible ! 126: * and set the item as selected. ! 127: */ ! 128: hmqDisp = (HMQ)WinQueryWindowULong(hwndPoint, QWL_HMQ); ! 129: cQueues = (SHORT) WinSendMsg(hwndWindowLB, LM_QUERYITEMCOUNT, ! 130: 0L, 0L); ! 131: ! 132: while (cQueues) { ! 133: /* ! 134: * Loop through all windows until we wind the right ! 135: * one with the correct window handle ! 136: */ ! 137: hmqItem = (HMQ)WinSendMsg(hwndWindowLB, LM_QUERYITEMHANDLE, ! 138: (MPARAM)--cQueues, 0L); ! 139: ! 140: if (hmqItem == hmqDisp) { ! 141: /* found the right item, move it to top */ ! 142: WinSendMsg(hwndWindowLB, LM_SETTOPINDEX, (MPARAM)cQueues, 0L); ! 143: WinSendMsg(hwndWindowLB, LM_SELECTITEM, (MPARAM)cQueues, ! 144: (MPARAM)TRUE); ! 145: break; ! 146: } ! 147: } ! 148: break; ! 149: } ! 150: break; ! 151: ! 152: ! 153: default: ! 154: /* ! 155: * Default is to see if the listbox has changed its focus ! 156: * item number. If it has, then we want to display the information ! 157: * about the window that the listbox cursor is over. There is no ! 158: * legal way to do this, One approach appears to temporary set the ! 159: * listbox to be a single selection listbox, then query its selection ! 160: * and set it back into multiple selection mode. ! 161: */ ! 162: if (fTrackingListBox && hwndWindowLB != NULL) { ! 163: ! 164: WinSetWindowBits(hwndWindowLB, QWL_STYLE, 0L, LS_MULTIPLESEL); ! 165: iItemFocus = (USHORT)WinSendMsg(hwndWindowLB, LM_QUERYSELECTION, ! 166: (MPARAM)LIT_FIRST, 0L); ! 167: WinSetWindowBits(hwndWindowLB, QWL_STYLE, LS_MULTIPLESEL, ! 168: LS_MULTIPLESEL); ! 169: ! 170: if (iItemFocus != iCurItemFocus) { ! 171: iCurItemFocus = iItemFocus; ! 172: if (iItemFocus != (USHORT)-1) { ! 173: ! 174: hmqDisp = (HMQ)WinSendMsg(hwndWindowLB, LM_QUERYITEMHANDLE, ! 175: (MPARAM)iItemFocus, 0L); ! 176: DisplayQueueInfo(hwnd, hmqDisp); ! 177: } ! 178: } ! 179: } ! 180: return(WinDefDlgProc(hwnd, msg, mp1, mp2)); ! 181: } ! 182: return 0L; ! 183: } ! 184: ! 185: ! 186: ! 187: ! 188: /**************************** Private Function ******************************\ ! 189: * InitQueueList () ! 190: * ! 191: * Effects: Builds the list of Queues displayed in the queues dialog ! 192: * ! 193: * ! 194: * Return value: ! 195: \***************************************************************************/ ! 196: void InitQueueList() ! 197: { ! 198: HENUM henum; ! 199: char szClassName[50]; /* Class name of window */ ! 200: HWND hwnd; ! 201: ULONG ulHMQ; ! 202: PID pidWindow; ! 203: TID tidWindow; ! 204: SHORT item; ! 205: HMQ *ahmqWatched; ! 206: HMQ *phmqT; ! 207: SHORT chmqAlloc; ! 208: SHORT i; ! 209: ! 210: /* ! 211: * We will enumerate through all of the OBJECT windows looking for ! 212: * windows that have the WC_QUEUE type. ! 213: */ ! 214: if (chmqWatched > 0) { ! 215: ahmqWatched = (HMQ *)WinAllocMem(hHeap, sizeof(HMQ) * chmqWatched); ! 216: chmqAlloc = chmqWatched; ! 217: if (ahmqWatched != NULL) ! 218: chmqWatched = SpyGetQueueList(chmqWatched, ahmqWatched); ! 219: } else ! 220: ahmqWatched = NULL; ! 221: ! 222: henum = WinBeginEnumWindows(HWND_OBJECT); ! 223: if (henum == NULL) ! 224: return; ! 225: ! 226: chmqInList = 0; ! 227: while ((hwnd = WinGetNextWindow(henum)) != NULL) { ! 228: WinLockWindow(hwnd, FALSE); ! 229: WinQueryClassName(hwnd, sizeof(szClassName), ! 230: (PSZ)szClassName); ! 231: ! 232: if (strcmp(szClassName, "#32767") == 0) { ! 233: /* ! 234: * We found an HMQ, add it to our list, Do not add our own ! 235: * HMQ to the list!. ! 236: */ ! 237: ulHMQ = (ULONG)WinQueryWindowULong(hwnd, QWL_HMQ); ! 238: if ((HMQ)ulHMQ != hmqSpy) { ! 239: WinQueryWindowProcess(hwnd, &pidWindow, &tidWindow); ! 240: ! 241: /* Reuse szClassName */ ! 242: sprintf(szClassName, "0x%04x (PID:%d TID:%d)", ! 243: (USHORT)ulHMQ, (SHORT)pidWindow, (SHORT)tidWindow); ! 244: ! 245: item = (USHORT)WinSendMsg(hwndWindowLB, LM_INSERTITEM, ! 246: (MPARAM)LIT_END, (MPARAM)(PSZ)szClassName); ! 247: ! 248: /* Set the item handle to the handle of the window */ ! 249: WinSendMsg(hwndWindowLB, LM_SETITEMHANDLE, (MPARAM)item, ! 250: (MPARAM)ulHMQ); ! 251: chmqInList++; ! 252: ! 253: /* ! 254: * Now see if we should select the item ! 255: */ ! 256: if (phmqT = ahmqWatched) { ! 257: for (i = 0; i < chmqWatched; i++) { ! 258: if ((HMQ)ulHMQ == *phmqT++) { ! 259: WinSendMsg(hwndWindowLB, LM_SELECTITEM, (MPARAM)item, ! 260: (MPARAM)TRUE); ! 261: break; ! 262: } ! 263: } ! 264: } ! 265: } ! 266: } ! 267: ! 268: } ! 269: ! 270: WinEndEnumWindows(henum); ! 271: ! 272: if (ahmqWatched) ! 273: WinFreeMem(hHeap, (char *)ahmqWatched, chmqAlloc * sizeof(HMQ)); ! 274: } ! 275: ! 276: ! 277: ! 278: /**************************** Private Function *****************************\ ! 279: * DisplayQueueInfoForWindow(HWND hwndDialog, HWND hwnd) ! 280: * ! 281: * Effects: Displays the information about the selected window in the dialog ! 282: * ! 283: * ! 284: * Return value: ! 285: \***************************************************************************/ ! 286: void DisplayQueueInfoForWindow(hwndDlg, hwndDisp) ! 287: HWND hwndDlg; ! 288: HWND hwndDisp; ! 289: { ! 290: HMQ hmqDisp; ! 291: ! 292: /* simply get the HMQ for the window and call display function */ ! 293: hmqDisp = (HMQ)WinQueryWindowULong(hwndDisp, QWL_HMQ); ! 294: DisplayQueueInfo(hwndDlg, hmqDisp); ! 295: } ! 296: ! 297: ! 298: ! 299: ! 300: /**************************** Private Function *****************************\ ! 301: * DisplayQueueInfo(HWND hwndDialog, HWND hwnd) ! 302: * ! 303: * Effects: Displays the information about the selected window in the dialog ! 304: * ! 305: * ! 306: * Return value: ! 307: \***************************************************************************/ ! 308: void DisplayQueueInfo(hwndDlg, hmqDisp) ! 309: HWND hwndDlg; ! 310: HMQ hmqDisp; ! 311: { ! 312: HWND hwnd; ! 313: HMQ hmqWindow; ! 314: HENUM henum; ! 315: char szTemp[50]; ! 316: PID pidWindow; ! 317: TID tidWindow; ! 318: ! 319: ! 320: if (hmqDisp != hmqDlgDisp) ! 321: { ! 322: hmqDlgDisp = hmqDisp; ! 323: ! 324: /* ! 325: * See if we can find a top level window for this HMQ ! 326: */ ! 327: henum = WinBeginEnumWindows(HWND_DESKTOP); ! 328: if (henum == NULL) ! 329: return; ! 330: ! 331: while ((hwnd = WinGetNextWindow(henum)) != NULL) { ! 332: WinLockWindow(hwnd, FALSE); ! 333: hmqWindow = (HMQ)WinQueryWindowULong(hwnd, QWL_HMQ); ! 334: ! 335: if (hmqWindow == hmqDisp) ! 336: break; ! 337: } ! 338: WinEndEnumWindows(henum); ! 339: ! 340: ! 341: if (hwnd == NULL) { ! 342: /* ! 343: * No top level windows found look for object window. ! 344: */ ! 345: henum = WinBeginEnumWindows(HWND_OBJECT); ! 346: if (henum == NULL) ! 347: return; ! 348: ! 349: while ((hwnd = WinGetNextWindow(henum)) != NULL) { ! 350: WinLockWindow(hwnd, FALSE); ! 351: hmqWindow = (HMQ)WinQueryWindowULong(hwnd, QWL_HMQ); ! 352: ! 353: if (hmqWindow == hmqDisp) ! 354: break; ! 355: } ! 356: WinEndEnumWindows(henum); ! 357: if (hwnd == NULL) ! 358: return; ! 359: } ! 360: ! 361: /* output information to window now */ ! 362: sprintf(szTemp, "0x%04x", (SHORT)hmqDisp); ! 363: WinSetDlgItemText(hwndDlg, DID_WHMQ, (PSZ)szTemp); ! 364: ! 365: sprintf(szTemp, "0x%04x", (SHORT)hwnd); ! 366: WinSetDlgItemText(hwndDlg, DID_WHANDLE, (PSZ)szTemp); ! 367: ! 368: /* ! 369: * Warning, we only query the text if the window is not an object ! 370: * window. If it is an object window, the message queue may not ! 371: * be processing messages, which could hang us ! 372: */ ! 373: if (WinIsChild(hwnd, HWND_OBJECT)) ! 374: szTemp[0] = '\0'; /* No text available */ ! 375: else ! 376: WinQueryWindowText(hwnd, sizeof(szTemp), (PSZ)szTemp); ! 377: WinSetDlgItemText(hwndDlg, DID_WTEXT, (PSZ)szTemp); ! 378: ! 379: WinQueryWindowProcess(hwnd, &pidWindow, &tidWindow); ! 380: sprintf(szTemp, "%d", (SHORT)pidWindow); ! 381: WinSetDlgItemText(hwndDlg, DID_WPID, (PSZ)szTemp); ! 382: sprintf(szTemp, "%d", (SHORT)tidWindow); ! 383: WinSetDlgItemText(hwndDlg, DID_WTID, (PSZ)szTemp); ! 384: } ! 385: } ! 386: ! 387: ! 388: ! 389: /***************************** Private Function ****************************\ ! 390: * void SelectQueueFromText(hwndDlg) ! 391: * ! 392: * Effects: ! 393: * Updates the text that is displayed in the message text line ! 394: * ! 395: * History: ! 396: * 27-September-1988 KurtE ! 397: \***************************************************************************/ ! 398: void SelectQueueFromText(hwndDlg) ! 399: HWND hwndDlg; ! 400: { ! 401: char szTemp[80]; ! 402: HMQ hmqSelect; ! 403: SHORT cItems; ! 404: SHORT i; ! 405: ! 406: ! 407: /* First get the edit text from the string */ ! 408: WinQueryDlgItemText(hwndDlg, DID_WHANDLE, sizeof(szTemp), ! 409: (PSZ)szTemp); ! 410: ! 411: hmqSelect = (HMQ)UConvertStringToNum(szTemp); ! 412: ! 413: cItems = (SHORT)WinSendMsg(hwndWindowLB, LM_QUERYITEMCOUNT, ! 414: 0L, 0L); ! 415: ! 416: for (i=0; i < cItems; i++) { ! 417: if ((HMQ)WinSendMsg(hwndWindowLB, LM_QUERYITEMHANDLE, ! 418: (MPARAM)i, 0L) == hmqSelect) ! 419: break; /* found it */ ! 420: } ! 421: ! 422: if (i < cItems) { ! 423: /* ! 424: * found the hmq, bring to top, and select it ! 425: */ ! 426: WinSendMsg(hwndWindowLB, LM_SETTOPINDEX, ! 427: MPFROMSHORT(i), (MPARAM)0L); ! 428: ! 429: /* Always set it on */ ! 430: WinSendMsg(hwndWindowLB, LM_SELECTITEM, ! 431: MPFROMSHORT(i), MPFROMSHORT(TRUE)); ! 432: ! 433: } else { ! 434: WinAlarm(HWND_DESKTOP, WA_WARNING); ! 435: WinSetDlgItemText(hwndDlg, DID_WHANDLE, (PSZ)""); ! 436: } ! 437: ! 438: } ! 439: ! 440: ! 441: ! 442: ! 443: /**************************** Private Function *****************************\ ! 444: * BuildQueueWatchList() ! 445: * ! 446: * Effects: Updates the list of windows to be watched from the listbox ! 447: * ! 448: * ! 449: * Return value: ! 450: \***************************************************************************/ ! 451: void BuildQueueWatchList() ! 452: { ! 453: ! 454: USHORT itemPrevious; ! 455: USHORT item; ! 456: ! 457: HMQ *ahmqList; ! 458: HMQ *phmqT; ! 459: ! 460: ! 461: ahmqList = (HMQ *)WinAllocMem(hHeap, sizeof(HMQ) * chmqInList); ! 462: if ((phmqT = ahmqList) == NULL) ! 463: return; /* Error */ ! 464: ! 465: ! 466: /* ! 467: * Simply loop through asking for the next selected item in the ! 468: * list. Make sure not to overrun our list. ! 469: */ ! 470: itemPrevious = (USHORT)LIT_FIRST; ! 471: chmqWatched = 0; ! 472: ! 473: while ((item = (USHORT)WinSendMsg(hwndWindowLB, LM_QUERYSELECTION, ! 474: (MPARAM)itemPrevious, 0L)) != (USHORT)LIT_NONE) { ! 475: /* ! 476: * Get the items handle, which has the value of the window handle ! 477: */ ! 478: *phmqT++ = (HMQ)WinSendMsg(hwndWindowLB, LM_QUERYITEMHANDLE, ! 479: (MPARAM)item, 0L); ! 480: chmqWatched++; ! 481: ! 482: itemPrevious = item; /* Where to cointinue the search */ ! 483: } ! 484: ! 485: SpySetQueueList (chmqWatched, ahmqList); ! 486: ! 487: WinFreeMem(hHeap, (char *)ahmqList, sizeof(HMQ) * chmqInList); ! 488: } ! 489:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.