-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathIni.h
executable file
·95 lines (77 loc) · 3.07 KB
/
Ini.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 预处理
#pragma once
#include "Define.h"
#include "Macro.h"
#include <Windows.h>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CIni 类
class CIni
{
private:
// INI 文件名
static TCHAR m_tzFileName[MAX_PATH];
public:
// 设置 INI 文件名
inline static VOID WINAPI SetIniName()
{
GetModuleFileName(NULL, m_tzFileName, MAX_PATH);
lstrcpy(_StrEnd(m_tzFileName) - _LengthOf(EXT_Ini), EXT_Ini);
}
// 设置 INI 文件名
inline static VOID WINAPI SetIniName(PCTSTR ptzFileName)
{
_StrToStr(m_tzFileName, ptzFileName);
}
// 获取整数
inline static UINT WINAPI GetInt(PCTSTR ptzKeyName, INT iDefault = 0, PCTSTR ptzSectionName = INI_Main)
{
return GetPrivateProfileInt(ptzSectionName, ptzKeyName, iDefault, m_tzFileName);
}
// 设置整数
inline static BOOL WINAPI SetInt(PCTSTR ptzKeyName, INT iValue = 0, PCTSTR ptzSectionName = INI_Main)
{
TCHAR tzString[16];
wsprintf(tzString, TEXT("%d"), iValue);
return WritePrivateProfileString(ptzSectionName, ptzKeyName, tzString, m_tzFileName);
}
// 获取字符串
inline static DWORD WINAPI GetString(PCTSTR ptzKeyName, PTSTR ptzReturnedString,
DWORD dwSize = MAX_PATH, PCTSTR ptzDefault = NULL, PCTSTR ptzSectionName = INI_Main)
{
return GetPrivateProfileString(ptzSectionName, ptzKeyName, ptzDefault, ptzReturnedString,
dwSize, m_tzFileName);
}
// 设置字符串
inline static BOOL WINAPI SetString(PCTSTR ptzKeyName, PCTSTR ptzString = NULL, PCTSTR ptzSectionName = INI_Main)
{
return WritePrivateProfileString(ptzSectionName, ptzKeyName, ptzString, m_tzFileName);
}
// 获取结构
inline static BOOL WINAPI GetStruct(PCTSTR ptzKeyName, PVOID pvStruct, UINT uSize, PCTSTR ptzSectionName = INI_Main)
{
return GetPrivateProfileStruct(ptzSectionName, ptzKeyName, pvStruct, uSize, m_tzFileName);
}
// 设置结构
inline static BOOL WINAPI SetStruct(PCTSTR ptzKeyName, PVOID pvStruct, UINT uSize, PCTSTR ptzSectionName = INI_Main)
{
return WritePrivateProfileStruct(ptzSectionName, ptzKeyName, pvStruct, uSize, m_tzFileName);
}
// 获取节
inline static DWORD WINAPI GetSection(PTSTR ptzReturnBuffer, DWORD dwSize, PCTSTR ptzSectionName = INI_Main)
{
return GetPrivateProfileSection(ptzSectionName, ptzReturnBuffer, dwSize, m_tzFileName);
}
// 设置节
inline static DWORD WINAPI SetSection(PCTSTR ptzString, PCTSTR ptzSectionName = INI_Main)
{
return WritePrivateProfileSection(ptzSectionName, ptzString, m_tzFileName);
}
// 获取节名
inline static DWORD WINAPI GetSectionNames(PTSTR ptzReturnBuffer, DWORD dwSize)
{
return GetPrivateProfileSectionNames(ptzReturnBuffer, dwSize, m_tzFileName);
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////