📄 ddemsg.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 <string.h>
#include <stdio.h>
#include "wddespy.h"
#define HWND_LEN 10
#define CONV_LEN 10
#define TASK_LEN 10
/*
* the values in this enum are used as indices into the aliasHdlTable array
*/
enum {
DEALIAS_HWND,
DEALIAS_TASK,
DEALIAS_CONV,
DEALIAS_CLIENT_CONV,
DEALIAS_SERVER_CONV,
};
static AliasHdl *aliasHdlTable[] = {
&HwndAlias,
&TaskAlias,
&ConvAlias,
&ConvAlias,
&ConvAlias
};
typedef struct {
WORD type;
HWND lb;
} ReplaceInfo;
static ReplaceInfo taskReplace;
static ReplaceInfo convReplace;
static ReplaceInfo hwndReplace;
msglist DDEMsgs[] = {
WM_DDE_ACK, (char *)STR_ACK,
WM_DDE_ADVISE, (char *)STR_ADVISE,
WM_DDE_DATA, (char *)STR_DATA,
WM_DDE_EXECUTE, (char *)STR_EXECUTE,
WM_DDE_INITIATE, (char *)STR_INITIATE,
WM_DDE_POKE, (char *)STR_POKE,
WM_DDE_REQUEST, (char *)STR_REQUEST,
WM_DDE_TERMINATE, (char *)STR_TERMINATE,
WM_DDE_UNADVISE, (char *)STR_UNADVISE,
0, (char *) -1 };
static msglist FormatMsgs[] = {
CF_BITMAP, "CF_BITMAP",
CF_DIB, "CF_DIB",
CF_DIF, "CF_DIF",
CF_DSPBITMAP, "CF_DSPBITMAP",
CF_DSPMETAFILEPICT, "CF_DSPMETAFILEPICT",
CF_DSPTEXT, "CF_DSPTEXT",
CF_METAFILEPICT, "CF_METAFILEPICT",
CF_OEMTEXT, "CF_OEMTEXT",
CF_OWNERDISPLAY, "CF_OWNERDISPLAY",
CF_PALETTE, "CF_PALETTE",
CF_PENDATA, "CF_PENDATA",
CF_RIFF, "CF_RIFF",
CF_SYLK, "CF_SYLK",
CF_TEXT, "CF_TEXT",
CF_TIFF, "CF_TIFF",
CF_WAVE, "CF_WAVE",
0, NULL };
static msglist XTypMsgs[] = {
XTYP_ADVSTART, "XTYP_ADVSTART",
XTYP_CONNECT, "XTYP_CONNECT",
XTYP_ADVREQ, "XTYP_ADVREQ",
XTYP_REQUEST, "XTYP_REQUEST",
XTYP_WILDCONNECT, "XTYP_WILDCONNECT",
XTYP_ADVDATA, "XTYP_ADVDATA",
XTYP_EXECUTE, "XTYP_EXECUTE",
XTYP_POKE, "XTYP_POKE",
XTYP_ADVSTOP, "XTYP_ADVSTOP",
XTYP_CONNECT_CONFIRM, "XTYP_CONNECT_CONFIRM",
XTYP_DISCONNECT, "XTYP_DISCONNECT",
XTYP_ERROR, "XTYP_ERROR",
XTYP_XACT_COMPLETE, "XTYP_XACT_COMPLETE",
XTYP_UNREGISTER, "XTYP_UNREGISTER",
XTYP_REGISTER, "XTYP_REGISTER",
0, NULL };
static msglist DDEErrorMsgs[] = {
DMLERR_ADVACKTIMEOUT, "DMLERR_ADVACKTIMEOUT",
DMLERR_BUSY, "DMLERR_BUSY",
DMLERR_DATAACKTIMEOUT, "DMLERR_DATAACKTIMEOUT",
DMLERR_DLL_NOT_INITIALIZED, "DMLERR_DLL_NOT_INITIALIZED",
DMLERR_DLL_USAGE, "DMLERR_DLL_USAGE",
DMLERR_EXECACKTIMEOUT, "DMLERR_EXECACKTIMEOUT",
DMLERR_INVALIDPARAMETER, "DMLERR_INVALIDPARAMETER",
DMLERR_LOW_MEMORY, "DMLERR_LOW_MEMORY",
DMLERR_MEMORY_ERROR, "DMLERR_MEMORY_ERROR",
DMLERR_NO_CONV_ESTABLISHED, "DMLERR_NO_CONV_ESTABLISHED",
DMLERR_NOTPROCESSED, "DMLERR_NOTPROCESSED",
DMLERR_POKEACKTIMEOUT, "DMLERR_POKEACKTIMEOUT",
DMLERR_POSTMSG_FAILED, "DMLERR_POSTMSG_FAILED",
DMLERR_REENTRANCY, "DMLERR_REENTRANCY",
DMLERR_SERVER_DIED, "DMLERR_SERVER_DIED",
DMLERR_SYS_ERROR, "DMLERR_SYS_ERROR",
DMLERR_UNADVACKTIMEOUT, "DMLERR_UNADVACKTIMEOUT",
DMLERR_UNFOUND_QUEUE_ID, "DMLERR_UNFOUND_QUEUE_ID",
0, NULL };
static char *fmtAlias( DWORD id, char *alias, unsigned type, WORD *prefixlen )
{
char *prefix;
char *ret;
unsigned len;
unsigned fmt_len;
char buf[10];
switch( type ) {
case DEALIAS_TASK:
fmt_len = TASK_FMT_LEN;
prefix = GetRCString( STR_TASK_PREFIX );
break;
case DEALIAS_CONV:
fmt_len = CONV_FMT_LEN;
prefix = GetRCString( STR_CONV_PREFIX );
break;
case DEALIAS_CLIENT_CONV:
fmt_len = CONV_FMT_LEN;
prefix = GetRCString( STR_CLICONV_PREFIX );
break;
case DEALIAS_SERVER_CONV:
fmt_len = CONV_FMT_LEN;
prefix = GetRCString( STR_SERVCONV_PREFIX );
break;
case DEALIAS_HWND:
fmt_len = HWND_FMT_LEN;
prefix = GetRCString( STR_HWND_PREFIX );
break;
}
if( alias == NULL ) {
alias = buf;
sprintf( alias, "0x%0*lX", fmt_len, id );
}
fmt_len = strlen( prefix );
len = strlen( alias ) + fmt_len + 1;
if( prefixlen != NULL ) *prefixlen = fmt_len;
ret = MemAlloc( len );
sprintf( ret, "%s%s", prefix, alias );
return( ret );
}
/*
* DeAlias - covert a value to its associated alias or
* format it as a number if no alias exists
*/
static char *DeAlias( long id, unsigned type ) {
char *alias;
char *ret;
AliasHdl *alias_list;
WORD prefixlen;
alias_list = aliasHdlTable[ type ];
if( !ConfigInfo.alias ) {
alias = NULL;
} else {
alias = LookupAlias( *alias_list, id );
}
ret = fmtAlias( id, alias, type, &prefixlen );
if( alias == NULL ) {
AddAlias( *alias_list, ret + prefixlen, id );
}
return( ret );
}
/*
* doReplace - replace strings in the list box
* NB this routine will not handle the case of replacing a string with itself
*/
static void doReplace( HWND lb, WORD searchcnt, char **searchfor,
char **replace )
{
WORD i;
WORD j;
WORD pos;
LRESULT ret;
char buf1[256];
char buf2[256];
char *inbuf;
char *outbuf;
char *tmp;
char *ptr;
inbuf = buf1;
outbuf = buf2;
//
// for each line in the listbox
//
for( i=0; ; i++ ) {
ret = SendMessage( lb, LB_GETTEXT, i, (LPARAM)(LPCSTR)inbuf );
if( ret == LB_ERR ) break;
//
// search for each thing
//
for( j=0; j < searchcnt; j++ ) {
//
//continue searching while there are more
//
ptr = strstr( inbuf, searchfor[j] );
pos = 0;
while( ptr != NULL ) {
//
// do the replacement
//
*ptr = '\0';
strcpy( outbuf, inbuf );
strcat( outbuf, replace[j] );
ptr += strlen( searchfor[j] );
strcat( outbuf, ptr );
pos = ptr - inbuf;
//
// swap the buffers
//
tmp = inbuf;
inbuf = outbuf;
outbuf = tmp;
ptr = strstr( inbuf + pos, searchfor[j] );
}
}
//
// replace the listbox line
//
SendMessage( lb, LB_INSERTSTRING, i, (LPARAM)(LPSTR)inbuf );
SendMessage( lb, LB_DELETESTRING, i+1, 0 );
}
}
static void updateAlias( DWORD id, char *newalias, char *oldalias,
ReplaceInfo *info ) {
WORD i;
WORD searchcnt;
char *searchfor[3];
char *replace[3];
if( oldalias != NULL && newalias != NULL ) {
if( !strcmp( oldalias, newalias ) ) return;
}
if( info->type == DEALIAS_CONV ) {
searchcnt = 3;
searchfor[0] = fmtAlias( id, oldalias, DEALIAS_CONV, NULL );
searchfor[1] = fmtAlias( id, oldalias, DEALIAS_CLIENT_CONV, NULL );
searchfor[2] = fmtAlias( id, oldalias, DEALIAS_SERVER_CONV, NULL );
replace[0] = fmtAlias( id, newalias, DEALIAS_CONV, NULL );
replace[1] = fmtAlias( id, newalias, DEALIAS_CLIENT_CONV, NULL );
replace[2] = fmtAlias( id, newalias, DEALIAS_SERVER_CONV, NULL );
} else {
searchcnt = 1;
searchfor[0] = fmtAlias( id, oldalias, info->type, NULL );
replace[0] = fmtAlias( id, newalias, info->type, NULL );
}
doReplace( info->lb, searchcnt, searchfor, replace );
for( i=0; i < searchcnt; i++ ) {
MemFree( searchfor[i] );
MemFree( replace[i] );
}
}
void refreshAnAlias( DWORD id, char *text, ReplaceInfo *info ) {
char *ptr;
WORD prefix;
if( id == -1 ) return;
ptr = fmtAlias( id, NULL, info->type, &prefix );
if( ConfigInfo.alias ) {
updateAlias( id, text, ptr + prefix, info );
} else {
updateAlias( id, ptr + prefix, text, info );
}
MemFree( ptr );
}
/*
* InitAliases
*/
void InitAliases( void ) {
DDEWndInfo *info;
info = (DDEWndInfo *) GetWindowLong( DDEMainWnd, 0 );
hwndReplace.type = DEALIAS_HWND;
hwndReplace.lb = info->list.box;
convReplace.type = DEALIAS_CONV;
convReplace.lb = info->list.box;
taskReplace.type = DEALIAS_TASK;
taskReplace.lb = info->list.box;
InitAliasHdl( &HwndAlias, updateAlias, &hwndReplace );
InitAliasHdl( &ConvAlias, updateAlias, &convReplace );
InitAliasHdl( &TaskAlias, updateAlias, &taskReplace );
}
/*
* RefreshAliases - replace all the aliases because the user has activate
* or deactivated them
*/
void RefreshAliases( void ) {
EnumAliases( HwndAlias, refreshAnAlias, &hwndReplace );
EnumAliases( ConvAlias, refreshAnAlias, &convReplace );
EnumAliases( TaskAlias, refreshAnAlias, &taskReplace );
}
/*
* GetFmtStr - convert a format code to an appropriate string
*/
char *GetFmtStr( WORD fmt, char *buf ) {
char *ret;
char *fmtstr;
ret = SrchMsg( fmt, FormatMsgs, NULL );
if( ret == NULL ) {
ret = buf;
fmtstr = GetRCString( STR_UNKNOWN_FMT_ID );
sprintf( buf, fmtstr, FMT_ID_LEN, fmt );
} else {
strcpy( buf, ret );
}
return( buf );
}
/*
* HSZToString - gets the string associated with hsz and allocates a buffer
* to hold it.
* The returned string must be freed with a call to MemFree
*/
char *HSZToString( HSZ hsz ) {
char *ret;
int codepage;
unsigned len;
#ifdef __NT__
codepage = CP_WINANSI;
#else
codepage = GetKBCodePage();
#endif
len = DdeQueryString( DDEInstId, hsz, NULL, 0, codepage );
len ++;
ret = MemAlloc( len );
DdeQueryString( DDEInstId, hsz, ret, len, codepage );
return( ret );
}
/*
* SetHorzExtent - set the horizontal extent of the list box
*/
static void SetHorzExtent( DDEWndInfo *info, char *text ) {
HDC dc;
HFONT font;
SIZE sz;
dc = GetDC( info->list.box );
font = GetMonoFont();
font = SelectObject( dc, font );
GetTextExtentPoint( dc, text, strlen( text ), &sz );
if( sz.cx > info->horz_extent ) {
SendMessage( info->list.box, LB_SETHORIZONTALEXTENT, sz.cx, 0L );
info->horz_extent = sz.cx;
}
SelectObject( dc, font );
ReleaseDC( info->list.box, dc );
}
void RecordMsg( char *buf ) {
DDEWndInfo *info;
LRESULT ret;
char *ptr;
char *start;
ptr = buf;
start = buf;
info = (DDEWndInfo *) GetWindowLong( DDEMainWnd, 0 );
while( *ptr ) {
if( *ptr == '\n' ) {
*ptr = '\0';
if( ConfigInfo.screen_out ) {
SetHorzExtent( info, start );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -