📄 reg.h
字号:
#ifndef _REG_H
#define _REG_H
extern LPCTSTR rkSettings; // = _T("Settings");
extern LPCTSTR rkIPMonikers; // = _T("Settings\\IPMonikers");
extern LPCTSTR rkIPAlias;
extern LPCTSTR rkLastStatus; // = _T("Settings\\LastStatus");
extern LPCTSTR rvSnapshot; // = _T("SnapshotPath");
extern LPCTSTR rvBackup; // = _T("BackupPath");
extern LPCTSTR rkVWTitle; // = _T("Settings\\VWTitle");
extern LPCTSTR rvRender;
extern LPCTSTR rvMem;
//////////////////////////////////////////////////////////////////////////
// 2003-7-1, nodman
static bool write_string(LPCTSTR sec, LPCTSTR key, LPCTSTR value)
{
CWinApp* app = AfxGetApp();
return FALSE != app->WriteProfileString(sec, key, value);
}
static CString read_string(LPCTSTR sec, LPCTSTR key)
{
CWinApp* app = AfxGetApp();
return app->GetProfileString(sec, key);
}
static bool write_dword(LPCTSTR sec, LPCTSTR key, DWORD value)
{
CWinApp* app = AfxGetApp();
return FALSE != app->WriteProfileInt(sec, key, value);
}
static DWORD read_dword(LPCTSTR sec, LPCTSTR key, DWORD def = 0)
{
CWinApp* app = AfxGetApp();
return app->GetProfileInt(sec, key, def);
}
static bool write_binary(LPCTSTR sec, LPCTSTR key, byte* buf, UINT size)
{
CWinApp* app = AfxGetApp();
return FALSE != app->WriteProfileBinary(sec, key, buf, size);
}
// !!! you must "delete[] buf" after operations !!!
static bool read_binary(LPCTSTR sec, LPCTSTR key, byte*& buf, UINT& size)
{
CWinApp* app = AfxGetApp();
return FALSE != app->GetProfileBinary(sec, key, &buf, &size);
}
static bool delete_string(LPCTSTR sec, LPCTSTR key)
{
static LPCTSTR slash = _T("\\");
CString actual_path(_T("Software\\"));
actual_path +=
CString(AfxGetApp()->m_pszRegistryKey) +
slash +
AfxGetApp()->m_pszAppName +
slash +
sec;
HKEY hkey = NULL;
LONG res = S_OK;
res = RegOpenKeyEx(HKEY_CURRENT_USER, actual_path, 0, KEY_ALL_ACCESS, &hkey);
if( res )
return false;
res = RegDeleteValue(hkey, key);
RegCloseKey(hkey);
return res == S_OK;
}
// 举例: path = "Software\\Senao\\DvrNetClient\\Settings"
template<class T, class A>
static bool enum_reg(LPCTSTR path, T& sk)
{
static LPCTSTR slash = _T("\\");
CString actual_path(_T("Software\\"));
actual_path +=
CString(AfxGetApp()->m_pszRegistryKey) +
slash +
AfxGetApp()->m_pszAppName +
slash +
path;
LONG res = 0;
HKEY key = NULL;
ERROR_SUCCESS;
res = RegOpenKeyEx(HKEY_CURRENT_USER, actual_path, 0, KEY_ALL_ACCESS, &key);
if( res )
return false;
TCHAR keyname[200];
TCHAR data[200];
DWORD keynamelen = 0;
DWORD datalen = 0;
int index = 0;
while(1)
{
keynamelen = 200;
datalen = 200;
res = RegEnumValue(key, index++, keyname, &keynamelen, NULL, NULL, (LPBYTE)data, &datalen);
if( res )
break;
//sk[keyname] = data;
sk.push_back(A(keyname, data));
}
RegCloseKey(key);
return true;
}
static void set_key(CWinApp* app, LPCTSTR company, LPCTSTR product)
{
free((void*)app->m_pszAppName);
app->m_pszAppName = _tcsdup(product);
//app->SetRegistryKey(company);
BOOL bEnable = AfxEnableMemoryTracking(FALSE);
free((void*)app->m_pszRegistryKey);
app->m_pszRegistryKey = _tcsdup(company);
free((void*)app->m_pszProfileName);
app->m_pszProfileName = _tcsdup(app->m_pszAppName);
AfxEnableMemoryTracking(bEnable);
}
#endif // _REG_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -