📄 spyproc.c
字号:
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "spy.h"
#include "mark.h"
#include "aboutdlg.h"
#include "wwinhelp.h"
static BOOL spyAll;
static WORD statusHite = 25;
static MenuItemHint menuHints[] = {
SPY_SAVE, STR_HINT_SAVE,
SPY_SAVE_AS, STR_HINT_SAVE_AS,
SPY_LOG, STR_HINT_LOG,
SPY_PAUSE_LOG, STR_HINT_PAUSE_LOG,
SPY_CONFIG_LOG, STR_HINT_CONFIG_LOG,
SPY_SET_FONT, STR_HINT_SET_FONT,
SPY_TOP, STR_HINT_TOP,
SPY_EXIT, STR_HINT_EXIT,
SPY_CLEAR_MESSAGES, STR_HINT_CLEAR_MESSAGES,
SPY_AUTO_SCROLL, STR_HINT_AUTO_SCROLL,
SPY_MARK, STR_HINT_MARK,
SPY_WINDOW, STR_HINT_WINDOW,
SPY_ADD_WINDOW, STR_HINT_ADD_WINDOW,
SPY_ANOTHER_WINDOW, STR_HINT_ADD_WINDOW,
SPY_ALL_WINDOWS, STR_HINT_ALL_WINDOWS,
SPY_OFFON, STR_HINT_OFFON,
SPY_STOP, STR_HINT_STOP,
SPY_PEEK_WINDOW, STR_HINT_PEEK_WINDOW,
SPY_SHOW_SELECTED_WINDOWS, STR_HINT_SHOW_SELECTED_WINDOWS,
SPY_MESSAGES_WATCH, STR_HINT_MESSAGES_WATCH,
SPY_MESSAGES_STOP, STR_HINT_MESSAGES_STOP,
SPY_MESSAGES_ASCFG, STR_HINT_MESSAGES_ASCFG,
SPY_MESSAGES_SAVE, STR_HINT_MESSAGES_SAVE,
SPY_MESSAGES_LOAD, STR_HINT_MESSAGES_LOAD,
SPY_ABOUT, STR_HINT_ABOUT,
SPY_SHOW_HELP, STR_HINT_SHOW_HELP,
SPY_HELP_CONTENTS, STR_HINT_HELP_CONTENTS,
SPY_HELP_SRCH, STR_HINT_HELP_SRCH,
SPY_HELP_ON_HELP, STR_HINT_HELP_ON_HELP
};
/*
* enableSpy - turn on spying
*/
static void enableSpy( void )
{
SetFilter( HandleMessageInst );
EnableMenuItem( SpyMenu, SPY_ADD_WINDOW, MF_ENABLED );
EnableMenuItem( SpyMenu, SPY_STOP, MF_ENABLED );
ClearMessageCount();
CheckMenuItem( SpyMenu, SPY_ALL_WINDOWS, MF_UNCHECKED );
spyAll = FALSE;
SetSpyState( ON );
} /* enableSpy */
/*
* disableSpy - set spy to stopped state
*/
static void disableSpy( void )
{
ClearFilter();
CheckMenuItem( SpyMenu, SPY_ALL_WINDOWS, MF_UNCHECKED );
EnableMenuItem( SpyMenu, SPY_ADD_WINDOW, MF_GRAYED );
EnableMenuItem( SpyMenu, SPY_STOP, MF_GRAYED );
SetSpyState( NEITHER );
spyAll = FALSE;
} /* disableSpy */
/*
* setMultipleWindows
*/
static void setMultipleWindows( HWND hwnd )
{
char str[128];
char *rcstr;
rcstr = GetRCString( STR_MULTIPLE_WIN_TITLE );
sprintf( str, rcstr, SpyName );
SetWindowText( hwnd, str );
} /* setMultipleWindows */
/*
* setSingleWindow - set window title for one window spyed on
*/
static void setSingleWindow( HWND hwnd, HWND selwin )
{
char str[128];
char tmp[32];
char *fmtstr;
int len;
len = GetWindowText( selwin, tmp, sizeof( tmp ) );
tmp[len] = 0;
if( len == 0 ) {
fmtstr = GetRCString( STR_1_WIN_TITLE );
sprintf( str, fmtstr, SpyName, UINT_STR_LEN, (UINT) selwin );
} else {
fmtstr = GetRCString( STR_1_NAMED_WIN_TITLE );
sprintf( str, fmtstr, SpyName, UINT_STR_LEN, (UINT) selwin, tmp );
}
SetWindowText( hwnd, str );
} /* setSingleWindow */
/*
* SaveExtra - save extra to file
*/
void SaveExtra( FILE *f )
{
SpyLogTitle( fileno( f ) );
} /* SaveExtra */
/*
* setUpForPick - for windows Send a WM_TIMER message to the callback
* - for NT this function minimizes the spy window and sets
* a timer. When the timer goes off the pick dialog is
* started. This is a kludge to ensure that the screen is
* properly refreshed after the spy window is minimized before
* we grab the screen bitmap and put up the big 'invisible
* window'. The time that we wait is not always enough
* but it is good enough for most cases and I don't want
* to make it so long that the pause is too obvious to the
* user
*/
void setUpForPick( HWND hwnd, WORD cmdid ) {
#ifdef __WINDOWS__
SendMessage( hwnd, WM_TIMER, cmdid, 0 );
#else
ShowWindow( hwnd, SW_MINIMIZE );
SetTimer( hwnd, cmdid, 300, NULL );
#endif
}
static void doSpyAll( HWND hwnd, BOOL state ) {
char *rcstr;
char tmp[32];
if( !state ) {
SendMessage( hwnd, WM_COMMAND,
GET_WM_COMMAND_MPS( SPY_STOP, 0, 0 ) );
} else {
spyAll = state;
EnableMenuItem( SpyMenu, SPY_STOP, MF_ENABLED );
CheckMenuItem( SpyMenu, SPY_ALL_WINDOWS, MF_CHECKED );
SetFilter( HandleMessageInst );
ClearSelectedWindows();
if( SpyState == NEITHER ) {
ClearMessageCount();
}
rcstr = GetRCString( STR_ALL_WIN_TITLE );
sprintf( tmp, rcstr, SpyName );
SetWindowText( hwnd, tmp );
EnableMenuItem( SpyMenu, SPY_ADD_WINDOW, MF_GRAYED );
}
}
static void showHintBar( HWND hwnd ) {
RECT area;
HWND statushwnd;
GetClientRect( hwnd, &area );
if( SpyMainWndInfo.show_hints ) {
statushwnd = GetHintHwnd( StatusHdl );
if( area.bottom - area.top < TOOLBAR_HEIGHT + statusHite ) {
ShowWindow( statushwnd, SW_HIDE );
} else {
ShowWindow( statushwnd, SW_SHOW );
}
}
}
/*
* SpyWindowProc - handle messages for the spy appl.
*/
LONG CALLBACK SpyWindowProc( HWND hwnd, UINT msg, UINT wparam, LONG lparam )
{
int check;
HWND selwin;
HWND hinthwnd;
WORD cmdid;
RECT area;
BOOL pausestate;
BOOL spyallstate;
about_info ai;
HMENU mh;
switch ( msg ) {
case WM_CREATE:
GetClientRect( hwnd, &area );
mh = GetMenu( hwnd );
area.top = area.bottom - statusHite;
StatusHdl = HintWndCreate( hwnd, &area, Instance, NULL );
statusHite = SizeHintBar( StatusHdl );
SetHintText( StatusHdl, (MenuItemHint*)menuHints,
sizeof( menuHints ) / sizeof( MenuItemHint ) );
if( SpyMainWndInfo.show_hints ) {
CheckMenuItem( mh, SPY_SHOW_HELP, MF_CHECKED | MF_BYCOMMAND );
} else {
hinthwnd = GetHintHwnd( StatusHdl );
ShowWindow( hinthwnd, SW_HIDE );
}
CreateSpyBox( hwnd );
SetWindowLong( hwnd, 0, (DWORD)SpyListBox );
CreateSpyTool( hwnd );
LogInit( hwnd, Instance, SpyLogTitle );
CheckMenuItem( SpyMenu, SPY_AUTO_SCROLL, MF_CHECKED );
EnableMenuItem( SpyMenu, SPY_ADD_WINDOW, MF_GRAYED );
EnableMenuItem( SpyMenu, SPY_STOP, MF_GRAYED );
EnableMenuItem( SpyMenu, SPY_OFFON, MF_GRAYED );
if( SpyMainWndInfo.on_top ) {
CheckMenuItem( mh, SPY_TOP, MF_CHECKED | MF_BYCOMMAND );
SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE );
}
break;
case WM_TIMER:
// See comment on setUpForPick
KillTimer( hwnd, wparam );
switch( wparam ) {
case SPY_ADD_WINDOW:
selwin = DoPickDialog( wparam );
if( selwin != NULL ) {
setMultipleWindows( hwnd );
AddSelectedWindow( selwin );
}
break;
case SPY_PEEK_WINDOW:
DoPickDialog( wparam );
break;
case SPY_WINDOW:
selwin = DoPickDialog( cmdid );
if( selwin != NULL ) {
ClearSelectedWindows();
setSingleWindow( hwnd, selwin );
enableSpy();
AddSelectedWindow( selwin );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -