home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 June
/
CHIPCD_6_2000.iso
/
software
/
cad
/
t425l1e
/
t425l1e.exe
/
_001870_
/
EXPORT_.C
Wrap
C/C++ Source or Header
|
1997-06-14
|
13KB
|
347 lines
//------------------------------------------------------------------------------------------------------
// Name : export_.c
// Date : 05.03.1997 Author : SM System : Win32
//------------------------------------------------------------------------------------------------------
// This file contains the language-independent implementation of the module EXPORT_.DLL. All texts and
// resources that are language-dependent are located in an additional EXPORT.DLL, whose sources can be
// found in the subdirectories \E (for English) and \D (for German).
//------------------------------------------------------------------------------------------------------
#define TOSO_MODULE_VERSION 420 // Required version of Toso Interface
//------------------------------------------------------------------------------------------------------
#define USER_DATA_ID "1.00-1996-11-20"
#define TXT_ID_HEADER "TommySoftware TXT 1.10"
//------------------------------------------------------------------------------------------------------
#include "windows.h"
#include "windowsx.h"
#include "stdlib.h"
#include "stdio.h"
#include "math.h"
#include "e:\release4\tosoapi4.h" // Toso Interface Definitions
#include "dialog.h"
//------------------------------------------------------------------------------------------------------
typedef struct {
STR32 TimeStamp;
FILENAME FileName;
} INF_HEADER;
//------ Language-dependent texts in EXPORT.DLL --------------------------------------------------------
DLL_IMPORT LPSTR
eStartUpText [],
eDialogText [],
eMessageText [];
//------------------------------------------------------------------------------------------------------
static HINSTANCE hInstDLL, // Instance handle of the main DLL
hLanguage, // Instance handle of the language DLL
hGlobalInst; // Instance handle of the serving application
static HWND hGlobalWnd; // Main window handle of the serving application
//------------------------------------------------------------------------------------------------------
static HBITMAP hBitmap;
static INF_HEADER INFHeader;
static int gError; // Current error status ( 0 = OK )
//------------------------------------------------------------------------------------------------------
BOOL ModuleLoadSettings( void )
{
BOOL Result = FALSE;
if( TosoProfileReadKeyOpen( "EXPORT", FALSE ) ) {
if( TosoProfileReadData( "Init", (LPBYTE) &INFHeader, sizeof( INFHeader ) ) )
Result = TRUE;
TosoProfileReadKeyClose();
INFHeader.TimeStamp[31] = 0x00;
if( lstrcmp( INFHeader.TimeStamp, USER_DATA_ID ) )
Result = FALSE;
}
if( !Result ) {
lstrcpy( INFHeader.FileName, eDialogText[1] );
}
return( Result );
}
//------------------------------------------------------------------------------------------------------
BOOL ModuleSaveSettings( void )
{
BOOL Result = FALSE;
if( TosoProfileWriteKeyOpen( "EXPORT", FALSE ) ) {
lstrcpy( INFHeader.TimeStamp, USER_DATA_ID );
if( TosoProfileWriteData( "Init", (LPBYTE) &INFHeader, sizeof( INFHeader ) ) )
Result = TRUE;
TosoProfileWriteKeyClose();
}
return( Result );
}
//------------------------------------------------------------------------------------------------------
// This procedure is used as callback procedure for an object enumeration based on the interface
// procedure TosoEnumerateAll(). It simply runs through of the object described in EnumData and write
// the coordinates of all its definition points to the currently open file.
// After each coordinate pair written, it also updates the current progress indicator and checks whether
// the user has pressed the Cancel button to stop the export.
BOOL ModuleEnumCallback( const ENUMDEF_DATA* EnumData )
{
DUMMYSTR Text1, Text2;
int Count;
switch( EnumData->EnumData ) {
case ENUMDATA_CURVE:
case ENUMDATA_AREA:
case ENUMDATA_MARK:
for( Count = 0; Count < EnumData->EnumCount; Count++ ) {
TosoFileWriteShort ( DB_POINT_ANY );
TosoFileWriteCommaDouble( EnumData->PointPtr[Count].x );
TosoFileWriteCommaDouble( EnumData->PointPtr[Count].y );
TosoFileWriteSemi();
if( TosoFileWriteError() ) {
gError = 1;
break;
}
wsprintf( Text1, eDialogText[3], TosoFileWriteCurrentLine() );
wsprintf( Text2, eDialogText[4], ( TosoFileWriteCurrentSize() + 1023 ) / 1024 );
TosoDialogUpdateProgress( Text1, Text2, NOPARAM, NOPARAM );
if( TosoDialogIsCanceled() ) {
gError = 999;
break;
}
}
break;
}
return( !gError );
}
//------------------------------------------------------------------------------------------------------
// This procedure performs the export. It starts the object enumeration (which writes coordinate pairs
// to the file).
// In addition, it initializes and display a progress indicator window to inform the user about the
// current progress and to allow him to cancel the export. Since the final file size is not known
// in advance, the progress indicator does not include a percent bar.
void ModuleExport( HANDLE FileHandle, const LPSTR FileName, int Flag )
{
FILENAME FileName2;
DUMMYSTR DummyStr;
gError = 0;
if( !TosoFileWriteInitDisk( FileHandle ) ) {
gError = 1;
return;
}
TosoFileSplitName( FileName, NULL, FileName2 );
wsprintf( DummyStr, eDialogText[2], FileName2 );
TosoDialogShowProgress( eDialogText[0], DummyStr, FALSE );
TosoFileWriteTextData( TXT_ID_HEADER );
TosoFileWriteSemi();
TosoEnumerateAll( TosoDrawingGetActive(), Flag, Flag,
ENUMMODE_PLAIN | ENUMMODE_LINES | ENUMMODE_LINETYPES,
(TOSOENUMOBJECT_PROC) ModuleEnumCallback );
TosoFileWriteShort( DB_END );
TosoFileWriteSemi();
if( !TosoFileWriteFlush() )
gError = 1;
TosoFileWriteExit();
TosoDialogHideProgress();
}
//------------------------------------------------------------------------------------------------------
// This DLL entry procedure must exist in any DLL to be used in Win32. Since our DLL does all necessary
// initialization in its TosoModuleInit() procedure, this procedure is quite empty.
BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD Reason, LPVOID Dummy )
{
switch( Reason ) {
case DLL_PROCESS_ATTACH:
hInstDLL = hInstance;
break;
case DLL_PROCESS_DETACH:
hInstDLL = NULL;
break;
}
return( TRUE );
}
//------------------------------------------------------------------------------------------------------
// This procedure is called when the module is loaded by the serving application. Its main tasks are:
// - Checking whether it is compatible with the given InterfaceVersion
// - Checking whether it is licensed to the given serial number (optional)
// - Storing of the serving application's instance and main windows handle for further use
// - Loading of the language-dependent library
// - Filling in the module ID structure whose address is passed in ModuleID
// - Loading of options from the registry database
// - Loading profiles
// - Allocating any static memory required
DLL_EXPORT int TosoModuleInit( const LPSTR SerialNumber, HINSTANCE hMainInst, HWND hMainWnd,
int InterfaceVersion, MODULE_ID* ModuleID )
{
if( InterfaceVersion < TOSO_MODULE_VERSION ) {
MessageBox( hMainWnd, eMessageText[0], eDialogText[0], MB_OK );
return( 0 );
}
if( !lstrcmp( SerialNumber, "DEMO" ) )
return( 0 );
hGlobalInst = hMainInst;
hGlobalWnd = hMainWnd;
hLanguage = LoadLibrary( "EXPORT.DLL" );
hBitmap = LoadBitmap( hLanguage, "IDB_COMMAND" );
ModuleID->OwnerID = DB_OWNER_TOSO;
ModuleID->ModuleID = 0x2000;
ModuleID->ModuleCTRL = MODULECTRL_ALL;
ModuleID->ModuleProc.InputPointInitProc = (TOSOINPUTPOINTINIT_PROC) NULL;
ModuleID->ModuleProc.InputPointMoveProc = (TOSOINPUTPOINTMOVE_PROC) NULL;
ModuleID->ModuleProc.InputPointExitProc = (TOSOINPUTPOINTEXIT_PROC) NULL;
ModuleID->ModuleProc.InputDisplayProc = (TOSOINPUTDISPLAY_PROC) NULL;
ModuleID->ModuleProc.InputParameterProc = (TOSOINPUTPARAMETER_PROC) NULL;
ModuleID->ModuleProc.InputCancelProc = (TOSOINPUTCANCEL_PROC) NULL;
ModuleID->ModuleProc.InputFinishProc = (TOSOINPUTFINISH_PROC) NULL;
ModuleID->ModuleData.Type = MODULETYPE_EXPORT;
ModuleID->ModuleData.InputData.CommandMode = COMMAND_DIRECT;
ModuleID->ModuleData.MenuData.MenuEntry = eStartUpText[1];
ModuleID->ModuleData.MenuData.Description = eStartUpText[2];
ModuleID->ModuleData.IconHandle = hBitmap;
ModuleID->ModuleData.IconXOffset = 0;
ModuleID->ModuleData.IconYOffset = 0;
ModuleID->ModuleData.IconMode = 0;
ModuleID->CommandData = NULL;
ModuleID->VendorData = NULL;
ModuleID->FileType = eStartUpText[4];
ModuleID->FileExtension = eStartUpText[5];
ModuleID->FileDefault = eStartUpText[6];
ModuleLoadSettings();
return( TOSO_MODULE_VERSION );
}
//------------------------------------------------------------------------------------------------------
// This procedure is called when the module is removed by the serving application. Its main tasks are:
// - Checking whether anything is to be saved. If so, it should display a message information the user
// about it and allowing him to save those changes.
// - Freeing of all statically allocated memory.
// If this procedure return FALSE, the serving application will not be able to terminate. So please, do
// only return FALSE if shutting down the module now would severely damage or destroy user data.
DLL_EXPORT BOOL TosoModuleExit( void )
{
ModuleSaveSettings();
DeleteBitmap( hBitmap );
return( TRUE );
}
//------------------------------------------------------------------------------------------------------
// This procedure is called when the user wants to save a non-TVG drawing using the File>Save as command.
// For an export filter, its task is simply to save the file.
DLL_EXPORT BOOL TosoModuleExport( const LPSTR FileName, int Flag )
{
HANDLE FileHandle;
BOOL Result = FALSE;
if( TosoFileCreate( &FileHandle, FileName ) ) {
ModuleExport( FileHandle, FileName, Flag );
TosoFileClose( FileHandle );
switch( gError ) {
case 999:
TosoFileDelete( FileName );
MessageBox( hGlobalWnd, eMessageText[2], eDialogText[0], MB_OK );
Result = TRUE;
break;
case 0:
Result = TRUE;
break;
default:
TosoFileDelete( FileName );
MessageBox( hGlobalWnd, eMessageText[4], eDialogText[0], MB_OK );
Result = FALSE;
break;
}
}
return( Result );
}
//------------------------------------------------------------------------------------------------------
// This procedure is called when a module's command is chosen by the user. For an export filter, its
// main tasks are:
// - Parameter editing
// - Help file display
DLL_EXPORT BOOL TosoModuleCommand( int CommandID, int ExecMode )
{
switch( ExecMode ) { // Check which type of action is requested
case MODULEEXEC_HELP: // Display the corresponding help topic
{
FILENAME FileName;
TosoFileApplicationPath( "EXPORT.HLP", FileName );
WinHelp( hGlobalWnd, FileName, HELP_CONTEXT, 1 );
}
return( TRUE );
case MODULEEXEC_USER: // Edit the options
{
DUMMYSTR Text1, Text2;
TOSO_GET_BUILD_DATE( Text2 );
wsprintf( Text1, eStartUpText[0], Text2 );
MessageBox( GetActiveWindow(), Text1, eDialogText[0], MB_OK );
}
return( TRUE );
case MODULEEXEC_SYSTEM: // Execute the command
// Nothing to do here...
break;
case MODULEEXEC_GET_PROFILE: // Read drawing-dependent data
// Nothing to do here...
break;
case MODULEEXEC_SET_PROFILE: // Write drawing-dependent data
// Nothing to do here...
break;
}
return( FALSE );
}