📄 cfgfile.c
字号:
//------------------------------------------------------------------------------
// File: cCfgFile.c
// Date: 2001-7-12 pm 01:44:21
// Written by: CYu
// Decription:
// Modification record
//------------------------------------------------------------------------------
// Copyright: EPSON Proprietary Material
// Copyright (c) 2001, All Rights Reserved
// SHANGHAI EPSON ELECTRONICS CO., LTD.
//
// DISTRIBUTION PROHIBITED without written authorization from EPSON
//------------------------------------------------------------------------------
#include <windows.h>
#include <io.h>
#include <fcntl.h>
#include <stdio.h>
#include <srvstruct.h>
//--- macro and definition -----------------------------------------------------
//--- static variables ---------------------------------------------------------
//--- external variables -------------------------------------------------------
KEYPOS kpa[256];
int screenWidth;
int screenHeight;
int screenPosX;
int screenPosY;
char tcaPanelFileName[256];
int nKeyNumber=0;
//--- shared variables ---------------------------------------------------------
//--- static functions ---------------------------------------------------------
static BOOL GetFileLine( int handle, BYTE *pLineBuffer );
static void ShowAlarmMessage( LPSTR lpMessage );
//--- external functions -------------------------------------------------------
extern BOOL GetConfigurationFromFile( void );
//------------------------------------------------------------------------------
// Function name : GetConfigurationFromFile
// Description :
// No return value
// No argument
// Remarks : nothing special. You are the expert in this technical area
// So also :
//------------------------------------------------------------------------------
BOOL GetConfigurationFromFile( void )
{
int handle;
BYTE baLineBuffer[1024];
handle = _open( "config\\cSim.ini", _O_BINARY | _O_RDONLY );
if( handle == -1 )
{
ShowAlarmMessage( "Can not open configuration file" );
return FALSE;
}
else
{
while( GetFileLine( handle, baLineBuffer ) )
{
if( baLineBuffer[0] == '\r' )
continue;
else if( !memcmp( baLineBuffer, "//", 2 ) )
continue;
else if( !memcmp( baLineBuffer, "PanelBmp=", 9 ) )
sprintf( tcaPanelFileName, "config\\%s",baLineBuffer+9 );
else if( !memcmp( baLineBuffer, "ScreenWidth=", 12 ) )
screenWidth = atoi( baLineBuffer+12 );
else if( !memcmp( baLineBuffer, "ScreenHeight=", 13 ) )
screenHeight = atoi( baLineBuffer+13 );
else if( !memcmp( baLineBuffer, "ScreenPosX=", 11 ) )
screenPosX = atoi( baLineBuffer+11 );
else if( !memcmp( baLineBuffer, "ScreenPosY=", 11 ) )
screenPosY = atoi( baLineBuffer+11 );
else if( !memcmp( baLineBuffer, "KeyNumber=", 10 ) )
{
int i;
nKeyNumber = atoi( baLineBuffer+10 );
memset( kpa, 0, sizeof( kpa ) );
for(i=0;i<nKeyNumber;i++)
{
GetFileLine( handle, baLineBuffer );
sscanf( baLineBuffer, "%d,%d,%d%*s", &kpa[i].uKeyCode, &kpa[i].pt.x, &kpa[i].pt.y );
}
}
}
_close( handle );
return TRUE;
}
}
//------------------------------------------------------------------------------
// Function name : GetFileLine
// Description :
// Return type : BOOL - this function return FALSE while reach the end of
// file
// Argument : int handle
// Argument : BYTE *pLineBuffer
// Remarks :
// So also :
//------------------------------------------------------------------------------
static BOOL GetFileLine( int handle,
BYTE *pLineBuffer )
{
int i;
BOOL bRet;
i = 0;
while( i<255 )
{
if( _read( handle, pLineBuffer+i, 1 ) )
{
if( pLineBuffer[i] == '\n' )// 0x0a
{
if( pLineBuffer[i-1] == '\r' )// 0x0a
pLineBuffer[i-1] = 0;
bRet = TRUE;
break;
}
}
else// end of file
{
bRet = FALSE;
break;
}
i++;
}
pLineBuffer[i] = 0;
return bRet;
}
//------------------------------------------------------------------------------
// Function name : ShowAlarmMessage
// Description :
// No return value
// Argument : LPSTR lpMessage - caller decides the message text
// Remarks :
// So also :
//------------------------------------------------------------------------------
void ShowAlarmMessage( LPSTR lpMessage )
{
if( strlen( lpMessage ) )
{
// annoying sound
Beep( 1000, 50 );
Beep( 2000, 50 );
Beep( 1500, 50 );
Beep( 2000, 50 );
MessageBox( NULL, lpMessage, "Error", MB_OK | MB_ICONERROR );
}
}
//----------------------------- The End of the File ----------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -