📄 dialogs.c
字号:
/******************************************************************************\
* This is a part of the Microsoft Source Code Samples.
* Copyright (C) 1993-1997 Microsoft Corporation.
* All rights reserved.
* This source code is only intended as a supplement to
* Microsoft Development Tools and/or WinHelp documentation.
* See these sources for detailed information regarding the
* Microsoft samples programs.
\******************************************************************************/
/*****************************************************************************\
*
* Module: dialogs.c
*
* Contains dialog procs for the Windows debugging Spy SDK applet.
*
* Functions:
*
* MyDialogBox()
* AboutDlgProc()
* SelectWindowDlgProc()
* OutputDlgProc()
* SelectFont()
* MessagesDlgProc()
* SelectWindowCommand()
* FillListBox()
* AddOneWindow()
* MakeWindowName()
* FindHwndInListBox()
* HighlightWindow()
* SelectWindowUpdateInfo()
* SelectWindowEnableFields()
* OutputCommand()
* MessagesInit()
* MessagesCommand()
* MessagesUpdateCheckBoxes()
*
* Comments:
*
\*****************************************************************************/
#include "spy.h"
#include <commdlg.h>
#define DINV 3
PRIVATE HWND ghwndSpyingOnTemp; // Temp when selecting hwnd to spy on.
PRIVATE HWND ghwndDlgBeingFilled = NULL;
PRIVATE BOOL bBorderOn = FALSE;
PRIVATE INT gcItemsSave;
PRIVATE BOOL SelectWindowCommand(HWND hwnd, INT nCmd, INT nNotifyCode);
PRIVATE VOID FillListBox(HWND hDlg, HWND hwndList, HWND hwnd);
BOOL CALLBACK AddOneWindow(HWND hwnd, LPARAM hwndListLP);
PRIVATE VOID MakeWindowName(HWND hwnd, LPSTR lpString, INT nStringLen);
PRIVATE INT FindHwndInListBox(HWND hwndList, HWND hSpyWnd);
PRIVATE VOID HighlightWindow(HWND hwnd, BOOL fDraw);
PRIVATE VOID SelectWindowUpdateInfo(HWND hDlg, HWND hwnd);
PRIVATE VOID SelectWindowEnableFields(HWND hwnd, BOOL fEnable);
PRIVATE BOOL OutputCommand(HWND hwnd, INT nCmd, INT nNotifyCode);
PRIVATE VOID MessagesInit(HWND hwnd);
PRIVATE BOOL MessagesCommand(HWND hwnd, INT nCmd, INT nNotifyCode);
PRIVATE VOID MessagesUpdateCheckBoxes(HWND hwnd);
CHAR szConsoleWindowClass[] = "ConsoleWindowClass";
/*****************************************************************************\
* MyDialogBox
*
* Puts up the specified dialog.
*
* Arguments:
* INT idDlg - The resource id of the dialog to display.
* DLGPROC pfnDlgProc - The dialog proc to use.
*
* Returns:
* The return value from DialogBox (whatever the dialog proc passes
* to EndDialog).
\*****************************************************************************/
BOOL
MyDialogBox(
INT idDlg,
DLGPROC pfnDlgProc
)
{
return DialogBox(ghInst, MAKEINTRESOURCE(idDlg), ghwndSpyApp, pfnDlgProc);
}
/*****************************************************************************\
* AboutDlgProc
*
* Dialog proc for the About box.
*
\*****************************************************************************/
BOOL CALLBACK
AboutDlgProc(
HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam
)
{
switch (msg) {
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
EndDialog(hwnd, IDOK);
break;
}
return FALSE;
}
/*****************************************************************************\
* SelectWindowDlgProc
*
* Dialog proc for the Select Window dialog. This dialog allows the user
* to select which window they want to spy on.
*
* Arguments:
* HWND hwnd - Window handle of the dialog.
* UINT msg - Message sent to window.
* WPARAM wParam - Message parameter.
* LPARAM lParam - Message parameter.
*
* Returns:
* The value that the dialog proc should return, based on the processing
* of the specific WM_COMMAND message received.
\*****************************************************************************/
BOOL CALLBACK
SelectWindowDlgProc(
HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam
)
{
HWND hwndList;
INT nIndex;
UNREFERENCED_PARAMETER(lParam);
switch (msg)
{
case WM_INITDIALOG:
hwndList = GetDlgItem(hwnd, DID_SELWINLIST);
ghwndSpyingOnTemp = ghwndSpyingOn == HWND_ALL ? NULL : (ghwndSpyingOn == NULL ? NULL
: GetParent(ghwndSpyingOn));
FillListBox(hwnd, hwndList, ghwndSpyingOnTemp);
nIndex = FindHwndInListBox(hwndList, ghwndSpyingOn == HWND_ALL ? NULL
: ghwndSpyingOn);
SendMessage(hwndList, LB_SETCURSEL, nIndex, 0);
ghwndSpyingOnTemp = (HWND)SendMessage(hwndList, LB_GETITEMDATA, nIndex, 0);
SelectWindowUpdateInfo(hwnd, ghwndSpyingOnTemp);
CheckDlgButton(hwnd, DID_SELWINALLWINDOWS, gfSpyAll);
SelectWindowEnableFields(hwnd, !gfSpyAll);
SetFocus(hwnd);
HighlightWindow(ghwndSpyingOnTemp, TRUE);
return TRUE;
case WM_NCLBUTTONDOWN:
if (wParam == HTCAPTION)
{
//
// The mouse is down for a move of the dialog, so clean up the
// border stuff.
//
if (bBorderOn)
HighlightWindow(ghwndSpyingOnTemp, FALSE);
}
return FALSE;
case WM_KEYDOWN:
case WM_LBUTTONUP:
case WM_NCLBUTTONUP:
//
// The mouse is up from a move of the dialog, so put up the
// border stuff again.
//
if (!bBorderOn)
HighlightWindow(ghwndSpyingOnTemp, TRUE);
return FALSE;
case WM_CANCELMODE:
return FALSE;
case WM_COMMAND:
return SelectWindowCommand(hwnd, LOWORD(wParam), HIWORD(wParam));
}
return FALSE;
}
/*****************************************************************************\
* SelectWindowCommand
*
* Handles thw WM_COMMAND messages for the Select Window dialog.
*
* Arguments:
* HWND hwnd - Window handle of the dialog.
* INT nCmd - Command value.
* INT nNotifyCode - The notify code.
*
* Returns:
* The value that the dialog proc should return, based on the processing
* of the specific WM_COMMAND message received.
\*****************************************************************************/
PRIVATE BOOL
SelectWindowCommand(
HWND hwnd,
INT nCmd,
INT nNotifyCode
)
{
INT nIndex;
HWND hwndList;
CHAR rgString[32];
switch (nCmd)
{
case IDOK:
SetWindowToSpyOn(IsDlgButtonChecked(hwnd, DID_SELWINALLWINDOWS) ?
HWND_ALL : ghwndSpyingOnTemp);
if (bBorderOn)
HighlightWindow(ghwndSpyingOnTemp, FALSE);
EndDialog(hwnd, IDOK);
return TRUE;
case IDCANCEL:
if (bBorderOn)
HighlightWindow(ghwndSpyingOnTemp, FALSE);
EndDialog(hwnd, IDCANCEL);
return TRUE;
case DID_SELWINLIST:
//
// User single clicked or doubled clicked in listbox -
// Single click means select a window to spy on
// Double click means enumerate all the children of that window.
//
hwndList = GetDlgItem(hwnd, DID_SELWINLIST);
switch (nNotifyCode)
{
case LBN_SELCHANGE:
//
// Single click case. Select a window to spy upon.
//
// Get the window handle, set it as the window to spy on.
//
if (bBorderOn)
HighlightWindow(ghwndSpyingOnTemp, FALSE);
nIndex = (INT)SendMessage(hwndList, LB_GETCURSEL, 0, 0);
ghwndSpyingOnTemp = (HWND)SendMessage(hwndList, LB_GETITEMDATA,
nIndex, 0);
SelectWindowUpdateInfo(hwnd, ghwndSpyingOnTemp);
HighlightWindow(ghwndSpyingOnTemp, TRUE);
break;
case LBN_DBLCLK:
//
// Double click case - first click has already been
// processed as single click. In this case, the user has
// requested to look at all the children of a given
// selection.
//
// Get the current selection, and check to see if it is the
// " [ parent.. ]" entry. If so, go up one level first.
//
SetCursor(LoadCursor(NULL, IDC_WAIT));
if (bBorderOn)
HighlightWindow(ghwndSpyingOnTemp, FALSE);
nIndex = (INT)SendMessage(hwndList, LB_GETCURSEL, 0, 0);
ghwndSpyingOnTemp = (HWND)SendMessage(hwndList, LB_GETITEMDATA,
nIndex, 0);
SendMessage(hwndList, LB_GETTEXT, nIndex, (LPARAM)rgString);
if (rgString[0] == ' ')
{
// At top? If so, we are done.
if (ghwndSpyingOnTemp == NULL)
{
SetCursor(LoadCursor(NULL, IDC_ARROW));
break;
}
ghwndSpyingOnTemp = GetParent(ghwndSpyingOnTemp);
}
SendMessage(hwndList, LB_RESETCONTENT, 0, 0);
FillListBox(hwnd, hwndList, ghwndSpyingOnTemp);
nIndex = FindHwndInListBox(hwndList, ghwndSpyingOnTemp);
SendMessage(hwndList, LB_SETCURSEL, nIndex, 0);
ghwndSpyingOnTemp = (HWND)SendMessage(hwndList, LB_GETITEMDATA,
nIndex, 0);
HighlightWindow(ghwndSpyingOnTemp,TRUE);
SelectWindowUpdateInfo(hwnd, ghwndSpyingOnTemp);
SetCursor(LoadCursor(NULL, IDC_ARROW));
break;
}
break;
case DID_SELWINALLWINDOWS:
SelectWindowEnableFields(hwnd,
!IsDlgButtonChecked(hwnd, DID_SELWINALLWINDOWS));
break;
}
return FALSE;
}
/*****************************************************************************\
* FillListBox
*
* Fills the listbox in the Select Window dialog with the names of
* the child windows of the given window.
*
* Arguments:
* hDlg - Window handle of the dialog window
* hwndList - Handle to the listbox within the dialog.
* hwnd - Parent whose children to enumerate.
*
* Returns:
* VOID
\*****************************************************************************/
PRIVATE VOID
FillListBox(
HWND hDlg,
HWND hwndList,
HWND hwnd
)
{
INT nIndex;
//
// First fill the list box with child windows
//
// Make sure we display the list box after things are added.
//
SendMessage(hwndList, WM_SETREDRAW, 0, 0);
//
// remember which dialog we are processing
//
ghwndDlgBeingFilled = hDlg;
if (hwnd == NULL)
{
//
// Enumerate the top level separately... gross unsymmetry, but
// hey.
//
EnumWindows(AddOneWindow, (LPARAM)hwndList);
}
else
{
EnumChildWindows(hwnd, AddOneWindow, (LPARAM)hwndList);
}
//
// Now give the user a method of getting back to the parent. The space at
// the beginning of the " [parent]" string identifies the entry as the
// parent entry and makes it different from all the other entries since
// the others start with a handle number of some sort.
//
nIndex = SendMessage(hwndList, LB_ADDSTRING, 0,
(LPARAM)(LPCTSTR)LoadResourceString(IDS_PARENT));
SendMessage(hwndList, LB_SETITEMDATA, nIndex, (LONG)hwnd);
//
// Now do the redraw...
//
SendMessage(hwndList, WM_SETREDRAW, 1, 0);
}
/*****************************************************************************\
* AddOneWindow
*
* Gets the windows to add to the list of windows to spy on.
*
* Arguments:
* HWND hwnd - handle of the window to add.
* HWND hwndList - handle to the listbox.
*
* Returns:
* TRUE - if a window was created.
\*****************************************************************************/
#define CCH_RGBUF 32
BOOL CALLBACK
AddOneWindow(
HWND hwnd,
LPARAM hwndListLP
)
{
CHAR rgBuf[CCH_RGBUF];
INT nIndex;
HWND htemp;
HWND hwndList = (HWND)hwndListLP;
//
// Make sure we don't add any window that has anything to do with
// the dialog or any other spy window
//
htemp = GetParent(hwnd);
// Don't put console windows in the list since they can not be hooked
if (GetClassName(hwnd, rgBuf, CCH_RGBUF) != 0 &&
strcmp(rgBuf, szConsoleWindowClass) == 0 )
{
return 1;
}
// Don't put windows that belong to spy in the list
if (hwnd == ghwndDlgBeingFilled || htemp == ghwndDlgBeingFilled
|| hwnd == ghwndSpyApp
|| htemp == ghwndSpyApp || hwnd == ghwndPrintf || htemp == ghwndPrintf
|| hwnd == ghwndSpyHook || htemp == ghwndSpyHook)
{
return 1;
}
MakeWindowName(hwnd, rgBuf, CCH_RGBUF);
nIndex = SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)rgBuf);
if (nIndex == LB_ERR || nIndex == LB_ERRSPACE)
return 0;
if (SendMessage(hwndList, LB_SETITEMDATA, nIndex, (LPARAM)hwnd) == LB_ERR)
return 0;
return 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -