You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
4.3 KiB
132 lines
4.3 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: LgPrivateProfile.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of LgPrivateProfile.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "LgPrivateProfile.h"
|
|
|
|
RECT CLgPrivateProfile::GetPrivateProfileRect( LPCTSTR pSectionName, LPCTSTR pValueName, RECT rDefault, LPCTSTR pFileName )
|
|
{
|
|
TCHAR pBuffer[MAX_PATH] = "";
|
|
|
|
// read value from file
|
|
DWORD dwSize = ::GetPrivateProfileString( pSectionName, pValueName, "", pBuffer, MAX_PATH, pFileName );
|
|
|
|
// paranoia: set terminating zero
|
|
pBuffer[dwSize] = 0;
|
|
|
|
// prepare output rect
|
|
RECT rRect = rDefault;
|
|
|
|
// const string with digits
|
|
const TCHAR pDigitSet[] = _T("+-0123456789");
|
|
const TCHAR pSpaceSet[] = _T(" \t,;:.");
|
|
|
|
// calculate string length
|
|
INT nStrLength = _tcslen( pBuffer );
|
|
|
|
// initialize digit pointer
|
|
LPTSTR pDigit = pBuffer;
|
|
|
|
INT nIndex = 0;
|
|
|
|
// find digit
|
|
if( ( nStrLength -= nIndex ) == ( nIndex = _tcscspn( pDigit += nIndex, pDigitSet ) ) ) return rRect;
|
|
// convert
|
|
rRect.left = atoi( pDigit += nIndex );
|
|
// find next space
|
|
if( ( nStrLength -= nIndex ) == ( nIndex = _tcscspn( pDigit, pSpaceSet ) ) ) return rRect;
|
|
|
|
// find digit
|
|
if( ( nStrLength -= nIndex ) == ( nIndex = _tcscspn( pDigit += nIndex, pDigitSet ) ) ) return rRect;
|
|
// convert
|
|
rRect.top = atoi( pDigit += nIndex );
|
|
// find next space
|
|
if( ( nStrLength -= nIndex ) == ( nIndex = _tcscspn( pDigit, pSpaceSet ) ) ) return rRect;
|
|
|
|
// find digit
|
|
if( ( nStrLength -= nIndex ) == ( nIndex = _tcscspn( pDigit += nIndex, pDigitSet ) ) ) return rRect;
|
|
// convert
|
|
rRect.right = atoi( pDigit += nIndex );
|
|
// find next space
|
|
if( ( nStrLength -= nIndex ) == ( nIndex = _tcscspn( pDigit, pSpaceSet ) ) ) return rRect;
|
|
|
|
// find digit
|
|
if( ( nStrLength -= nIndex ) == ( nIndex = _tcscspn( pDigit += nIndex, pDigitSet ) ) ) return rRect;
|
|
// convert
|
|
rRect.bottom = atoi( pDigit += nIndex );
|
|
// find next space
|
|
if( ( nStrLength -= nIndex ) == ( nIndex = _tcscspn( pDigit, pSpaceSet ) ) ) return rRect;
|
|
|
|
// convert to integer
|
|
return rRect;
|
|
}
|
|
|
|
INT CLgPrivateProfile::WritePrivateProfileRect( LPCTSTR pSectionName, LPCTSTR pValueName, RECT rValue, LPCTSTR pFileName )
|
|
{
|
|
TCHAR pValue[MAX_PATH];
|
|
|
|
// init default
|
|
INT nCount = _snprintf( pValue, MAX_PATH, _T("%d,%d,%d,%d"), rValue.left, rValue.top, rValue.right, rValue.bottom );
|
|
if( nCount < 0 )
|
|
nCount = MAX_PATH - 1;
|
|
pValue[nCount] = 0;
|
|
|
|
// write value from file
|
|
return ::WritePrivateProfileString( pSectionName, pValueName, pValue, pFileName );
|
|
}
|
|
|
|
INT CLgPrivateProfile::GetPrivateProfileInt( LPCTSTR pSectionName, LPCTSTR pValueName, INT nDefault, LPCTSTR pFileName )
|
|
{
|
|
TCHAR pBuffer[MAX_PATH];
|
|
TCHAR pDefault[MAX_PATH];
|
|
|
|
// init default
|
|
INT nCount = _snprintf( pDefault, MAX_PATH, _T("%d"), nDefault );
|
|
if( nCount < 0 )
|
|
*pDefault = '0';
|
|
|
|
// read value from file
|
|
DWORD dwSize = ::GetPrivateProfileString( pSectionName, pValueName, pDefault, pBuffer, MAX_PATH, pFileName );
|
|
|
|
// paranoia: set terminating zero
|
|
pBuffer[dwSize] = 0;
|
|
|
|
// convert to integer
|
|
return atoi( pBuffer );
|
|
}
|
|
|
|
INT CLgPrivateProfile::WritePrivateProfileInt( LPCTSTR pSectionName, LPCTSTR pValueName, INT nValue, LPCTSTR pFileName )
|
|
{
|
|
TCHAR pValue[MAX_PATH];
|
|
|
|
// init default
|
|
INT nCount = _snprintf( pValue, MAX_PATH, _T("%d"), nValue );
|
|
if( nCount < 0 )
|
|
nCount = MAX_PATH - 1;
|
|
pValue[nCount] = 0;
|
|
|
|
// write value from file
|
|
return ::WritePrivateProfileString( pSectionName, pValueName, pValue, pFileName );
|
|
}
|
|
|
|
HBITMAP CLgPrivateProfile::LoadProfileImage( LPCTSTR pSectionName, LPCTSTR pBitmapName, LPCTSTR pIniFileName )
|
|
{
|
|
TCHAR pBitmapFileName[MAX_PATH];
|
|
INT nSize = GetPrivateProfileString( pSectionName, pBitmapName, "", pBitmapFileName, MAX_PATH, pIniFileName );
|
|
pBitmapFileName[nSize] = 0;
|
|
TCHAR pFullName[MAX_PATH];
|
|
_tcscpy( pFullName, pIniFileName );
|
|
::PathRemoveFileSpec( pFullName );
|
|
::PathCombine( pFullName, pFullName, pBitmapFileName );
|
|
return (HBITMAP)LoadImage( NULL, pFullName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE );
|
|
}
|