File:  [OS/2 SDKs] / os232sdk / toolkt20 / c / samples / spy / window.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 12:26:30 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: os2sdk-1990, HEAD
Microsoft OS/2 SDK 2.0 05-30-1990

/****************************** Module Header ******************************\
* Module Name:  window.c - Spy Window dialog functions.
*
* Created: Microsoft, IBM Corporation 1990
*
\***************************************************************************/

#define INCL_WIN
#define INCL_WINSYS
#define INCL_DOSPROCESS
#include <os2.h>
#include <stdio.h>
#include <string.h>
#include "spy.h"
#include "spyhk32.h"
#include <time.h>
#include <stdlib.h>


/************* GLOBAL VARIABLES         */




/************* PROCEDURE DECLARATIONS   */

void    InitWindowList(HWND, HWND, int);
void    BuildWindowWatchList(void);
void    DisplayWindowInfo(HWND, HWND);


void    SelectWindowFromText(HWND);
SHORT   DumpWindowInfo(HWND, SHORT);
int _cdecl CompareHwnds(const void *, const void *);




/**************************** Public Function ******************************\
* MRESULT EXPENTRY SpyWindowsDlgProc(hwnd, msg, mp1, mp2)
*
* Effects: The Spy Windows Dialog procedure
*
* Return value: none
\***************************************************************************/
MRESULT EXPENTRY SpyWindowsDlgProc(hwnd, msg, mp1, mp2)
HWND hwnd;
USHORT msg;
MPARAM mp1;
MPARAM mp2;
{
    BOOL        fSelect = TRUE;
    SHORT       cWindows;
    HWND        hwndPoint;
    HWND        hwndItem;   /* from handle of list item */
    USHORT      iItemFocus; /* Index to item that has the focus */

    switch (msg) {

    case WM_INITDLG:
        /* Initialize the dialog items */
        hwndWindowLB = WinWindowFromID(hwnd, DID_WINDOWLIST);
        InitWindowList(hwnd, HWND_DESKTOP, 0);
        InitWindowList(hwnd, HWND_OBJECT, -10);
        hwndWinDlgDisp = NULL;
        fTrackingListBox = TRUE;
        break;

    case WM_CHAR:
        /*
         * Handle VK_ENTER and VK_NEWLINE if our Edit control has
         * the focus and it is a keydown
         */
        if (!(SHORT1FROMMP(mp1) & KC_KEYUP) &&
                (SHORT1FROMMP(mp1) & KC_VIRTUALKEY) &&
                ( (SHORT2FROMMP(mp2) == VK_ENTER) ||
                  (SHORT2FROMMP(mp2) == VK_NEWLINE) )) {


            if (WinQueryFocus(HWND_DESKTOP, FALSE) ==
                    WinWindowFromID(hwnd, DID_WHANDLE)) {
                SelectWindowFromText(hwnd);
                break;
            }
        }

        /* Normaly pass to dialog procedure to handle message */
        return(WinDefDlgProc(hwnd, msg, mp1, mp2));
        break;

    case WM_COMMAND:
        switch (SHORT1FROMMP(mp1)) {
        case DID_OK:
            BuildWindowWatchList();
        case DID_CANCEL:
            /* Now dismiss the dialog */
            WinDismissDlg(hwnd, SHORT1FROMMP(mp1));
            break;
        case DID_WUNSELALL:
            fSelect = FALSE;
        case DID_WSELALL:
            cWindows = (SHORT) WinSendMsg(hwndWindowLB, LM_QUERYITEMCOUNT,
                0L, 0L);

            fTrackingListBox = FALSE;
            while (cWindows) {
                /* Loop through all windows, selecting or unselcting all */
                WinSendMsg(hwndWindowLB, LM_SELECTITEM, (MPARAM)--cWindows,
                    (MPARAM)fSelect);
            }
            fTrackingListBox = TRUE;
            break;

        case DID_WSELMOUSE:
            /* Call function to track mouse, returns window handle */
            hwndPoint = HwndSelWinWithMouse(hwnd, DisplayWindowInfo, FALSE);
            if (hwndPoint == NULL)
        break;    /* No window to process */

            /*
             * Now find the window in the list, Make the item visible
             * and set the item as selected.
             */
            cWindows = (SHORT) WinSendMsg(hwndWindowLB, LM_QUERYITEMCOUNT,
                    0L, 0L);

            while (cWindows) {
                /*
                 * Loop through all windows until we wind the right
                 * one with the correct window handle
                 */
                hwndItem = (HWND)WinSendMsg(hwndWindowLB, LM_QUERYITEMHANDLE,
                        (MPARAM)--cWindows, 0L);

                if (hwndItem == hwndPoint) {
                    /* found the right item, move it to top */
                    WinSendMsg(hwndWindowLB, LM_SETTOPINDEX, (MPARAM)cWindows, 0L);
                    WinSendMsg(hwndWindowLB, LM_SELECTITEM, (MPARAM)cWindows,
                            (MPARAM)TRUE);
                    break;
                }
            }
            break;

        }
        break;


    default:
        /*
         * Default is to see if the listbox has changed its focus
         * item number.  If it has, then we want to display the information
         * about the window that the listbox cursor is over.  There is no
         * legal way to do this, One approach appears to temporary set the
         * listbox to be a single selection listbox, then query its selection
         * and set it back into multiple selection mode.
         */
        if (fTrackingListBox && hwndWindowLB != NULL) {

            WinSetWindowBits(hwndWindowLB, QWL_STYLE, 0L, LS_MULTIPLESEL);
            iItemFocus = (USHORT)WinSendMsg(hwndWindowLB, LM_QUERYSELECTION,
                    (MPARAM)LIT_FIRST, 0L);
            WinSetWindowBits(hwndWindowLB, QWL_STYLE, LS_MULTIPLESEL,
                    LS_MULTIPLESEL);

            if (iItemFocus != iCurItemFocus) {
                iCurItemFocus = iItemFocus;
                if (iItemFocus != (USHORT)-1) {

                    hwndItem = (HWND)WinSendMsg(hwndWindowLB, LM_QUERYITEMHANDLE,
                            (MPARAM)iItemFocus, 0L);
                    DisplayWindowInfo(hwnd, hwndItem);
                }
            }
        }
        return(WinDefDlgProc(hwnd, msg, mp1, mp2));
    }
    return 0L;
}




/***************************** Private Function ****************************\
* void SelectWindowFromText(hwndDlg)
*
* Effects:
*   Updates the text that is displayed in the message text line
*
* History:
*   27-September-1988 KurtE
\***************************************************************************/
void SelectWindowFromText(hwndDlg)
HWND    hwndDlg;
{
    char    szTemp[80];
    HWND    hwndSelect;
    SHORT   cItems;
    SHORT   i;


    /* First get the edit text from the string */
    WinQueryDlgItemText(hwndDlg, DID_WHANDLE, sizeof(szTemp),
            (PSZ)szTemp);

    hwndSelect = (HWND)UConvertStringToNum(szTemp);

    cItems = (SHORT)WinSendMsg(hwndWindowLB, LM_QUERYITEMCOUNT,
            0L, 0L);

    for (i=0; i < cItems; i++) {
        if ((HWND)WinSendMsg(hwndWindowLB, LM_QUERYITEMHANDLE,
                (MPARAM)i, 0L) == hwndSelect)
            break;  /* found it */
    }

    if (i < cItems) {
        /*
         * found the hwnd, bring to top, and select it
         */
        WinSendMsg(hwndWindowLB, LM_SETTOPINDEX,
                MPFROMSHORT(i),  (MPARAM)0L);

        /* Always set it on */
        WinSendMsg(hwndWindowLB, LM_SELECTITEM,
                MPFROMSHORT(i), MPFROMSHORT(TRUE));

    } else {
        WinAlarm(HWND_DESKTOP, WA_WARNING);
        WinSetDlgItemText(hwndDlg, DID_WHANDLE, (PSZ)"");
    }

}


/**************************** Private Function ******************************\
* InitWindowList (hwndDialog, hwnd, level)
*
* Effects: Builds the list of windows displayed in the windows dialog
*
*
* Return value:
\***************************************************************************/
void InitWindowList(hwndDialog, hwnd, level)
HWND    hwndDialog;
HWND    hwnd;
int     level;
{
    char    szTemp[30];
    char    szId[20];
    HWND    hwndT;
    USHORT  item;
    USHORT  id;
    int     i;

    /*
     * We will first add this item to our list of
     * items in the listbox, If the item is in our list of hwnds,
     * set the item selected. To keep from getting into endless loops
     * will not add spywindow client, and descendants.
     */
    if (hwnd != hwndSpy) {
        id = (USHORT)WinQueryWindowUShort(hwnd, QWS_ID);
        sprintf(szId, "ID: %x", id);

        for (i = 0; i < cToName; i++) {
            if (id == rgidtoname[i].id) {
                strcpy (szId, rgidtoname[i].szIdName);
                break;
            }
        }

        sprintf(szTemp, "%04x(%d) - %s", (USHORT)hwnd, level, szId);
        item = (USHORT)WinSendMsg(hwndWindowLB, LM_INSERTITEM,
                (MPARAM)LIT_END, (MPARAM)(PSZ)szTemp);

        /* Set the item handle to the handle of the window */
        WinSendMsg(hwndWindowLB, LM_SETITEMHANDLE, (MPARAM)item,
                (MPARAM)hwnd);

        if (SpyFWindowInList(hwnd, TRUE))
            WinSendMsg(hwndWindowLB, LM_SELECTITEM, (MPARAM)item,
                (MPARAM)TRUE);

        /*
         * Then we recurse with all of our children
         */
        if ((hwndT = WinQueryWindow(hwnd, QW_TOP, FALSE)) != NULL)
            InitWindowList(hwndDialog, hwndT, level+1);
    }

    /*
     * Then go to our next sibling
     */
    if ((hwndT = WinQueryWindow(hwnd, QW_NEXT, FALSE)) != NULL)
        InitWindowList(hwndDialog, hwndT, level);
}



/**************************** Private Function *****************************\
* BuildWindowWatchList()
*
* Effects: Updates the list of windows to be watched from the listbox
*
*
* Return value:
\***************************************************************************/
void BuildWindowWatchList()
{

    USHORT  itemPrevious;
    USHORT  item;
    HWND    hwnd;

    SHORT   chwnd;
    HWND    rghwnd[MAXHWNDS];

    /*
     * Simply loop through asking for the next selected item in the
     * list.  Make sure not to overrun our list.
     */
    itemPrevious = (USHORT)LIT_FIRST;
    chwnd = 0;

    while ((item = (USHORT)WinSendMsg(hwndWindowLB, LM_QUERYSELECTION,
            (MPARAM)itemPrevious, 0L)) != (USHORT)LIT_NONE) {
        /*
         * Get the items handle, which has the value of the window handle
         */
        hwnd = (HWND)WinSendMsg(hwndWindowLB, LM_QUERYITEMHANDLE,
                (MPARAM)item, 0L);

        /* Make sure it still is a valid window */
        if (WinIsWindow(hab, hwnd)) {
            rghwnd[chwnd++] = hwnd;
            if (chwnd >= MAXHWNDS)
                break;  /* Dont overflow array */
        }

        itemPrevious = item;    /* Where to cointinue the search */
    }

    SpySetWindowList (chwnd, rghwnd);
}


/**************************** Public Function ******************************\
* HWND HwndSelWinWithMouse(HWND hwnd, void (*pfnDisplayInfo)(HWND, HWND),
*                          BOOL fFrameOnly)
*
* Effects: This function is used to allow the user to select a window with
*           the mouse.  If fDisplayInfo is TRUE, it will update the
*           information in the dialog box, about the window that the
*           mouse is currently over.
*
* Return value: none
\***************************************************************************/
HWND HwndSelWinWithMouse(hwnd, pfnDisplayInfo, fFrameOnly)
HWND hwnd;
void (*pfnDisplayInfo)(HWND, HWND);
BOOL fFrameOnly;
{

    QMSG        qmsg;
    HWND        hwndPoint;
    char        szClassName[50];    /* Class name of window */
    CLASSINFO   classinfo;          /* Information about class */


    /*
     * First set the capture to the specified window
     */
    WinSetCapture(HWND_DESKTOP, hwnd);
    WinSetPointer (HWND_DESKTOP, hptrSelWin);

    /*
     * Now loop through all of the messages that are sent, until
     * we get our mouse 1 down message.  We will also filter out
     * the WM_MOVE message, else we will dispatch the messages.
     */
    while (WinGetMsg(hab, &qmsg, NULL, 0, 0)) {
        if (qmsg.msg == WM_MOUSEMOVE) {
            if (pfnDisplayInfo != NULL) {
                hwndPoint = WinWindowFromPoint(HWND_DESKTOP,
                    &qmsg.ptl, TRUE, FALSE);
                (*pfnDisplayInfo)(hwnd, hwndPoint);
            }
        }
        else if (qmsg.msg == WM_BUTTON1DOWN)
            break;
        else
            WinDispatchMsg(hab, &qmsg);
    }

    WinSetPointer (HWND_DESKTOP, hptrArrow);
    WinSetCapture(HWND_DESKTOP, NULL);


    /*
     * Map the point to the window,  If the CTRL-Key is down,
     * we will go up through the parent chain until we get to
     * a frame window or desktop.  Dont let hwndSpy through!!!
     */
    hwndPoint = WinWindowFromPoint(HWND_DESKTOP,
        &qmsg.ptl, TRUE, FALSE);
    if (fFrameOnly || WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x8000) {
        /* Asked for frame window */
        for (;;) {
            if (hwndPoint == NULL)
                return (NULL);         /* No frames available */
            /* See if frame class */
            WinQueryClassName(hwndPoint, sizeof(szClassName),
                (PSZ)szClassName);
            if (WinQueryClassInfo(hab, (PSZ)szClassName, &classinfo) &&
                    (classinfo.flClassStyle & CS_FRAME))
                break;  /* We have our frame */

            /* Not frame, go back to parent */
            hwndPoint = WinQueryWindow(hwndPoint, QW_PARENT, FALSE);
        }
    }

    if (pfnDisplayInfo != NULL)
        (*pfnDisplayInfo)(hwnd, hwndPoint);

    if (WinIsChild(hwndPoint, hwndSpy))
        return (NULL);    /* Dont want to get in endless loops */

    return (hwndPoint);
}



/**************************** Private Function *****************************\
* DisplayWindowInfo(HWND hwndDialog, HWND hwnd)
*
* Effects: Displays the information about the selected window in the dialog
*
*
* Return value:
\***************************************************************************/
void DisplayWindowInfo(hwndDlg, hwnd)
HWND            hwndDlg;
HWND            hwnd;
{
    HWND        hwndT;
    HWND        hwndParent;
    char        szTemp[50];
    char        szTemp2[10];
    CLASSINFO   classinfo;
    RECTL       rcl;
    USHORT      id;
    ULONG       ul;
    USHORT      us1;
    USHORT      us2;
    USHORT      us3;
    USHORT      us4;
    PID         pidWindow;
    TID         tidWindow;


    if (hwnd != hwndWinDlgDisp)
    {
        hwndWinDlgDisp = hwnd;

        /* This could be table driven */
        sprintf(szTemp, "%p", hwnd);
        WinSetDlgItemText(hwndDlg, DID_WHANDLE, (PSZ)szTemp);

        /*
         * Make sure the window has not been deleted
         */
        if (WinIsWindow(hab, hwnd)) {
            WinQueryClassName(hwnd, sizeof(szTemp), (PSZ)szTemp);
            if (!WinQueryClassInfo(hab, (PSZ)szTemp, &classinfo)) {
                classinfo.flClassStyle = -1;    /* Let know error conditon */
                classinfo.cbWindowData = 0;     /* Make sure we dont dump */
            }

            WinSetDlgItemText(hwndDlg, DID_WCLASS, (PSZ)szTemp);


            /*
             * Warning, we only query the text if the window is not an object
             * window.  If it is an object window, the message queue may not
             * be processing messages, which could hang us
             */
            if (WinIsChild(hwnd, HWND_OBJECT))
                szTemp[0] = '\0';   /* No text available */
            else
                WinQueryWindowText(hwnd, sizeof(szTemp), (PSZ)szTemp);
            WinSetDlgItemText(hwndDlg, DID_WTEXT, (PSZ)szTemp);

            hwndParent = WinQueryWindow(hwnd, QW_PARENT, FALSE);
            sprintf(szTemp, "%p", hwndParent);
            WinSetDlgItemText(hwndDlg, DID_WPARENT, (PSZ)szTemp);

            hwndT = WinQueryWindow(hwnd, QW_TOP, FALSE);
            sprintf(szTemp, "%p", hwndT);
            WinSetDlgItemText(hwndDlg, DID_WCHILD, (PSZ)szTemp);

            hwndT = WinQueryWindow(hwnd, QW_OWNER, FALSE);
            sprintf(szTemp, "%p", hwndT);
            WinSetDlgItemText(hwndDlg, DID_WOWNER, (PSZ)szTemp);

            WinQueryWindowRect(hwnd, &rcl);
            WinMapWindowPoints(hwnd, hwndParent, (PPOINTL)&rcl, 2);
            sprintf(szTemp, "(%d, %d), (%d, %d)", (SHORT)rcl.xLeft,
                (SHORT)rcl.yBottom, (SHORT)rcl.xRight, (SHORT)rcl.yTop);
            WinSetDlgItemText(hwndDlg, DID_WRECT, (PSZ)szTemp);

            id = (USHORT)WinQueryWindowUShort(hwnd, QWS_ID);
            sprintf(szTemp, "0x%04x", id);
            WinSetDlgItemText(hwndDlg, DID_WID, (PSZ)szTemp);

            ul = (ULONG)WinQueryWindowULong(hwnd, QWL_STYLE);
            sprintf(szTemp, "0x%08lx", ul);
            WinSetDlgItemText(hwndDlg, DID_WSTYLE, (PSZ)szTemp);

            sprintf(szTemp, "0x%08lx", classinfo.flClassStyle);
            WinSetDlgItemText(hwndDlg, DID_WCSTYLE, (PSZ)szTemp);

            ul = (ULONG)WinQueryWindowULong(hwnd, QWP_PFNWP);
            sprintf(szTemp, "%p", ul);
            WinSetDlgItemText(hwndDlg, DID_WPFNWP, (PSZ)szTemp);

            ul = (ULONG)WinQueryWindowULong(hwnd, QWL_HMQ);
            sprintf(szTemp, "0x%04x", (SHORT)ul);
            WinSetDlgItemText(hwndDlg, DID_WHMQ, (PSZ)szTemp);

            WinQueryWindowProcess(hwnd, &pidWindow, &tidWindow);
            sprintf(szTemp, "%d", pidWindow);
            WinSetDlgItemText(hwndDlg, DID_WPID, (PSZ)szTemp);
            sprintf(szTemp, "%d", tidWindow);
            WinSetDlgItemText(hwndDlg, DID_WTID, (PSZ)szTemp);

            /*
             * We have four General purpose lines left, used only for
             * frames now
             */
            if ((classinfo.flClassStyle & CS_FRAME) &&
                        (classinfo.cbWindowData > QWL_HWNDFOCUSSAVE)) {
                ul = (ULONG)WinQueryWindowULong(hwnd, QWL_HWNDFOCUSSAVE);
                sprintf(szTemp, "Frame Focus: %p",ul);
                WinSetDlgItemText(hwndDlg, DID_WOLINE1, (PSZ)szTemp);

                us1 = (USHORT)WinQueryWindowUShort(hwnd, QWS_FLAGS);
                us2 = (USHORT)WinQueryWindowUShort(hwnd, QWS_RESULT);
                sprintf(szTemp, "Flags: 0x%04x Rslt: 0x%04x", us1, us2);
                WinSetDlgItemText(hwndDlg, DID_WOLINE2, (PSZ)szTemp);

                us1 = (USHORT)WinQueryWindowUShort(hwnd, QWS_XRESTORE);
                us2 = (USHORT)WinQueryWindowUShort(hwnd, QWS_YRESTORE);
                us3 = (USHORT)WinQueryWindowUShort(hwnd, QWS_CXRESTORE);
                us4 = (USHORT)WinQueryWindowUShort(hwnd, QWS_CYRESTORE);
                sprintf(szTemp, "Restore: (%d, %d, %d, %d)",us1, us2, us3, us4);
                WinSetDlgItemText(hwndDlg, DID_WOLINE3, (PSZ)szTemp);

                us1 = (USHORT)WinQueryWindowUShort(hwnd, QWS_XMINIMIZE);
                us2 = (USHORT)WinQueryWindowUShort(hwnd, QWS_YMINIMIZE);
                sprintf(szTemp, "Minimize: (%d, %d)",us1, us2);
                WinSetDlgItemText(hwndDlg, DID_WOLINE4, (PSZ)szTemp);
            } else {
                /*
                 * Nothing special to output for this window type, so lets
                 * dump the window extra words.
                 * Note: This code is sh.ty
                 */
                us1 = 0;    /* Word offset */
                for (id=DID_WOLINE1; id <= DID_WOLINE4; id++) {
                    szTemp[0] = '\0';
                    for (us2 = 0; us2 < 4; us2++) {
                        if (us1 >= classinfo.cbWindowData)
                            break;
                        us3 = (USHORT)WinQueryWindowUShort(hwnd, us1);
                        sprintf(szTemp2, "%04x ", us3);
                        strcat(szTemp, szTemp2);
                        us1 += 2;   /* Setup for next word */
                    }

                    /* output this line */
                    WinSetDlgItemText(hwndDlg, id, (PSZ)szTemp);
                }
            }
        } else {
            /*
             * Window was deleted, Show the window text as deleted, and
             * clear out the remaining fields.
             */
            WinSetDlgItemText(hwndDlg, DID_WTEXT, (PSZ)"*** Deleted ***");
            szTemp[0] = '\0';
            for (id=DID_WCLASS; id <= DID_WOLINE4; id++) {
                WinSetDlgItemText(hwndDlg, id, (PSZ)szTemp);
            }
        }
    }
}




/**************************** Public Function ******************************\
* DumpOneWindowInfo()
*
* Effects: Dump the information about one window to the current outputs
*
* Return value: none
\***************************************************************************/
void    DumpOneWindowInfo()
{
    HWND        hwndPoint;
    HWND        hwndT;
    SHORT       wLevel;

    hwndPoint = HwndSelWinWithMouse(hwndSpy, NULL, FALSE);
    if (hwndPoint == NULL)
        return;    /* No window selected */

    /* Now see what level the window is at */
    wLevel = 0;
    hwndT = hwndPoint;
    while (hwndT != NULL) {
        wLevel++;
        hwndT = WinQueryWindow(hwndT, QW_PARENT, FALSE);
    };


    DumpWindowInfo(hwndPoint, wLevel);
}


/**************************** Private Function ******************************\
* DumpAllWIndowsInfo (HWND hwnd, WORD wLevel)
*
* Effects: Dumps the complet window list out to the current output units.
*
*
* Return value:
\***************************************************************************/
SHORT DumpAllWindowsInfo(hwnd, wLevel)
HWND    hwnd;
SHORT   wLevel;
{
    HWND    hwndT;
    SPWD    *pspwdT;
    SHORT   cWindowBytes;

    pspwdT = pspwd + wDumpCount;

    cWindowBytes = DumpWindowInfo(hwnd, wLevel);

    pspwdT->hwnd = hwnd;
    pspwdT->index = wDumpCount;


    /*
     * Then we recurse with all of our children
     */
    if ((hwndT = WinQueryWindow(hwnd, QW_TOP, FALSE)) != NULL)
        cWindowBytes += DumpAllWindowsInfo(hwndT, wLevel+1);

    /*
     * Then go to our next sibling
     */
    if ((hwndT = WinQueryWindow(hwnd, QW_NEXT, FALSE)) != NULL)
        cWindowBytes += DumpAllWindowsInfo(hwndT, wLevel);

    return (cWindowBytes);
}



/**************************** Private Function ******************************\
* DumpWindowIndex (void)
*
* Effects: Dump a sorted list of Hwnds and index into other list
*          This function works like sh.t
*
*
* Return value:
\***************************************************************************/
void    DumpWindowIndex(cBytes)
SHORT   cBytes;
{
    SHORT   cch;
    char    szTemp[20];
    char    szOutput[100];
    SPWD    *pspwdT;
    SHORT   i;

    /* Sort the hwnds first */
    qsort((void *)pspwd, wDumpCount, sizeof(SPWD), CompareHwnds);
    pspwdT = pspwd;

    strcpy (szOutput, "Index of Window Handles");
    cch = strlen(szOutput);
    for (i=0; i< wDumpCount; i++) {
        if ((i & 3) == 0) {
            /* 4 per row */
            OutputString(szOutput, cch);
            szOutput[0] = '\0';
            cch = 0;
        }

        cch += sprintf(szTemp, "%3d-%04x ",
                pspwdT->index,    (USHORT)pspwdT->hwnd);
        strcat (szOutput, szTemp);
        pspwdT++;
    }

    OutputString(szOutput, cch);

    cch = sprintf(szOutput, "Number of Windows: %d, Approx heap size: %d",
            wDumpCount, cBytes);
    OutputString(szOutput, cch);


}


/**************************** Private Function ******************************\
* int  CompareHwnds(SPWD *pspwd1, SPWD *pspwd2)
*
* Effects: Compares two window handles.
*
*
* Return value:
\***************************************************************************/
int  _cdecl CompareHwnds(pspwd1, pspwd2)
const void    *pspwd1;
const void    *pspwd2;
{
    return (((SPWD *)pspwd1)->hwnd < ((SPWD *)pspwd2)->hwnd)? -1 : 1;
}




/**************************** Private Function *****************************\
* DumpWindowInfo(HWND hwnd, SHORT wLevel)
*
* Effects: Displays the information about the selected window in the dialog
*
*
* Return value:
\***************************************************************************/
SHORT DumpWindowInfo(hwnd, wLevel)
HWND        hwnd;
SHORT       wLevel;
{
    HWND    hwndParent;
    HWND    hwndChild;
    HWND    hwndOwner;

    char    szTemp[128];
    char    szTemp2[20];
    SHORT   cch;
    char    szClass[30];
    RECTL   rcl;
    USHORT  id;
    ULONG   ulStyle;
    ULONG   ulPFNWP;
    ULONG   ulHMQ;
    SHORT   wOffsetClassData;
    SHORT   wWindowWord;
    PID     pidWindow;
    TID     tidWindow;

    CLASSINFO   classinfo;

    hwndParent = WinQueryWindow(hwnd, QW_PARENT, FALSE);
    hwndChild = WinQueryWindow(hwnd, QW_TOP, FALSE);
    hwndOwner = WinQueryWindow(hwnd, QW_OWNER, FALSE);
    id = (USHORT)WinQueryWindowUShort(hwnd, QWS_ID);

    cch = sprintf(szTemp,
        "%d-H:%p(%d) P:%p C:%p O:%p ID:%04x",
        ++wDumpCount, hwnd, wLevel, hwndParent,
        hwndChild, hwndOwner, id);

    OutputString(szTemp, cch);

    ulHMQ = (ULONG)WinQueryWindowULong(hwnd, QWL_HMQ);
    WinQueryWindowRect(hwnd, &rcl);
    WinMapWindowPoints(hwnd, hwndParent, (PPOINTL)&rcl, 2);
    ulStyle = (ULONG)WinQueryWindowULong(hwnd, QWL_STYLE);

    cch = sprintf(szTemp,
        "          MQ:%p St:%08lx  Rect: (%d, %d) (%d, %d)",
        ulHMQ, ulStyle,
        (SHORT)rcl.xLeft, (SHORT)rcl.yBottom,
        (SHORT)rcl.xRight, (SHORT)rcl.yTop);
    OutputString(szTemp, cch);

    ulPFNWP = (ULONG)WinQueryWindowULong(hwnd, QWP_PFNWP);
    WinQueryClassName(hwnd, sizeof(szClass), (PSZ)szClass);
    if (!WinQueryClassInfo(hab, (PSZ)szClass, &classinfo)) {
        classinfo.flClassStyle = -1;    /* Let know error conditon */
        classinfo.cbWindowData = 0;     /* Make sure we dont dump */
    }

    WinQueryWindowProcess(hwnd, &pidWindow, &tidWindow);

    cch = sprintf(szTemp,
        "          PID:%d  TID:%d  Pfn:%p  Cl:%s",
        ulStyle, pidWindow, tidWindow, ulPFNWP, szClass);
    OutputString(szTemp, cch);

    /*
     * Dump the window extra words out also.
     */
    strcpy (szTemp, "          ");
    id = 8;
    for (wOffsetClassData = 0; wOffsetClassData < classinfo.cbWindowData;
            wOffsetClassData += 2) {

        wWindowWord = (USHORT)WinQueryWindowUShort(hwnd, wOffsetClassData);
        sprintf(szTemp2, "%04x ", wWindowWord);
        strcat(szTemp, szTemp2);
        if (--id == 0) {
            /* line full is full */
            OutputString(szTemp, strlen(szTemp));
            szTemp[10] = '\0';
            id = 8;
        }
    }

    if (id != 8)
        OutputString(szTemp, strlen(szTemp));

    /* Return the number of bytes associated with the window */
    return ((SIZEOFWND + classinfo.cbWindowData + 3) & 0xfffc);
}


/**************************** Public Function ******************************\
* DumpFrameAcclTable()
*
* Effects: Dump the information about one window to the current outputs
*
* Return value: none
\***************************************************************************/
void    DumpFrameAcclTable()
{
    HWND        hwndPoint;
    HACCEL      haccel;
    ACCELTABLE *npAcclTbl;
    SHORT       cbAccel;
    char        szTemp[100];
    char        szFS[100];
    SHORT       cch;
    ACCEL       *npAccel;
    PID         pidHwnd;
    TID         tidHwnd;
    PPIB        ppib;
    PTIB        ptib;
    SHORT       i;
    SHORT       j;
    char        szChar[2];
    char        *pszChar;

    hwndPoint = HwndSelWinWithMouse(hwndSpy, NULL, TRUE);
    if (hwndPoint == NULL)
        return;

    // Now lets get the accel table for the frame window
    haccel = WinQueryAccelTable(hab, hwndPoint);
    if (haccel == NULL)
        return;

    WinQueryWindowProcess(hwndPoint, &pidHwnd, &tidHwnd);
    DosGetThreadInfo(&ptib, &ppib);
    if (ppib->pib_ulpid == pidHwnd) {
        // It is in our own process, so do it local
        // Allocate memory for the Accel table.  If over 4K to much anyway!
        cbAccel = WinCopyAccelTable(haccel, (PACCELTABLE)NULL, 0);
        npAcclTbl = (ACCELTABLE *)WinAllocMem(hHeap, cbAccel);
        if (npAcclTbl == NULL)
            return;
        WinCopyAccelTable(haccel, npAcclTbl, cbAccel);
    } else {
        // Let the hook do it for us
        /* Lets use the hook */
        SpySetPIDIntercept(pidHwnd, PIT_ACCEL, (ULONG)haccel);

        /* HACK: Send message to frame known to send another message */
        WinSendMsg(hwndPoint, WM_QUERYTASKFOCUS, 0L, 0L);

        // Ask for size
        cbAccel = SpyGetPIDInterceptData(NULL, 0, NULL);
        npAcclTbl = (ACCELTABLE *)WinAllocMem(hHeap, cbAccel);
        if (npAcclTbl == NULL)
            return;
        SpyGetPIDInterceptData((char *)npAcclTbl, cbAccel, NULL);
    }

    // Now Dump the Accel table header
    cch = sprintf(szTemp,"HACCEL:%p for HWND:%p CP:%d CNT:%d",
        haccel, hwndPoint, npAcclTbl->codepage, npAcclTbl->cAccel);
    OutputString(szTemp, cch);

    // Now dump each of the items
    npAccel = npAcclTbl->aaccel;
    szChar[1] = '\0';   // Make it NULL TERMINATED
    for (i=npAcclTbl->cAccel; i > 0; i--) {
        pszChar = szChar;
        if (npAccel->fs & AF_CHAR) {
            if ((npAccel->key >= ' ') && (npAccel->key <= '~'))
                szChar[0] = (char)npAccel->key;
            else
                szChar[0] = ' ';
        } else if (npAccel->fs & AF_VIRTUALKEY) {
            if ((npAccel->key >= ivktosMin) && (npAccel->key < cvktos))
                pszChar = avktos[npAccel->key].szVkey;
            else
                szChar[0] = ' ';
        }
        szFS[0] = '\0';
        for (j=0; j < caftos; j++) {
            if (npAccel->fs & aaftos[j].usBit)
                strcat(szFS, aaftos[j].szBit);
        }

        cch=sprintf(szTemp, "    fs:%x key:%x(%s) cmd:%x - %s",
                npAccel->fs, npAccel->key, pszChar, npAccel->cmd, szFS);
        OutputString(szTemp, cch);
        npAccel++;
    }

    // And free the memory we allocated
    WinFreeMem(hHeap, (NPBYTE)npAcclTbl, cbAccel);
}


/**************************** Public Function ******************************\
* SelOrDeselWithMouse(BOOL fSelect)
*
* Effects: Fastway to add/or remove window from watch list
*
* Return value: none
\***************************************************************************/

void SelOrDeselWithMouse(fSelect)
BOOL    fSelect;
{
    HWND    rghwnd[MAXHWNDS];
    HWND    hwndPoint;
    SHORT    chwnd;
    BOOL    fWinCurInList;
    SHORT    i;

    /* First get the window of interest */
    hwndPoint = HwndSelWinWithMouse(hwndSpy, NULL, FALSE);
    if (hwndPoint == NULL)
        return;    /* No window selected */
    fWinCurInList = SpyFWindowInList(hwndPoint, TRUE);

    if ((fWinCurInList && fSelect)
            || (!fWinCurInList && !fSelect))
        return;        /* Alredy right state */

    chwnd = SpyGetWindowList(MAXHWNDS, (HWND FAR *)rghwnd);

    if (fSelect) {
        /* Add window to end of list */
        rghwnd[chwnd++] = hwndPoint;
    } else {
        /* find it in the list, and delete it out */
        for (i=0; rghwnd[i] != hwndPoint; i++)
            ;

        /* Now copy rest of them down */
        chwnd--;    /* One less item */
        for (;i < chwnd; i++ ) {
            rghwnd[i] = rghwnd[i+1];
        }
    }

    /* Now call to update the list */
    SpySetWindowList(chwnd, (HWND FAR *)rghwnd);
}



unix.superglobalmegacorp.com

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