📄 iedde.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 <windows.h>
#include <ddeml.h>
#include "imgedit.h"
#include "iemem.h"
#include "wrdll.h"
/****************************************************************************/
/* macro definitions */
/****************************************************************************/
#define NUM_FORMATS 3
#define TIME_OUT 4000
#define WRE_SERVICE_NAME "WATCOMResourceEditor"
#define WRE_BITMAP_TOPIC "WATCOMEditBitmaps"
#define WRE_CURSOR_TOPIC "WATCOMEditCursors"
#define WRE_ICON_TOPIC "WATCOMEditIcons"
#define WRE_IMAGE_DUMP "WATCOMDumpImage"
#define BMP_SERVICE_NAME "WATCOMBitmapEditor"
#define CUR_SERVICE_NAME "WATCOMCursorEditor"
#define ICO_SERVICE_NAME "WATCOMIconEditor"
#define BMP_SERVICE_TOPIC "WATCOMBitmapEditLink"
#define CUR_SERVICE_TOPIC "WATCOMCursorEditLink"
#define ICO_SERVICE_TOPIC "WATCOMIconEditLink"
#define WRE_FILE_ITEM "WATCOMResFile"
#define WRE_NAME_ITEM "WATCOMResName"
#define WRE_DATA_ITEM "WATCOMResData"
/****************************************************************************/
/* type definitions */
/****************************************************************************/
typedef enum {
DDEBitmap
, DDECursor
, DDEIcon
, DDENone
}IEEditFormat;
typedef struct IEService {
char *service;
char *topic;
HSZ hservice;
HSZ htopic;
} IEService;
typedef struct IETopic {
char *topic;
HSZ htopic;
} IETopic;
typedef struct IEClipFormat {
char *str;
UINT format;
} IEClipFormat;
/****************************************************************************/
/* external function prototypes */
/****************************************************************************/
extern HDDEDATA CALLBACK DdeCallBack( WORD wType, WORD wFmt, HCONV hConv,
HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
DWORD lData1, DWORD lData2 );
/****************************************************************************/
/* static function prototypes */
/****************************************************************************/
extern BOOL IEHData2Mem ( HDDEDATA, void **, uint_32 * );
extern BOOL IEStartDDEEditSession ( void );
extern HDDEDATA IECreateResData ( img_node *node );
/****************************************************************************/
/* static variables */
/****************************************************************************/
// These are the clipboard formats registered by the Image Editor
static IEClipFormat IEClipFormats[NUM_FORMATS] =
{
{ WR_CLIPBD_BITMAP, 0 },
{ WR_CLIPBD_CURSOR, 0 },
{ WR_CLIPBD_ICON, 0 }
};
// These are the services offered by the Image Editor
static IEService IEServices[NUM_FORMATS] =
{
{ BMP_SERVICE_NAME, BMP_SERVICE_TOPIC, NULL, NULL },
{ CUR_SERVICE_NAME, CUR_SERVICE_TOPIC, NULL, NULL },
{ ICO_SERVICE_NAME, ICO_SERVICE_TOPIC, NULL, NULL }
};
#if 0
// These are the services offered by the Resource Editor
// that will be used by the Image Editor
static IETopic IETopics[NUM_FORMATS] =
{
{ WRE_BITMAP_TOPIC, NULL },
{ WRE_CURSOR_TOPIC, NULL },
{ WRE_ICON_TOPIC, NULL }
};
#endif
static IEEditFormat EditFormat = DDENone;
static DWORD IdInst = 0;
static FARPROC DdeProc;
static HSZ hFileItem = NULL;
static HSZ hNameItem = NULL;
static HSZ hDataItem = NULL;
static HSZ hService = NULL;
static HCONV IEClientConv = NULL;
static HCONV IEServerConv = NULL;
BOOL IEDDEStart( HINSTANCE inst )
{
WORD ret;
DWORD flags;
int i;
_imged_touch(inst); /* MakeProcInstance vanishes in NT */
if( IdInst != 0 ) {
return( FALSE );
}
for( i=0; i<NUM_FORMATS; i++ ) {
IEClipFormats[i].format =
RegisterClipboardFormat( IEClipFormats[i].str );
if( IEClipFormats[i].format == 0 ) {
return( FALSE );
}
}
DdeProc = MakeProcInstance( (FARPROC)DdeCallBack, inst );
if( DdeProc == (FARPROC)NULL ) {
return( FALSE );
}
flags = APPCLASS_STANDARD | APPCMD_FILTERINITS |
CBF_FAIL_ADVISES | CBF_FAIL_SELFCONNECTIONS |
CBF_SKIP_REGISTRATIONS | CBF_SKIP_UNREGISTRATIONS;
ret = DdeInitialize( &IdInst, (PFNCALLBACK)DdeProc, flags, 0 );
if( ret != DMLERR_NO_ERROR ) {
return( FALSE );
}
for( i=0; i<NUM_FORMATS; i++ ) {
IEServices[i].hservice = DdeCreateStringHandle( IdInst, IEServices[i].service, CP_WINANSI );
IEServices[i].htopic = DdeCreateStringHandle( IdInst, IEServices[i].topic, CP_WINANSI );
}
hFileItem = DdeCreateStringHandle( IdInst, WRE_FILE_ITEM, CP_WINANSI );
if( hFileItem == (HSZ)NULL ) {
return( FALSE );
}
hNameItem = DdeCreateStringHandle( IdInst, WRE_NAME_ITEM, CP_WINANSI );
if( hNameItem == (HSZ)NULL ) {
return( FALSE );
}
hDataItem = DdeCreateStringHandle( IdInst, WRE_DATA_ITEM, CP_WINANSI );
if( hDataItem == (HSZ)NULL ) {
return( FALSE );
}
for( i=0; i<NUM_FORMATS; i++ ) {
if( IEServices[i].hservice != (HSZ)NULL ) {
DdeNameService( IdInst, IEServices[i].hservice, (HSZ)NULL, DNS_REGISTER );
}
}
return( TRUE );
}
void IEDDEEnd( void )
{
int i;
if( IdInst != 0 ) {
DdeNameService( IdInst, (HSZ)NULL, (HSZ)NULL, DNS_UNREGISTER );
if( hDataItem != (HSZ)NULL ) {
DdeFreeStringHandle( IdInst, hDataItem );
}
if( hNameItem != (HSZ)NULL ) {
DdeFreeStringHandle( IdInst, hNameItem );
}
if( hFileItem != (HSZ)NULL ) {
DdeFreeStringHandle( IdInst, hFileItem );
}
for( i=0; i<NUM_FORMATS; i++ ) {
if( IEServices[i].hservice != (HSZ)NULL ) {
DdeFreeStringHandle( IdInst, IEServices[i].hservice );
}
if( IEServices[i].htopic != (HSZ)NULL ) {
DdeFreeStringHandle( IdInst, IEServices[i].htopic );
}
}
DdeUninitialize( IdInst );
IdInst = 0;
}
if( DdeProc != (FARPROC)NULL ) {
FreeProcInstance( DdeProc );
}
}
BOOL IEDDEDumpConversation( HINSTANCE inst )
{
HCONV hconv;
HSZ hservice;
HSZ htopic;
BOOL ok;
ok = IEDDEStart( inst );
if( ok ) {
hservice = DdeCreateStringHandle( IdInst, WRE_SERVICE_NAME, CP_WINANSI );
ok = ( hservice != (HSZ)NULL );
}
if( ok ) {
htopic = DdeCreateStringHandle( IdInst, WRE_IMAGE_DUMP, CP_WINANSI );
ok = ( htopic != (HSZ)NULL );
}
if( ok ) {
// We expect the server to reject this connect attempt
// if it doesn't then we terminate the conversation
hconv = DdeConnect( IdInst, hservice, htopic, (LPVOID)NULL );
if( hconv != (HCONV)NULL ) {
DdeDisconnect( hconv );
}
}
if( hservice != (HSZ)NULL ) {
DdeFreeStringHandle( IdInst, hservice );
}
if( htopic != (HSZ)NULL ) {
DdeFreeStringHandle( IdInst, htopic );
}
IEDDEEnd();
if( !ok ) {
IEDisplayErrorMsg( WIE_DDEINITTITLE, WIE_DDETERMINATIONMSG,
MB_OK | MB_ICONINFORMATION );
}
return( ok );
}
BOOL IEDDEStartConversation( void )
{
if( IdInst == 0 ) {
return( FALSE );
}
hService = DdeCreateStringHandle( IdInst, WRE_SERVICE_NAME, CP_WINANSI );
if( hService == (HSZ)NULL ) {
return( FALSE );
}
IEClientConv = DdeConnect( IdInst, hService, (HSZ)NULL, (LPVOID)NULL );
if( IEClientConv == (HCONV)NULL ) {
return( FALSE );
}
if( !IEStartDDEEditSession() ) {
return( FALSE );
}
return( TRUE );
}
void IEDDEEndConversation( void )
{
if( IEClientConv != (HCONV)NULL ) {
DdeDisconnect( IEClientConv );
IEClientConv = (HCONV)NULL;
}
if( IEServerConv != (HCONV)NULL ) {
DdeDisconnect( IEServerConv );
IEServerConv = (HCONV)NULL;
}
if( hService != (HSZ)NULL ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -