Annotation of mstools/samples/sdktools/spy/app/dialogs.c, revision 1.1

1.1     ! root        1: 
        !             2: /******************************************************************************\
        !             3: *       This is a part of the Microsoft Source Code Samples. 
        !             4: *       Copyright (C) 1993 Microsoft Corporation.
        !             5: *       All rights reserved. 
        !             6: *       This source code is only intended as a supplement to 
        !             7: *       Microsoft Development Tools and/or WinHelp documentation.
        !             8: *       See these sources for detailed information regarding the 
        !             9: *       Microsoft samples programs.
        !            10: \******************************************************************************/
        !            11: 
        !            12: /*****************************************************************************\
        !            13: *
        !            14: * Module: dialogs.c
        !            15: *
        !            16: *   Contains dialog procs for the Windows debugging Spy SDK applet.
        !            17: *
        !            18: * Functions:
        !            19: *
        !            20: *   MyDialogBox()
        !            21: *   AboutDlgProc()
        !            22: *   SelectWindowDlgProc()
        !            23: *   OutputDlgProc()
        !            24: *   SelectFont()
        !            25: *   MessagesDlgProc()
        !            26: *   SelectWindowCommand()
        !            27: *   FillListBox()
        !            28: *   AddOneWindow()
        !            29: *   MakeWindowName()
        !            30: *   FindHwndInListBox()
        !            31: *   HighlightWindow()
        !            32: *   SelectWindowUpdateInfo()
        !            33: *   SelectWindowEnableFields()
        !            34: *   OutputCommand()
        !            35: *   MessagesInit()
        !            36: *   MessagesCommand()
        !            37: *   MessagesUpdateCheckBoxes()
        !            38: *
        !            39: * Comments:
        !            40: *
        !            41: \*****************************************************************************/
        !            42: 
        !            43: #include "spy.h"
        !            44: 
        !            45: #include <commdlg.h>
        !            46: 
        !            47: 
        !            48: #define DINV                3
        !            49: 
        !            50: 
        !            51: PRIVATE HWND ghwndSpyingOnTemp;     // Temp when selecting hwnd to spy on.
        !            52: PRIVATE HWND ghwndDlgBeingFilled = NULL;
        !            53: PRIVATE BOOL bBorderOn = FALSE;
        !            54: PRIVATE INT gcItemsSave;
        !            55: 
        !            56: 
        !            57: PRIVATE BOOL SelectWindowCommand(HWND hwnd, INT nCmd, INT nNotifyCode);
        !            58: PRIVATE VOID FillListBox(HWND hDlg, HWND hwndList, HWND hwnd);
        !            59: BOOL CALLBACK AddOneWindow(HWND hwnd, HWND hwndList);
        !            60: PRIVATE VOID MakeWindowName(HWND hwnd, LPSTR lpString, INT nStringLen);
        !            61: PRIVATE INT FindHwndInListBox(HWND hwndList, HWND hSpyWnd);
        !            62: PRIVATE VOID HighlightWindow(HWND hwnd, BOOL fDraw);
        !            63: PRIVATE VOID SelectWindowUpdateInfo(HWND hDlg, HWND hwnd);
        !            64: PRIVATE VOID SelectWindowEnableFields(HWND hwnd, BOOL fEnable);
        !            65: PRIVATE BOOL OutputCommand(HWND hwnd, INT nCmd, INT nNotifyCode);
        !            66: PRIVATE VOID MessagesInit(HWND hwnd);
        !            67: PRIVATE BOOL MessagesCommand(HWND hwnd, INT nCmd, INT nNotifyCode);
        !            68: PRIVATE VOID MessagesUpdateCheckBoxes(HWND hwnd);
        !            69: 
        !            70: 
        !            71: CHAR szConsoleWindowClass[] = "ConsoleWindowClass";
        !            72: 
        !            73: /*****************************************************************************\
        !            74: * MyDialogBox
        !            75: *
        !            76: * Puts up the specified dialog.
        !            77: *
        !            78: * Arguments:
        !            79: *   INT idDlg          - The resource id of the dialog to display.
        !            80: *   DLGPROC pfnDlgProc - The dialog proc to use.
        !            81: *
        !            82: * Returns:
        !            83: *   The return value from DialogBox (whatever the dialog proc passes
        !            84: *   to EndDialog).
        !            85: \*****************************************************************************/
        !            86: 
        !            87: BOOL
        !            88: MyDialogBox(
        !            89:     INT idDlg,
        !            90:     DLGPROC pfnDlgProc
        !            91:     )
        !            92: {
        !            93:     return DialogBox(ghInst, MAKEINTRESOURCE(idDlg), ghwndSpyApp, pfnDlgProc);
        !            94: }
        !            95: 
        !            96: 
        !            97: 
        !            98: /*****************************************************************************\
        !            99: * AboutDlgProc
        !           100: *
        !           101: *   Dialog proc for the About box.
        !           102: *
        !           103: \*****************************************************************************/
        !           104: 
        !           105: BOOL CALLBACK
        !           106: AboutDlgProc(
        !           107:     HWND hwnd,
        !           108:     UINT msg,
        !           109:     WPARAM wParam,
        !           110:     LPARAM lParam
        !           111:     )
        !           112: {
        !           113:     switch (msg) {
        !           114:         case WM_INITDIALOG:
        !           115:             return TRUE;
        !           116: 
        !           117:         case WM_COMMAND:
        !           118:             EndDialog(hwnd, IDOK);
        !           119:             break;
        !           120:     }
        !           121: 
        !           122:     return FALSE;
        !           123: }
        !           124: 
        !           125: 
        !           126: 
        !           127: /*****************************************************************************\
        !           128: * SelectWindowDlgProc
        !           129: *
        !           130: * Dialog proc for the Select Window dialog.  This dialog allows the user
        !           131: * to select which window they want to spy on.
        !           132: *
        !           133: * Arguments:
        !           134: *   HWND hwnd       - Window handle of the dialog.
        !           135: *   UINT msg        - Message sent to window.
        !           136: *   WPARAM wParam   - Message parameter.
        !           137: *   LPARAM lParam   - Message parameter.
        !           138: *
        !           139: * Returns:
        !           140: *   The value that the dialog proc should return, based on the processing
        !           141: *   of the specific WM_COMMAND message received.
        !           142: \*****************************************************************************/
        !           143: 
        !           144: BOOL CALLBACK
        !           145: SelectWindowDlgProc(
        !           146:     HWND hwnd,
        !           147:     UINT msg,
        !           148:     WPARAM wParam,
        !           149:     LPARAM lParam
        !           150:     )
        !           151: {
        !           152:     HWND hwndList;
        !           153:     INT nIndex;
        !           154: 
        !           155:     UNREFERENCED_PARAMETER(lParam);
        !           156: 
        !           157:     switch (msg)
        !           158:     {
        !           159:         case WM_INITDIALOG:
        !           160:             hwndList = GetDlgItem(hwnd, DID_SELWINLIST);
        !           161:             ghwndSpyingOnTemp = ghwndSpyingOn == HWND_ALL ? NULL : (ghwndSpyingOn == NULL ? NULL
        !           162:                 : GetParent(ghwndSpyingOn));
        !           163:             FillListBox(hwnd, hwndList, ghwndSpyingOnTemp);
        !           164:             nIndex = FindHwndInListBox(hwndList, ghwndSpyingOn == HWND_ALL ? NULL
        !           165:                 : ghwndSpyingOn);
        !           166:             SendMessage(hwndList, LB_SETCURSEL, nIndex, 0);
        !           167:             ghwndSpyingOnTemp = (HWND)SendMessage(hwndList, LB_GETITEMDATA, nIndex, 0);
        !           168:             SelectWindowUpdateInfo(hwnd, ghwndSpyingOnTemp);
        !           169:             CheckDlgButton(hwnd, DID_SELWINALLWINDOWS, gfSpyAll);
        !           170:             SelectWindowEnableFields(hwnd, !gfSpyAll);
        !           171:             SetFocus(hwnd);
        !           172:             HighlightWindow(ghwndSpyingOnTemp, TRUE);
        !           173: 
        !           174:             return TRUE;
        !           175: 
        !           176:         case WM_NCLBUTTONDOWN:
        !           177:             if (wParam == HTCAPTION)
        !           178:             {
        !           179:                 //
        !           180:                 // The mouse is down for a move of the dialog, so clean up the
        !           181:                 // border stuff.
        !           182:                 //
        !           183:                 if (bBorderOn)
        !           184:                     HighlightWindow(ghwndSpyingOnTemp, FALSE);
        !           185:             }
        !           186: 
        !           187:             return FALSE;
        !           188: 
        !           189:         case WM_KEYDOWN:
        !           190:         case WM_LBUTTONUP:
        !           191:         case WM_NCLBUTTONUP:
        !           192:             //
        !           193:             // The mouse is up from a move of the dialog, so put up the
        !           194:             // border stuff again.
        !           195:             //
        !           196:             if (!bBorderOn)
        !           197:                 HighlightWindow(ghwndSpyingOnTemp, TRUE);
        !           198: 
        !           199:             return FALSE;
        !           200: 
        !           201:         case WM_CANCELMODE:
        !           202:             return FALSE;
        !           203: 
        !           204:         case WM_COMMAND:
        !           205:             return SelectWindowCommand(hwnd, LOWORD(wParam), HIWORD(wParam));
        !           206:     }
        !           207: 
        !           208:     return FALSE;
        !           209: }
        !           210: 
        !           211: 
        !           212: 
        !           213: /*****************************************************************************\
        !           214: * SelectWindowCommand
        !           215: *
        !           216: * Handles thw WM_COMMAND messages for the Select Window dialog.
        !           217: *
        !           218: * Arguments:
        !           219: *   HWND hwnd       - Window handle of the dialog.
        !           220: *   INT nCmd        - Command value.
        !           221: *   INT nNotifyCode - The notify code.
        !           222: *
        !           223: * Returns:
        !           224: *   The value that the dialog proc should return, based on the processing
        !           225: *   of the specific WM_COMMAND message received.
        !           226: \*****************************************************************************/
        !           227: 
        !           228: PRIVATE BOOL
        !           229: SelectWindowCommand(
        !           230:     HWND hwnd,
        !           231:     INT nCmd,
        !           232:     INT nNotifyCode
        !           233:     )
        !           234: {
        !           235:     INT nIndex;
        !           236:     HWND hwndList;
        !           237:     CHAR rgString[32];
        !           238: 
        !           239:     switch (nCmd)
        !           240:     {
        !           241:         case IDOK:
        !           242:             SetWindowToSpyOn(IsDlgButtonChecked(hwnd, DID_SELWINALLWINDOWS) ?
        !           243:                 HWND_ALL : ghwndSpyingOnTemp);
        !           244: 
        !           245:             if (bBorderOn)
        !           246:                 HighlightWindow(ghwndSpyingOnTemp, FALSE);
        !           247: 
        !           248:             EndDialog(hwnd, IDOK);
        !           249:             return TRUE;
        !           250: 
        !           251:         case IDCANCEL:
        !           252:             if (bBorderOn)
        !           253:                 HighlightWindow(ghwndSpyingOnTemp, FALSE);
        !           254: 
        !           255:             EndDialog(hwnd, IDCANCEL);
        !           256:             return TRUE;
        !           257: 
        !           258:         case DID_SELWINLIST:
        !           259:             //
        !           260:             // User single clicked or doubled clicked in listbox -
        !           261:             //   Single click means select a window to spy on
        !           262:             //   Double click means enumerate all the children of that window.
        !           263:             //
        !           264:             hwndList = GetDlgItem(hwnd, DID_SELWINLIST);
        !           265:             switch (nNotifyCode)
        !           266:             {
        !           267:                 case LBN_SELCHANGE:
        !           268:                     //
        !           269:                     // Single click case. Select a window to spy upon.
        !           270:                     //
        !           271:                     // Get the window handle, set it as the window to spy on.
        !           272:                     //
        !           273: 
        !           274:                     if (bBorderOn)
        !           275:                         HighlightWindow(ghwndSpyingOnTemp, FALSE);
        !           276: 
        !           277:                     nIndex = (INT)SendMessage(hwndList, LB_GETCURSEL, 0, 0);
        !           278:                     ghwndSpyingOnTemp = (HWND)SendMessage(hwndList, LB_GETITEMDATA,
        !           279:                         nIndex, 0);
        !           280:                     SelectWindowUpdateInfo(hwnd, ghwndSpyingOnTemp);
        !           281: 
        !           282:                     HighlightWindow(ghwndSpyingOnTemp, TRUE);
        !           283: 
        !           284:                     break;
        !           285: 
        !           286:                 case LBN_DBLCLK:
        !           287:                     //
        !           288:                     // Double click case - first click has already been
        !           289:                     // processed as single click. In this case, the user has
        !           290:                     // requested to look at all the children of a given
        !           291:                     // selection.
        !           292:                     //
        !           293:                     // Get the current selection, and check to see if it is the
        !           294:                     // " [ parent.. ]" entry. If so, go up one level first.
        !           295:                     //
        !           296: 
        !           297:                     SetCursor(LoadCursor(NULL, IDC_WAIT));
        !           298: 
        !           299:                     if (bBorderOn)
        !           300:                         HighlightWindow(ghwndSpyingOnTemp, FALSE);
        !           301: 
        !           302:                     nIndex = (INT)SendMessage(hwndList, LB_GETCURSEL, 0, 0);
        !           303:                     ghwndSpyingOnTemp = (HWND)SendMessage(hwndList, LB_GETITEMDATA,
        !           304:                         nIndex, 0);
        !           305:                     SendMessage(hwndList, LB_GETTEXT, nIndex, (LPARAM)rgString);
        !           306: 
        !           307:                     if (rgString[0] == ' ')
        !           308:                     {
        !           309:                         // At top?  If so, we are done.
        !           310:                         if (ghwndSpyingOnTemp == NULL)
        !           311:                         {
        !           312:                             SetCursor(LoadCursor(NULL, IDC_ARROW));
        !           313:                             break;
        !           314:                         }
        !           315: 
        !           316:                         ghwndSpyingOnTemp = GetParent(ghwndSpyingOnTemp);
        !           317:                     }
        !           318: 
        !           319:                     SendMessage(hwndList, LB_RESETCONTENT, 0, 0);
        !           320:                     FillListBox(hwnd, hwndList, ghwndSpyingOnTemp);
        !           321: 
        !           322:                     nIndex = FindHwndInListBox(hwndList, ghwndSpyingOnTemp);
        !           323:                     SendMessage(hwndList, LB_SETCURSEL, nIndex, 0);
        !           324:                     ghwndSpyingOnTemp = (HWND)SendMessage(hwndList, LB_GETITEMDATA,
        !           325:                         nIndex, 0);
        !           326:                     HighlightWindow(ghwndSpyingOnTemp,TRUE);
        !           327:                     SelectWindowUpdateInfo(hwnd, ghwndSpyingOnTemp);
        !           328:                     SetCursor(LoadCursor(NULL, IDC_ARROW));
        !           329:                     break;
        !           330:             }
        !           331: 
        !           332:             break;
        !           333: 
        !           334:         case DID_SELWINALLWINDOWS:
        !           335:             SelectWindowEnableFields(hwnd,
        !           336:                 !IsDlgButtonChecked(hwnd, DID_SELWINALLWINDOWS));
        !           337: 
        !           338:             break;
        !           339:     }
        !           340: 
        !           341:     return FALSE;
        !           342: }
        !           343: 
        !           344: 
        !           345: 
        !           346: /*****************************************************************************\
        !           347: * FillListBox
        !           348: *
        !           349: * Fills the listbox in the Select Window dialog with the names of
        !           350: * the child windows of the given window.
        !           351: *
        !           352: * Arguments:
        !           353: *   hDlg     - Window handle of the dialog window
        !           354: *   hwndList - Handle to the listbox within the dialog.
        !           355: *   hwnd     - Parent whose children to enumerate.
        !           356: *
        !           357: * Returns:
        !           358: *   VOID
        !           359: \*****************************************************************************/
        !           360: 
        !           361: PRIVATE VOID
        !           362: FillListBox(
        !           363:     HWND hDlg,
        !           364:     HWND hwndList,
        !           365:     HWND hwnd
        !           366:     )
        !           367: {
        !           368:     INT nIndex;
        !           369: 
        !           370:     //
        !           371:     // First fill the list box with child windows
        !           372:     //
        !           373:     // Make sure we display the list box after things are added.
        !           374:     //
        !           375: 
        !           376:     SendMessage(hwndList, WM_SETREDRAW, 0, 0);
        !           377: 
        !           378:     //
        !           379:     // remember which dialog we are processing
        !           380:     //
        !           381: 
        !           382:     ghwndDlgBeingFilled = hDlg;
        !           383: 
        !           384:     if (hwnd == NULL)
        !           385:     {
        !           386:         //
        !           387:         // Enumerate the top level separately... gross unsymmetry, but
        !           388:         // hey.
        !           389:         //
        !           390:         EnumWindows(AddOneWindow, (LPARAM)hwndList);
        !           391:     }
        !           392:     else
        !           393:     {
        !           394:         EnumChildWindows(hwnd, AddOneWindow, (LPARAM)hwndList);
        !           395:     }
        !           396: 
        !           397:     //
        !           398:     // Now give the user a method of getting back to the parent. The space at
        !           399:     // the beginning of the " [parent]" string identifies the entry as the
        !           400:     // parent entry and makes it different from all the other entries since
        !           401:     // the others start with a handle number of some sort.
        !           402:     //
        !           403: 
        !           404:     nIndex = SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)" [ parent... ]");
        !           405:     SendMessage(hwndList, LB_SETITEMDATA, nIndex, (LONG)hwnd);
        !           406: 
        !           407:     //
        !           408:     // Now do the redraw...
        !           409:     //
        !           410: 
        !           411:     SendMessage(hwndList, WM_SETREDRAW, 1, 0);
        !           412: }
        !           413: 
        !           414: 
        !           415: 
        !           416: /*****************************************************************************\
        !           417: * AddOneWindow
        !           418: *
        !           419: * Gets the windows to add to the list of windows to spy on.
        !           420: *
        !           421: * Arguments:
        !           422: *     HWND hwnd - handle of the window to add.
        !           423: *     HWND hwndList - handle to the listbox.
        !           424: *
        !           425: * Returns:
        !           426: *     TRUE - if a window was created.
        !           427: \*****************************************************************************/
        !           428: #define CCH_RGBUF   32
        !           429: 
        !           430: BOOL CALLBACK
        !           431: AddOneWindow(
        !           432:     HWND hwnd,
        !           433:     HWND hwndList
        !           434:     )
        !           435: {
        !           436:     CHAR rgBuf[CCH_RGBUF];
        !           437:     INT nIndex;
        !           438:     HWND htemp;
        !           439: 
        !           440:     //
        !           441:     // Make sure we don't add any window that has anything to do with
        !           442:     // the dialog or any other spy window
        !           443:     //
        !           444: 
        !           445:     htemp = GetParent(hwnd);
        !           446: 
        !           447:     // Don't put console windows in the list since they can not be hooked
        !           448:     if (GetClassName(hwnd, (LPTSTR) rgBuf, CCH_RGBUF) != 0 &&
        !           449:         strcmp(rgBuf, szConsoleWindowClass) == 0 )
        !           450:     {
        !           451:         return 1;
        !           452:     }
        !           453: 
        !           454:     // Don't put windows that belong to spy in the list
        !           455:     if (hwnd == ghwndDlgBeingFilled || htemp == ghwndDlgBeingFilled
        !           456:         || hwnd == ghwndSpyApp
        !           457:         || htemp == ghwndSpyApp || hwnd == ghwndPrintf || htemp == ghwndPrintf
        !           458:         || hwnd == ghwndSpyHook || htemp == ghwndSpyHook)
        !           459:     {
        !           460:         return 1;
        !           461:     }
        !           462: 
        !           463:     MakeWindowName(hwnd, rgBuf, CCH_RGBUF);
        !           464: 
        !           465:     nIndex = SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)rgBuf);
        !           466: 
        !           467:     if (nIndex == LB_ERR || nIndex == LB_ERRSPACE)
        !           468:         return 0;
        !           469: 
        !           470:     if (SendMessage(hwndList, LB_SETITEMDATA, nIndex, (LPARAM)hwnd) == LB_ERR)
        !           471:         return 0;
        !           472: 
        !           473:     return 1;
        !           474: }
        !           475: 
        !           476: 
        !           477: 
        !           478: /*****************************************************************************\
        !           479: * MakeWindowName
        !           480: *
        !           481: * Builds the window name from the window handle passed in.
        !           482: *
        !           483: * Arguments:
        !           484: *     HWND hwnd - handle to the window.
        !           485: *     LPSTR lpString - String to put window name into.
        !           486: *     INT nSTringLen - Length of window string.
        !           487: *
        !           488: * Returns:
        !           489: *     VOID
        !           490: \*****************************************************************************/
        !           491: 
        !           492: PRIVATE VOID
        !           493: MakeWindowName(
        !           494:     HWND hwnd,
        !           495:     LPSTR lpString,
        !           496:     INT nStringLen
        !           497:     )
        !           498: {
        !           499:     wsprintf(lpString, "%8.8lX:", hwnd);
        !           500: 
        !           501:     if (hwnd == NULL || !IsWindow(hwnd))
        !           502:     {
        !           503:         lstrcat(lpString, "!!!");
        !           504:     }
        !           505:     else
        !           506:     {
        !           507:         GetWindowText(hwnd, lpString + 9, nStringLen - 9);
        !           508:     }
        !           509: }
        !           510: 
        !           511: 
        !           512: 
        !           513: /*****************************************************************************\
        !           514: * FindHwndInListBox
        !           515: *
        !           516: * Gets the window from the list of windows in the listbox.
        !           517: *
        !           518: * Arguments:
        !           519: *     HWND hwndList - handle to the listbox.
        !           520: *     HWND hSpyWnd - handle to the spy window.
        !           521: *
        !           522: * Returns:
        !           523: *     INT - Index to the window in the listbox. 
        !           524: \*****************************************************************************/
        !           525: 
        !           526: PRIVATE INT
        !           527: FindHwndInListBox(
        !           528:     HWND hwndList,
        !           529:     HWND hSpyWnd
        !           530:     )
        !           531: {
        !           532:     CHAR rgBuf[9];
        !           533:     INT nIndex;
        !           534: 
        !           535:     wsprintf(rgBuf, "%08lX", (LONG)hSpyWnd);
        !           536: 
        !           537:     nIndex = SendMessage(hwndList, LB_FINDSTRING, (WPARAM)-1, (LPARAM)rgBuf);
        !           538: 
        !           539:     if (nIndex == LB_ERR)
        !           540:         nIndex = 0;
        !           541: 
        !           542:     return nIndex;
        !           543: }
        !           544: 
        !           545: 
        !           546: 
        !           547: /*****************************************************************************\
        !           548: * HighlightWindow
        !           549: *
        !           550: * Used to temporarily highlight the window that the user has selected from
        !           551: * the Select Window dialog.  It does this by inverting a border around the
        !           552: * window.
        !           553: *
        !           554: * Arguments:
        !           555: *     HWND hwnd - handle to the selected window.
        !           556: *     BOOL fdraw - whether to draw the window inverted on non-inverted.
        !           557: *
        !           558: * Returns:
        !           559: *     VOID
        !           560: \*****************************************************************************/
        !           561: 
        !           562: PRIVATE VOID
        !           563: HighlightWindow(
        !           564:     HWND hwnd,
        !           565:     BOOL fDraw
        !           566:     )
        !           567: {
        !           568:     HDC hdc;
        !           569:     RECT rc;
        !           570: 
        !           571:     bBorderOn = fDraw;
        !           572: 
        !           573:     if (hwnd == NULL || !IsWindow(hwnd))
        !           574:         return;
        !           575: 
        !           576:     hdc = GetWindowDC(hwnd);
        !           577:     GetWindowRect(hwnd, &rc);
        !           578:     OffsetRect(&rc, -rc.left, -rc.top);
        !           579: 
        !           580:     if (!IsRectEmpty(&rc))
        !           581:     {
        !           582:         PatBlt(hdc, rc.left, rc.top, rc.right - rc.left, DINV,  DSTINVERT);
        !           583:         PatBlt(hdc, rc.left, rc.bottom - DINV, DINV,
        !           584:             -(rc.bottom - rc.top - 2 * DINV), DSTINVERT);
        !           585:         PatBlt(hdc, rc.right - DINV, rc.top + DINV, DINV,
        !           586:             rc.bottom - rc.top - 2 * DINV, DSTINVERT);
        !           587:         PatBlt(hdc, rc.right, rc.bottom - DINV, -(rc.right - rc.left),
        !           588:             DINV, DSTINVERT);
        !           589:     }
        !           590: 
        !           591:     ReleaseDC(hwnd, hdc);
        !           592: }
        !           593: 
        !           594: 
        !           595: 
        !           596: /*****************************************************************************\
        !           597: * SelectWindowUpdateInfo
        !           598: *
        !           599: * Updates the informational fields in the Select Window dialog when
        !           600: * a new window is selected from the hwnd listbox.
        !           601: *
        !           602: * Arguments:
        !           603: *     HWND hDlg - handle to the select window dialog box.
        !           604: *     HWND hwnd - handle to the new window selected.
        !           605: *
        !           606: * Returns:
        !           607: *     VOID
        !           608: \*****************************************************************************/
        !           609: 
        !           610: PRIVATE VOID
        !           611: SelectWindowUpdateInfo(
        !           612:     HWND hDlg,
        !           613:     HWND hwnd
        !           614:     )
        !           615: {
        !           616:     HWND hParent;
        !           617:     DWORD dwStyle;
        !           618:     RECT rc;
        !           619:     CHAR szTemp[MAXSTRING];
        !           620: 
        !           621:     if (hwnd)
        !           622:     {
        !           623:         hParent = GetParent(hwnd);
        !           624:         dwStyle = GetWindowLong(hwnd, GWL_STYLE);
        !           625: 
        !           626:         MakeWindowName(hwnd, szTemp, MAXSTRING);
        !           627:         SetDlgItemText(hDlg, DID_SELWINWINDOW, szTemp);
        !           628: 
        !           629:         GetClassName(hwnd, szTemp, MAXSTRING);
        !           630:         SetDlgItemText(hDlg, DID_SELWINCLASS, szTemp);
        !           631: 
        !           632:         if (hParent)
        !           633:         {
        !           634:             MakeWindowName(hParent, szTemp, MAXSTRING);
        !           635:             SetDlgItemText(hDlg, DID_SELWINPARENT, szTemp);
        !           636:         }
        !           637:         else
        !           638:         {
        !           639:             SetDlgItemText(hDlg, DID_SELWINPARENT, "<No Parent>");
        !           640:         }
        !           641: 
        !           642:         GetWindowRect(hwnd, &rc);
        !           643:         wsprintf(szTemp, "(%d,%d)-(%d,%d) %dx%d", rc,
        !           644:             rc.right-rc.left, rc.bottom-rc.top);
        !           645:         SetDlgItemText(hDlg, DID_SELWINRECT, szTemp);
        !           646: 
        !           647:         if (dwStyle & WS_POPUP)
        !           648:             wsprintf (szTemp, "%08lX: WS_POPUP", dwStyle);
        !           649:         else if (dwStyle & WS_CHILD)
        !           650:             wsprintf (szTemp, "%08lX: WS_CHILD, ID: %lX", dwStyle,
        !           651:             GetWindowLong(hwnd, GWL_ID));
        !           652:         else if (dwStyle & WS_ICONIC)
        !           653:             wsprintf (szTemp, "%08lX: WS_ICONIC", dwStyle);
        !           654:         else
        !           655:             wsprintf (szTemp, "%08lX: WS_OVERLAPPED", dwStyle);
        !           656: 
        !           657:         SetDlgItemText(hDlg, DID_SELWINSTYLE, szTemp);
        !           658:     }
        !           659:     else
        !           660:     {
        !           661:         SetDlgItemText(hDlg, DID_SELWINWINDOW, "<Undefined>");
        !           662:         SetDlgItemText(hDlg, DID_SELWINCLASS,  "<Undefined>");
        !           663:         SetDlgItemText(hDlg, DID_SELWINPARENT, "<Undefined>");
        !           664:         SetDlgItemText(hDlg, DID_SELWINRECT, "<Undefined>");
        !           665:         SetDlgItemText(hDlg, DID_SELWINSTYLE, "<Undefined>");
        !           666:     }
        !           667: }
        !           668: 
        !           669: 
        !           670: 
        !           671: /*****************************************************************************\
        !           672: * SelectWindowEnableFields
        !           673: *
        !           674: * Enables/disables the different fields in the Select Window dialog
        !           675: * based on whether the user wants to spy on all windows or individually
        !           676: * select one.
        !           677: *
        !           678: * Arguments:
        !           679: *   HWND hwnd    - Dialog window handle.
        !           680: *   BOOL fEnable - TRUE to enable the fields, FALSE to disable them.
        !           681: *
        !           682: * Returns:
        !           683: *   VOID
        !           684: \*****************************************************************************/
        !           685: 
        !           686: PRIVATE VOID
        !           687: SelectWindowEnableFields(
        !           688:     HWND hwnd,
        !           689:     BOOL fEnable
        !           690:     )
        !           691: {
        !           692:     EnableWindow(GetDlgItem(hwnd, DID_SELWINLIST), fEnable);
        !           693:     EnableWindow(GetDlgItem(hwnd, DID_SELWINWINDOW), fEnable);
        !           694:     EnableWindow(GetDlgItem(hwnd, DID_SELWINCLASS), fEnable);
        !           695:     EnableWindow(GetDlgItem(hwnd, DID_SELWINPARENT), fEnable);
        !           696:     EnableWindow(GetDlgItem(hwnd, DID_SELWINRECT), fEnable);
        !           697:     EnableWindow(GetDlgItem(hwnd, DID_SELWINSTYLE), fEnable);
        !           698: }
        !           699: 
        !           700: 
        !           701: 
        !           702: /*****************************************************************************\
        !           703: * OutputDlgProc
        !           704: *
        !           705: * Dialog proc for the Output dialog.
        !           706: *
        !           707: * Arguments:
        !           708: *   HWND hwnd - handle to the output dialog
        !           709: *   UINT msg - message sent to output dialog
        !           710: *   WPARAM wParam - message parameter.
        !           711: *   LPARAM lParam - message parameter.
        !           712: *
        !           713: * Returns:
        !           714: *   The value that the dialog proc should return, based on the processing
        !           715: *   of the specific WM_COMMAND message received.
        !           716: *
        !           717: \*****************************************************************************/
        !           718: 
        !           719: BOOL CALLBACK
        !           720: OutputDlgProc(
        !           721:     HWND hwnd,
        !           722:     UINT msg,
        !           723:     WPARAM wParam,
        !           724:     LPARAM lParam
        !           725:     )
        !           726: {
        !           727:     switch (msg)
        !           728:     {
        !           729:         case WM_INITDIALOG:
        !           730:             CheckDlgButton(hwnd, DID_OUTPUTWINDOW, gfOutputWin);
        !           731:             CheckDlgButton(hwnd, DID_OUTPUTCOM1, gfOutputCom1);
        !           732:             CheckDlgButton(hwnd, DID_OUTPUTFILE, gfOutputFile);
        !           733: 
        !           734:             SetDlgItemText(hwnd, DID_OUTPUTFILENAME, gszFile);
        !           735:             SetDlgItemInt(hwnd, DID_OUTPUTLINES, gnLines, FALSE);
        !           736: 
        !           737:             return TRUE;
        !           738: 
        !           739:         case WM_COMMAND:
        !           740:             return OutputCommand(hwnd, LOWORD(wParam), HIWORD(wParam));
        !           741:     }
        !           742: 
        !           743:     return FALSE;
        !           744: }
        !           745: 
        !           746: 
        !           747: 
        !           748: /*****************************************************************************\
        !           749: * OutputCommand
        !           750: *
        !           751: * Handles the WM_COMMAND messages for the Output dialog.
        !           752: *
        !           753: * Arguments:
        !           754: *   HWND hwnd       - Window handle of the dialog.
        !           755: *   INT nCmd        - Command value.
        !           756: *   INT nNotifyCode - The notify code.
        !           757: *
        !           758: * Returns:
        !           759: *   The value that the dialog proc should return, based on the processing
        !           760: *   of the specific WM_COMMAND message received.
        !           761: *
        !           762: \*****************************************************************************/
        !           763: 
        !           764: PRIVATE BOOL
        !           765: OutputCommand(
        !           766:     HWND hwnd,
        !           767:     INT nCmd,
        !           768:     INT nNotifyCode
        !           769:     )
        !           770: {
        !           771:     HFILE fh;
        !           772:     INT i;
        !           773:     CHAR szTemp[MAXSTRING];
        !           774: 
        !           775:     switch (nCmd)
        !           776:     {
        !           777:         case IDOK:
        !           778:             i = GetDlgItemInt(hwnd, DID_OUTPUTLINES, &i, FALSE);
        !           779:             if (i != gnLines)
        !           780:             {
        !           781:                 if ( i > 0 && i <= LINES_MAX)
        !           782:                 {
        !           783:                     gnLines = i;
        !           784:                     MyCreatePrintfWin(ghwndSpyApp);
        !           785:                 }
        !           786:                 else
        !           787:                 {
        !           788:                     Message(MB_OK | MB_ICONEXCLAMATION,
        !           789:                         "Window lines should be between 1-%d", LINES_MAX);
        !           790:                     SetFocus(GetDlgItem(hwnd, DID_OUTPUTLINES));
        !           791:                     break;
        !           792:                 }
        !           793:             }
        !           794: 
        !           795:             gfOutputWin = IsDlgButtonChecked(hwnd, DID_OUTPUTWINDOW);
        !           796:             gfOutputCom1 = IsDlgButtonChecked(hwnd, DID_OUTPUTCOM1);
        !           797:             gfOutputFile = IsDlgButtonChecked(hwnd, DID_OUTPUTFILE);
        !           798: 
        !           799:             if (gfOutputFile)
        !           800:             {
        !           801:                 GetDlgItemText(hwnd, DID_OUTPUTFILENAME, szTemp, MAXSTRING);
        !           802:                 //BUGBUG verify that they entered a filename!
        !           803:                 if (lstrcmp(gszFile, szTemp))        /* Not Equal */
        !           804:                 {
        !           805:                     fh = _lcreat(szTemp, 0);
        !           806:                     if (fh == (HFILE)(-1))
        !           807:                     {
        !           808:                         if (Message(MB_OKCANCEL | MB_ICONEXCLAMATION,
        !           809:                             "Cannot open %s", szTemp) == IDCANCEL)
        !           810:                         {
        !           811:                             EndDialog(hwnd, FALSE);
        !           812:                         }
        !           813: 
        !           814:                         return TRUE;
        !           815:                     }
        !           816: 
        !           817:                     lstrcpy(gszFile, szTemp);
        !           818:                     if (gfhFile)
        !           819:                         _lclose(gfhFile);
        !           820:                     gfhFile = fh;
        !           821:                 }
        !           822:             }
        !           823:             else
        !           824:             {
        !           825:                 if (gfhFile)
        !           826:                 {
        !           827:                     _lclose(gfhFile);
        !           828:                     gfhFile = 0;
        !           829:                 }
        !           830:             }
        !           831: 
        !           832:             EndDialog(hwnd, TRUE);
        !           833:             return TRUE;
        !           834: 
        !           835:         case IDCANCEL:
        !           836:             EndDialog(hwnd, FALSE);
        !           837:             return TRUE;
        !           838:     }
        !           839: 
        !           840:     return FALSE;
        !           841: }
        !           842: 
        !           843: 
        !           844: 
        !           845: /*****************************************************************************\
        !           846: * SelectFont
        !           847: *
        !           848: * Allows the user to select a new font for the display.
        !           849: *
        !           850: * Arguments:
        !           851: *    none
        !           852: *
        !           853: * Returns:
        !           854: *    VOID
        !           855: \*****************************************************************************/
        !           856: 
        !           857: VOID
        !           858: SelectFont(
        !           859:     VOID
        !           860:     )
        !           861: {
        !           862:     CHOOSEFONT cf;
        !           863:     LOGFONT lf;
        !           864:     HFONT hfontNew;
        !           865: 
        !           866:     GetObject(ghfontPrintf, sizeof(LOGFONT), (LPVOID)&lf);
        !           867: 
        !           868:     cf.lStructSize = sizeof(cf);
        !           869:     cf.hwndOwner = ghwndSpyApp;
        !           870:     cf.hDC = NULL;
        !           871:     cf.lpLogFont = &lf;
        !           872:     cf.iPointSize = 0;
        !           873:     cf.Flags = CF_ANSIONLY | CF_FORCEFONTEXIST | CF_INITTOLOGFONTSTRUCT
        !           874:         | CF_SCREENFONTS;
        !           875:     cf.rgbColors = 0;
        !           876:     cf.lCustData = 0;
        !           877:     cf.lpfnHook = NULL;
        !           878:     cf.lpTemplateName = NULL;
        !           879:     cf.hInstance = NULL;
        !           880:     cf.lpszStyle = NULL;
        !           881:     cf.nFontType = 0;
        !           882:     cf.nSizeMin = 0;
        !           883:     cf.nSizeMax = 0;
        !           884: 
        !           885:     if (ChooseFont(&cf))
        !           886:     {
        !           887:         if (hfontNew = CreateFontIndirect(&lf))
        !           888:         {
        !           889:             SetPrintfFont(ghwndPrintf, hfontNew);
        !           890:             ghfontPrintf = hfontNew;
        !           891:         }
        !           892:     }
        !           893: }
        !           894: 
        !           895: 
        !           896: 
        !           897: /*****************************************************************************\
        !           898: * MessagesDlgProc
        !           899: *
        !           900: * Dialog proc for the Messages dialog.  This dialog allows the user
        !           901: * to select which messages they want to spy on.
        !           902: *
        !           903: * Arguments:
        !           904: *    HWND hwnd - handle to the dialog window.
        !           905: *    UINT msg - message to the window
        !           906: *    WPARAM wParam - message parameter
        !           907: *    LPARAM lParam - message parameter
        !           908: *
        !           909: * Returns:
        !           910: *   The value that the dialog proc should return, based on the processing
        !           911: *   of the specific WM_COMMAND message received.
        !           912: \*****************************************************************************/
        !           913: 
        !           914: BOOL CALLBACK
        !           915: MessagesDlgProc(
        !           916:     HWND hwnd,
        !           917:     UINT msg,
        !           918:     WPARAM wParam,
        !           919:     LPARAM lParam
        !           920:     )
        !           921: {
        !           922:     switch (msg)
        !           923:     {
        !           924:         case WM_INITDIALOG:
        !           925:             MessagesInit(hwnd);
        !           926:             return TRUE;
        !           927: 
        !           928:         case WM_COMMAND:
        !           929:             return MessagesCommand(hwnd, LOWORD(wParam), HIWORD(wParam));
        !           930:     }
        !           931: 
        !           932:     return FALSE;
        !           933: }
        !           934: 
        !           935: 
        !           936: 
        !           937: /*****************************************************************************\
        !           938: * MessagesInit
        !           939: *
        !           940: * Initializes the messages dialog.
        !           941: *
        !           942: * Arguments:
        !           943: *   HWND hwnd - Dialog window handle.
        !           944: *
        !           945: * Returns:
        !           946: *   VOID
        !           947: \*****************************************************************************/
        !           948: 
        !           949: PRIVATE VOID
        !           950: MessagesInit(
        !           951:     HWND hwnd
        !           952:     )
        !           953: {
        !           954:     HWND hwndList;
        !           955:     INT i;
        !           956:     INT j;
        !           957:     INT iSel;
        !           958:     PMSGDESC pmd;
        !           959: 
        !           960:     for (j = 0; j < gcMsgGroups; j++)
        !           961:         gaMsgGroup[j].cUseCount = 0;
        !           962: 
        !           963:     hwndList = GetDlgItem(hwnd, DID_MSGSLIST);
        !           964: 
        !           965:     for (i = 0, pmd = gaMsgs; i < gcMessages; i++, pmd++)
        !           966:     {
        !           967:         iSel = (INT)SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)pmd->pszMsg);
        !           968:         SendMessage(hwndList, LB_SETITEMDATA, iSel, (LPARAM)pmd);
        !           969: 
        !           970:         if (pmd->Flags & MTF_SELECTED)
        !           971:         {
        !           972:             SendMessage(hwndList, LB_SETSEL, TRUE, iSel);
        !           973: 
        !           974:             for (j = 0; j < gcMsgGroups; j++)
        !           975:             {
        !           976:                 if (gaMsgGroup[j].flMask & pmd->Flags)
        !           977:                     gaMsgGroup[j].cUseCount++;
        !           978:             }
        !           979:         }
        !           980:     }
        !           981: 
        !           982:     //
        !           983:     // Set the selection rectangle to the first item in the listbox.
        !           984:     //
        !           985:     SendMessage(hwndList, LB_SETCARETINDEX, 0, FALSE);
        !           986: 
        !           987:     //
        !           988:     // Loop through all the message groups.
        !           989:     //
        !           990:     for (j = 0; j < gcMsgGroups; j++)
        !           991:     {
        !           992:         //
        !           993:         // Is at least one message in the group selected?
        !           994:         //
        !           995:         if (gaMsgGroup[j].cUseCount)
        !           996:         {
        !           997:             //
        !           998:             // Check the corresponding checkbox.  If all messages
        !           999:             // in the group are selected, the checkbox is checked.
        !          1000:             // If only some are selected, the checkbox is set to
        !          1001:             // grayed (3-state).
        !          1002:             //
        !          1003:             CheckDlgButton(hwnd, gaMsgGroup[j].idCheckBox,
        !          1004:                 (gaMsgGroup[j].cUseCount == gaMsgGroup[j].cMsgs) ? 1 : 2);
        !          1005:         }
        !          1006:     }
        !          1007: 
        !          1008:     if (gfMsgsUser)
        !          1009:         CheckDlgButton(hwnd, DID_MSGSUSER, 1);
        !          1010: 
        !          1011:     if (gfMsgsUnknown)
        !          1012:         CheckDlgButton(hwnd, DID_MSGSUNKNOWN, 1);
        !          1013: 
        !          1014:     gcItemsSave = SendMessage(hwndList, LB_GETSELITEMS,
        !          1015:         gcMessages, (LPARAM)gaiSelected);
        !          1016: }
        !          1017: 
        !          1018: 
        !          1019: 
        !          1020: /*****************************************************************************\
        !          1021: * MessagesCommand
        !          1022: *
        !          1023: * Handles the WM_COMMAND messages for the Messages dialog.
        !          1024: *
        !          1025: * Arguments:
        !          1026: *   HWND hwnd       - Window handle of the dialog.
        !          1027: *   INT nCmd        - Command value.
        !          1028: *   INT nNotifyCode - The notify code.
        !          1029: *
        !          1030: * Returns:
        !          1031: *   The value that the dialog proc should return, based on the processing
        !          1032: *   of the specific WM_COMMAND message received.
        !          1033: *
        !          1034: \*****************************************************************************/
        !          1035: 
        !          1036: PRIVATE BOOL
        !          1037: MessagesCommand(
        !          1038:     HWND hwnd,
        !          1039:     INT nCmd,
        !          1040:     INT nNotifyCode
        !          1041:     )
        !          1042: {
        !          1043:     INT i;
        !          1044:     INT j;
        !          1045:     PMSGGROUP pmg;
        !          1046:     PMSGDESC pmd;
        !          1047:     BOOL fChecked;
        !          1048:     HWND hwndList;
        !          1049:     INT cItems;
        !          1050:     BOOL fSel;
        !          1051:     INT iSel;
        !          1052:     INT cSelItemsMax;
        !          1053:     INT iTopIndex;
        !          1054: 
        !          1055:     switch (nCmd)
        !          1056:     {
        !          1057:         case DID_MSGSLIST:
        !          1058:             if (nNotifyCode == LBN_SELCHANGE)
        !          1059:             {
        !          1060:                 hwndList = GetDlgItem(hwnd, DID_MSGSLIST);
        !          1061:                 cItems = SendMessage(hwndList, LB_GETSELITEMS,
        !          1062:                     gcMessages, (LPARAM)gaiSelected2);
        !          1063:                 if (cItems == gcItemsSave)
        !          1064:                 {
        !          1065:                     //
        !          1066:                     // Nothing changed except for the selection
        !          1067:                     // rectangle moving.  We are done.
        !          1068:                     //
        !          1069:                     break;
        !          1070:                 }
        !          1071: 
        !          1072:                 if (cItems > gcItemsSave)
        !          1073:                 {
        !          1074:                     //
        !          1075:                     // A message was selected.  Look for it.
        !          1076:                     //
        !          1077:                     for (i = 0; i < gcItemsSave &&
        !          1078:                         gaiSelected[i] == gaiSelected2[i]; i++)
        !          1079:                         ;
        !          1080: 
        !          1081:                     iSel = gaiSelected2[i];
        !          1082:                     fSel = TRUE;
        !          1083:                 }
        !          1084:                 else
        !          1085:                 {
        !          1086:                     //
        !          1087:                     // A message was unselected.  Look for it.
        !          1088:                     //
        !          1089:                     for (i = 0; i < cItems &&
        !          1090:                         gaiSelected[i] == gaiSelected2[i]; i++)
        !          1091:                         ;
        !          1092: 
        !          1093:                     iSel = gaiSelected[i];
        !          1094:                     fSel = FALSE;
        !          1095:                 }
        !          1096: 
        !          1097:                 //
        !          1098:                 // Get the currently selected item.  It was either
        !          1099:                 // just turned on or off.
        !          1100:                 //
        !          1101:                 pmd = (PMSGDESC)SendMessage(hwndList, LB_GETITEMDATA, iSel, 0);
        !          1102: 
        !          1103:                 //
        !          1104:                 // Loop through the message groups and update the use
        !          1105:                 // counts for all groups that contain this message.
        !          1106:                 //
        !          1107:                 for (i = 0; i < gcMsgGroups; i++)
        !          1108:                 {
        !          1109:                     if (pmd->Flags & gaMsgGroup[i].flMask)
        !          1110:                     {
        !          1111:                         gaMsgGroup[i].cUseCount += fSel ? 1 : -1;
        !          1112:                     }
        !          1113:                 }
        !          1114: 
        !          1115:                 //
        !          1116:                 // Be sure that the checkboxes reflect the updated
        !          1117:                 // status of the message group use counts.
        !          1118:                 //
        !          1119:                 MessagesUpdateCheckBoxes(hwnd);
        !          1120: 
        !          1121:                 //
        !          1122:                 // Save away the new selected item array.
        !          1123:                 //
        !          1124:                 cSelItemsMax = max(cItems, gcItemsSave);
        !          1125:                 for (i = 0; i < cSelItemsMax; i++)
        !          1126:                 {
        !          1127:                     gaiSelected[i] = gaiSelected2[i];
        !          1128:                 }
        !          1129: 
        !          1130:                 gcItemsSave = cItems;
        !          1131:             }
        !          1132: 
        !          1133:             break;
        !          1134: 
        !          1135:         case DID_MSGSALL:
        !          1136:             hwndList = GetDlgItem(hwnd, DID_MSGSLIST);
        !          1137:             SendMessage(hwndList, LB_SETSEL, TRUE, (LPARAM)-1);
        !          1138: 
        !          1139:             for (i = 0; i < gcMsgGroups; i++)
        !          1140:             {
        !          1141:                 gaMsgGroup[i].cUseCount = gaMsgGroup[i].cMsgs;
        !          1142:                 CheckDlgButton(hwnd, gaMsgGroup[i].idCheckBox, 1);
        !          1143:             }
        !          1144: 
        !          1145:             gcItemsSave = SendMessage(hwndList, LB_GETSELITEMS, gcMessages,
        !          1146:                 (LPARAM)gaiSelected);
        !          1147: 
        !          1148:             CheckDlgButton(hwnd, DID_MSGSUSER, 1);
        !          1149:             CheckDlgButton(hwnd, DID_MSGSUNKNOWN, 1);
        !          1150: 
        !          1151:             break;
        !          1152: 
        !          1153:         case DID_MSGSNONE:
        !          1154:             hwndList = GetDlgItem(hwnd, DID_MSGSLIST);
        !          1155:             SendMessage(hwndList, LB_SETSEL, FALSE, (LPARAM)-1);
        !          1156: 
        !          1157:             for (i = 0; i < gcMsgGroups; i++)
        !          1158:             {
        !          1159:                 gaMsgGroup[i].cUseCount = 0;
        !          1160:                 CheckDlgButton(hwnd, gaMsgGroup[i].idCheckBox, 0);
        !          1161:             }
        !          1162: 
        !          1163:             gcItemsSave = 0;
        !          1164: 
        !          1165:             CheckDlgButton(hwnd, DID_MSGSUSER, 0);
        !          1166:             CheckDlgButton(hwnd, DID_MSGSUNKNOWN, 0);
        !          1167: 
        !          1168:             break;
        !          1169: 
        !          1170:         case DID_MSGSDDE:
        !          1171:         case DID_MSGSCLIP:
        !          1172:         case DID_MSGSMOUSE:
        !          1173:         case DID_MSGSNC:
        !          1174:         case DID_MSGSKEYBD:
        !          1175:         case DID_MSGSBM:
        !          1176:         case DID_MSGSCB:
        !          1177:         case DID_MSGSEM:
        !          1178:         case DID_MSGSLB:
        !          1179:         case DID_MSGSSTM:
        !          1180:             for (i = 0; i < gcMsgGroups; i++)
        !          1181:             {
        !          1182:                 if (gaMsgGroup[i].idCheckBox == nCmd)
        !          1183:                 {
        !          1184:                     pmg = &gaMsgGroup[i];
        !          1185:                     break;
        !          1186:                 }
        !          1187:             }
        !          1188: 
        !          1189:             fChecked = IsDlgButtonChecked(hwnd, pmg->idCheckBox);
        !          1190:             if (fChecked == 1)
        !          1191:                 fChecked = FALSE;
        !          1192:             else
        !          1193:                 fChecked = TRUE;
        !          1194: 
        !          1195:             hwndList = GetDlgItem(hwnd, DID_MSGSLIST);
        !          1196: 
        !          1197:             if (fChecked)
        !          1198:             {
        !          1199:                 SendMessage(hwndList, WM_SETREDRAW, FALSE, 0);
        !          1200:                 iTopIndex = SendMessage(hwndList, LB_GETTOPINDEX, 0, 0);
        !          1201:             }
        !          1202: 
        !          1203:             //
        !          1204:             // Get the list of currently selected items.
        !          1205:             //
        !          1206:             cItems = SendMessage(hwndList, LB_GETSELITEMS,
        !          1207:                 gcMessages, (LPARAM)gaiSelected);
        !          1208: 
        !          1209:             //
        !          1210:             // Look for all the messages in this group.
        !          1211:             //
        !          1212:             for (i = 0, iSel = 0; i < gcMessages; i++)
        !          1213:             {
        !          1214:                 pmd = (PMSGDESC)SendMessage(hwndList, LB_GETITEMDATA, i, 0);
        !          1215:                 if (pmd->Flags & pmg->flMask)
        !          1216:                 {
        !          1217:                     //
        !          1218:                     // Bump up through the list of selected items, looking
        !          1219:                     // to see if this item is currently selected.
        !          1220:                     //
        !          1221:                     for (fSel = FALSE; iSel < cItems &&
        !          1222:                         gaiSelected[iSel] <= i; iSel++)
        !          1223:                     {
        !          1224:                         //
        !          1225:                         // A match was found.  The item is selected.
        !          1226:                         //
        !          1227:                         if(gaiSelected[iSel] == i)
        !          1228:                         {
        !          1229:                             fSel = TRUE;
        !          1230:                             break;
        !          1231:                         }
        !          1232:                     }
        !          1233: 
        !          1234:                     //
        !          1235:                     // Is the current selection state of the item
        !          1236:                     // different from the desired selection state?
        !          1237:                     //
        !          1238:                     if (fSel != fChecked)
        !          1239:                     {
        !          1240:                         //
        !          1241:                         // Update the use counts of all groups that contain
        !          1242:                         // this message.
        !          1243:                         //
        !          1244:                         for (j = 0; j < gcMsgGroups; j++)
        !          1245:                         {
        !          1246:                             if (pmd->Flags & gaMsgGroup[j].flMask)
        !          1247:                             {
        !          1248:                                 gaMsgGroup[j].cUseCount += fChecked ? 1 : -1;
        !          1249:                             }
        !          1250:                         }
        !          1251: 
        !          1252:                         //
        !          1253:                         // Select/deselect the message in the list box.
        !          1254:                         //
        !          1255:                         SendMessage(hwndList, LB_SETSEL, fChecked, i);
        !          1256:                     }
        !          1257:                 }
        !          1258:             }
        !          1259: 
        !          1260:             //
        !          1261:             // Be sure that the checkboxes reflect the updated
        !          1262:             // status of the message group use counts.
        !          1263:             //
        !          1264:             MessagesUpdateCheckBoxes(hwnd);
        !          1265: 
        !          1266:             if (fChecked)
        !          1267:             {
        !          1268:                 SendMessage(hwndList, LB_SETTOPINDEX, iTopIndex, 0);
        !          1269:                 SendMessage(hwndList, WM_SETREDRAW, TRUE, 0);
        !          1270:                 InvalidateRect(hwndList, NULL, FALSE);
        !          1271:             }
        !          1272: 
        !          1273:             gcItemsSave = SendMessage(hwndList, LB_GETSELITEMS,
        !          1274:                 gcMessages, (LPARAM)gaiSelected);
        !          1275: 
        !          1276:             break;
        !          1277: 
        !          1278:         case IDOK:
        !          1279:             hwndList = GetDlgItem(hwnd, DID_MSGSLIST);
        !          1280:             cItems = SendMessage(hwndList, LB_GETSELITEMS,
        !          1281:                 gcMessages, (LPARAM)gaiSelected);
        !          1282: 
        !          1283:             //
        !          1284:             // Unselect all messages.
        !          1285:             //
        !          1286:             for (i = 0; i < gcMessages; i++)
        !          1287:                 gaMsgs[i].Flags &= ~MTF_SELECTED;
        !          1288: 
        !          1289:             //
        !          1290:             // Mark all the messages that are selected.
        !          1291:             //
        !          1292:             for (i = 0; i < cItems; i++)
        !          1293:             {
        !          1294:                 pmd = (PMSGDESC)SendMessage(hwndList, LB_GETITEMDATA,
        !          1295:                     gaiSelected[i], 0);
        !          1296:                 pmd->Flags |= MTF_SELECTED;
        !          1297:             }
        !          1298: 
        !          1299:             if (IsDlgButtonChecked(hwnd, DID_MSGSUSER))
        !          1300:                 gfMsgsUser = TRUE;
        !          1301:             else
        !          1302:                 gfMsgsUser = FALSE;
        !          1303: 
        !          1304:             if (IsDlgButtonChecked(hwnd, DID_MSGSUNKNOWN))
        !          1305:                 gfMsgsUnknown = TRUE;
        !          1306:             else
        !          1307:                 gfMsgsUnknown = FALSE;
        !          1308: 
        !          1309: #if 0  //Debug code!
        !          1310: for (i = 0; i < gcMsgGroups; i++)
        !          1311: {
        !          1312:     iSel = 0;
        !          1313:     for (j = 0; j < cItems; j++)
        !          1314:     {
        !          1315:         pmd = (PMSGDESC)SendMessage(hwndList, LB_GETITEMDATA,
        !          1316:             gaiSelected[j], 0);
        !          1317:         if (pmd->Flags & gaMsgGroup[i].flMask)
        !          1318:             iSel++;
        !          1319:     }
        !          1320: 
        !          1321:     if (iSel != gaMsgGroup[i].cUseCount)
        !          1322:     {
        !          1323:         DbgPrintf("Use counts are wrong!!!");
        !          1324:         for (j = 0; j < gcMsgGroups; j++)
        !          1325:         {
        !          1326:             DbgPrintf("cMsgs:%d Use:%d", gaMsgGroup[j].cMsgs, gaMsgGroup[j].cUseCount);
        !          1327:         }
        !          1328:     }
        !          1329: }
        !          1330: #endif // end debug code
        !          1331: 
        !          1332:             EndDialog(hwnd, IDOK);
        !          1333:             return TRUE;
        !          1334: 
        !          1335:         case IDCANCEL:
        !          1336:             EndDialog(hwnd, IDCANCEL);
        !          1337:             return TRUE;
        !          1338:     }
        !          1339: 
        !          1340:     return FALSE;
        !          1341: }
        !          1342: 
        !          1343: 
        !          1344: 
        !          1345: /*****************************************************************************\
        !          1346: * MessagesUpdateCheckBoxes
        !          1347: *
        !          1348: * Updates the message group checkboxes in the Messages dialog.
        !          1349: * This routine should be called when the use counts in the
        !          1350: * message group table are changed, so that the state of the
        !          1351: * checkboxes will get updated also.
        !          1352: *
        !          1353: * Arguments:
        !          1354: *   HWND hwnd - Dialog window handle.
        !          1355: *
        !          1356: * Returns:
        !          1357: *   VOID
        !          1358: \*****************************************************************************/
        !          1359: 
        !          1360: PRIVATE VOID
        !          1361: MessagesUpdateCheckBoxes(
        !          1362:     HWND hwnd
        !          1363:     )
        !          1364: {
        !          1365:     INT i;
        !          1366:     INT fState;
        !          1367: 
        !          1368:     for (i = 0; i < gcMsgGroups; i++)
        !          1369:     {
        !          1370:         if (gaMsgGroup[i].cUseCount == gaMsgGroup[i].cMsgs)
        !          1371:             fState = 1;
        !          1372:         else if (gaMsgGroup[i].cUseCount == 0)
        !          1373:             fState = 0;
        !          1374:         else
        !          1375:             fState = 2;
        !          1376: 
        !          1377:         CheckDlgButton(hwnd, gaMsgGroup[i].idCheckBox, fState);
        !          1378:     }
        !          1379: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.