Old fashion design for PC-104
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

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: LgPrivateProfile.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgPrivateProfile.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "LgPrivateProfile.h"
  16. RECT CLgPrivateProfile::GetPrivateProfileRect( LPCTSTR pSectionName, LPCTSTR pValueName, RECT rDefault, LPCTSTR pFileName )
  17. {
  18. TCHAR pBuffer[MAX_PATH] = "";
  19. // read value from file
  20. DWORD dwSize = ::GetPrivateProfileString( pSectionName, pValueName, "", pBuffer, MAX_PATH, pFileName );
  21. // paranoia: set terminating zero
  22. pBuffer[dwSize] = 0;
  23. // prepare output rect
  24. RECT rRect = rDefault;
  25. // const string with digits
  26. const TCHAR pDigitSet[] = _T("+-0123456789");
  27. const TCHAR pSpaceSet[] = _T(" \t,;:.");
  28. // calculate string length
  29. INT nStrLength = _tcslen( pBuffer );
  30. // initialize digit pointer
  31. LPTSTR pDigit = pBuffer;
  32. INT nIndex = 0;
  33. // find digit
  34. if( ( nStrLength -= nIndex ) == ( nIndex = _tcscspn( pDigit += nIndex, pDigitSet ) ) ) return rRect;
  35. // convert
  36. rRect.left = atoi( pDigit += nIndex );
  37. // find next space
  38. if( ( nStrLength -= nIndex ) == ( nIndex = _tcscspn( pDigit, pSpaceSet ) ) ) return rRect;
  39. // find digit
  40. if( ( nStrLength -= nIndex ) == ( nIndex = _tcscspn( pDigit += nIndex, pDigitSet ) ) ) return rRect;
  41. // convert
  42. rRect.top = atoi( pDigit += nIndex );
  43. // find next space
  44. if( ( nStrLength -= nIndex ) == ( nIndex = _tcscspn( pDigit, pSpaceSet ) ) ) return rRect;
  45. // find digit
  46. if( ( nStrLength -= nIndex ) == ( nIndex = _tcscspn( pDigit += nIndex, pDigitSet ) ) ) return rRect;
  47. // convert
  48. rRect.right = atoi( pDigit += nIndex );
  49. // find next space
  50. if( ( nStrLength -= nIndex ) == ( nIndex = _tcscspn( pDigit, pSpaceSet ) ) ) return rRect;
  51. // find digit
  52. if( ( nStrLength -= nIndex ) == ( nIndex = _tcscspn( pDigit += nIndex, pDigitSet ) ) ) return rRect;
  53. // convert
  54. rRect.bottom = atoi( pDigit += nIndex );
  55. // find next space
  56. if( ( nStrLength -= nIndex ) == ( nIndex = _tcscspn( pDigit, pSpaceSet ) ) ) return rRect;
  57. // convert to integer
  58. return rRect;
  59. }
  60. INT CLgPrivateProfile::WritePrivateProfileRect( LPCTSTR pSectionName, LPCTSTR pValueName, RECT rValue, LPCTSTR pFileName )
  61. {
  62. TCHAR pValue[MAX_PATH];
  63. // init default
  64. INT nCount = _snprintf( pValue, MAX_PATH, _T("%d,%d,%d,%d"), rValue.left, rValue.top, rValue.right, rValue.bottom );
  65. if( nCount < 0 )
  66. nCount = MAX_PATH - 1;
  67. pValue[nCount] = 0;
  68. // write value from file
  69. return ::WritePrivateProfileString( pSectionName, pValueName, pValue, pFileName );
  70. }
  71. INT CLgPrivateProfile::GetPrivateProfileInt( LPCTSTR pSectionName, LPCTSTR pValueName, INT nDefault, LPCTSTR pFileName )
  72. {
  73. TCHAR pBuffer[MAX_PATH];
  74. TCHAR pDefault[MAX_PATH];
  75. // init default
  76. INT nCount = _snprintf( pDefault, MAX_PATH, _T("%d"), nDefault );
  77. if( nCount < 0 )
  78. *pDefault = '0';
  79. // read value from file
  80. DWORD dwSize = ::GetPrivateProfileString( pSectionName, pValueName, pDefault, pBuffer, MAX_PATH, pFileName );
  81. // paranoia: set terminating zero
  82. pBuffer[dwSize] = 0;
  83. // convert to integer
  84. return atoi( pBuffer );
  85. }
  86. INT CLgPrivateProfile::WritePrivateProfileInt( LPCTSTR pSectionName, LPCTSTR pValueName, INT nValue, LPCTSTR pFileName )
  87. {
  88. TCHAR pValue[MAX_PATH];
  89. // init default
  90. INT nCount = _snprintf( pValue, MAX_PATH, _T("%d"), nValue );
  91. if( nCount < 0 )
  92. nCount = MAX_PATH - 1;
  93. pValue[nCount] = 0;
  94. // write value from file
  95. return ::WritePrivateProfileString( pSectionName, pValueName, pValue, pFileName );
  96. }
  97. HBITMAP CLgPrivateProfile::LoadProfileImage( LPCTSTR pSectionName, LPCTSTR pBitmapName, LPCTSTR pIniFileName )
  98. {
  99. TCHAR pBitmapFileName[MAX_PATH];
  100. INT nSize = GetPrivateProfileString( pSectionName, pBitmapName, "", pBitmapFileName, MAX_PATH, pIniFileName );
  101. pBitmapFileName[nSize] = 0;
  102. TCHAR pFullName[MAX_PATH];
  103. _tcscpy( pFullName, pIniFileName );
  104. ::PathRemoveFileSpec( pFullName );
  105. ::PathCombine( pFullName, pFullName, pBitmapFileName );
  106. return (HBITMAP)LoadImage( NULL, pFullName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE );
  107. }