📄 ddetrack.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: DDE Spy window tracking.
*
****************************************************************************/
#include "wddespy.h"
#include <string.h>
#include <stdio.h>
#define MAX_TRK_STR 10
#define STR_HDR_CNT 3
static TrackHeaderInfo StrHdr[ STR_HDR_CNT ] = {
STR_HANDLE, PUSH_STR_HDL, 9,
STR_COUNT, PUSH_STR_CNT, 7,
STR_STRING, PUSH_STR_TEXT, 9
};
#define CNV_HDR_CNT 4
static TrackHeaderInfo ConvHdr[ CNV_HDR_CNT] = {
STR_CLIENT, PUSH_CLIENT, 9,
STR_SERVER, PUSH_SERVER, 9,
STR_SERVICE, PUSH_SERVICE, 21,
STR_TOPIC, PUSH_TOPIC, 10
};
#define LNK_HDR_CNT 7
static TrackHeaderInfo LnkHdr[] = {
STR_CLIENT, PUSH_CLIENT, 9,
STR_SERVER, PUSH_SERVER, 9,
STR_TYPE, PUSH_TYPE, 5,
STR_SERVICE, PUSH_SERVICE, 11,
STR_TOPIC, PUSH_TOPIC, 11,
STR_ITEM, PUSH_ITEM, 11,
STR_FORMAT, PUSH_FORMAT, 11
};
#define SRV_HDR_CNT 2
static TrackHeaderInfo SrvHdr[] = {
STR_SERVER_NAME, PUSH_SERVER, 20,
STR_INSTANCE, PUSH_INST, 20
};
static void MakePushWin( DDETrackInfo *info, HWND hwnd, TrackHeaderInfo *hdrinfo, WORD hdrcnt );
/*
* SetTrackWndDefault - set the tracking window size, pos etc to the defaults
*/
void SetTrackWndDefault( void ) {
WORD i;
for( i=0; i < NO_TRK_WND; i++ ) {
Tracking[i].visible = FALSE;
Tracking[i].xpos = 0;
Tracking[i].ypos = i * GetSystemMetrics( SM_CYCAPTION );
Tracking[i].xsize = GetSystemMetrics( SM_CXSCREEN );
Tracking[i].ysize = 150;
}
}
/*
* InitTrackWind - update the checkmarks in the Tracking menu and
* and the visibility state of the tracking windows so it
* corresponds to the information contained in the Tracking
* array
*/
void InitTrackWind( HWND hwnd ) {
WORD i;
HMENU mh;
mh = GetMenu( hwnd );
for( i = 0; i < NO_TRK_WND; i++ ) {
if( Tracking[ i ].visible ) {
ShowWindow( Tracking[ i ].hwnd, SW_SHOWNORMAL );
CheckMenuItem( mh, i + DDE_TRK_FIRST, MF_BYCOMMAND | MF_CHECKED );
} else {
ShowWindow( Tracking[ i ].hwnd, SW_HIDE );
CheckMenuItem( mh, i + DDE_TRK_FIRST, MF_BYCOMMAND | MF_UNCHECKED );
}
DDESetStickyState( i + DDE_TRK_FIRST, Tracking[ i ].visible );
}
}
/*
* CreateTrackWind - create the tracking windows.
* The tracking windows are always present when the program
* is running. When not visible they are hidden NOT
* destroyed
*/
BOOL CreateTrackWind( void ) {
WORD type;
WORD i;
for( i = 0; i < NO_TRK_WND; i++ ) {
type = i + DDE_TRK_FIRST;
Tracking[ i ].hwnd =
CreateWindow(
TRACKING_CLASS, /* Window class name */
"", /* Window caption */
WS_OVERLAPPED | WS_CAPTION
| WS_SYSMENU | WS_THICKFRAME
| WS_MAXIMIZEBOX, /* Window style */
Tracking[i].xpos, /* Initial X position */
Tracking[i].ypos, /* Initial Y position */
Tracking[i].xsize, /* Initial X size */
Tracking[i].ysize, /* Initial Y size */
NULL, /* Parent window handle */
NULL, /* Window menu handle */
Instance, /* Program instance handle */
&type /* Create parameters */
);
if( Tracking[ i ].hwnd == NULL ) return( FALSE );
}
return( TRUE );
}
/*
* FiniTrackWnd - destroy the tracking windows
*/
void FiniTrackWnd( void ) {
WORD i;
for( i=0; i < NO_TRK_WND; i++ ) {
DestroyWindow( Tracking[ i ].hwnd );
}
}
/*
* SetTrackFont - redraw the tracking windows after a font change
*/
void SetTrackFont( void ) {
unsigned i;
DDETrackInfo *info;
HFONT font;
RECT area;
font = GetMonoFont();
for( i=0; i < NO_TRK_WND; i++ ) {
info = (DDETrackInfo *)GetWindowLong( Tracking[i].hwnd, 0 );
MakePushWin( info, Tracking[i].hwnd, info->hdrinfo, info->hdrcnt );
GetClientRect( Tracking[i].hwnd, &area );
ResizeListBox( area.right - area.left, area.bottom - area.top,
&info->list );
SendMessage( info->list.box, WM_SETFONT, (WPARAM)font,
MAKELONG( TRUE, 0 ) );
}
}
/*
* GetNextPos - get a pointer to the next available pointer position
* in the element list for a tracking window
*/
static void **GetNextPos( DDETrackInfo *listinfo )
{
WORD i;
void **data;
data = listinfo->data;
for( i=0; i < listinfo->cnt; i++ ) {
if( data[i] == NULL ) return( data + i );
}
listinfo->cnt ++;
listinfo->data = MemReAlloc( listinfo->data,
listinfo->cnt * sizeof( void *) );
return( listinfo->data + listinfo->cnt - 1 );
}
/* #########################################################################
* SERVER TRACKING STUFF
* #########################################################################*/
static int SortServerByServer( const void *_str1, const void *_str2 ) {
ServerInfo * const *str1 = _str1;
ServerInfo * const *str2 = _str2;
if( *str1 == NULL ) return( 1 );
if( *str2 == NULL ) return( -1 );
return( stricmp( (*str1)->server, (*str2)->server ) );
}
static int SortServerByInst( const void *_str1, const void *_str2 ) {
ServerInfo * const *str1 = _str1;
ServerInfo * const *str2 = _str2;
if( *str1 == NULL ) return( 1 );
if( *str2 == NULL ) return( -1 );
return( stricmp( (*str1)->instname, (*str2)->instname ) );
}
/*
* DisplayServers - refresh the information in the servers tracking window
*/
static void DisplayServers( DDETrackInfo *info ) {
unsigned i;
unsigned len;
char buf[80];
ServerInfo **servers;
ServerInfo *cur;
int (*fn)(const void *, const void *);
switch( info->sorttype ) {
case PUSH_SERVER:
fn = SortServerByServer;
break;
case PUSH_INST:
fn = SortServerByInst;
break;
default:
return;
}
qsort( info->data, info->cnt, sizeof( ServerInfo * ), fn );
SendMessage( info->list.box, LB_RESETCONTENT, 0, 0L );
servers = info->data;
for( i=0; i < info->cnt; i++ ) {
cur = servers[i];
if( cur == NULL ) break;
memset( buf, ' ', 80 * sizeof( char ) );
len = strlen( cur->server );
strcpy( buf, cur->server );
buf[len] = ' ';
strcpy( buf + 20, cur->instname );
SendMessage( info->list.box, LB_ADDSTRING, 0, (DWORD)buf );
}
}
/*
* DoServerSort - change the sort type for the server tracking window
*/
static void DoServerSort( WORD type, DDETrackInfo *info ) {
if( type == PUSH_SERVER || type == PUSH_INST ) {
info->sorttype = type;
DisplayServers( info );
}
}
/*
* FindServer - find the information about the server with instance string
* inst. If we don't know about this server return NULL
*/
static ServerInfo **FindServer( char *inst, DDETrackInfo *info ) {
unsigned i;
ServerInfo **list;
list = info->data;
for( i=0; i < info->cnt; i++ ) {
if( list[i] != NULL ) {
if( !strcmp( inst, list[i]->instname ) ) {
return( list + i );
}
}
}
return( NULL );
}
/*
* TrackServerMsg - update the coversations tracking window
*/
void TrackServerMsg( MONCBSTRUCT *info ) {
char *inst;
DDETrackInfo *listinfo;
ServerInfo **entry;
ServerInfo *cur;
inst = HSZToString( info->hsz2 );
listinfo = (DDETrackInfo *)GetWindowLong(
Tracking[ DDEMENU_TRK_SERVER - DDE_TRK_FIRST ].hwnd, 0 );
entry = FindServer( inst, listinfo );
if( info->wType == XTYP_REGISTER ) {
if( entry == NULL ) {
entry = GetNextPos( listinfo );
cur = MemAlloc( sizeof( ServerInfo ) );
*entry = cur;
cur->instname = inst;
cur->server = HSZToString( info->hsz1 );
} else {
MemFree( inst );
}
} else if( info->wType == XTYP_UNREGISTER ) {
if( entry != NULL ) {
cur = *entry;
MemFree( cur->instname );
MemFree( cur->server );
*entry = NULL;
} else {
MemFree( inst );
}
}
DisplayServers( listinfo );
}
/* #########################################################################
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -