当前位置: 首页>>代码示例>>C++>>正文


C++ CWinApp::GetSectionKey方法代码示例

本文整理汇总了C++中CWinApp::GetSectionKey方法的典型用法代码示例。如果您正苦于以下问题:C++ CWinApp::GetSectionKey方法的具体用法?C++ CWinApp::GetSectionKey怎么用?C++ CWinApp::GetSectionKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CWinApp的用法示例。


在下文中一共展示了CWinApp::GetSectionKey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: MRCWriteProfileBinary

//-------------------------------------------------------------------------
BOOL MRCWriteProfileBinary(LPCTSTR lpszSection, LPCTSTR lpszEntry, 
										LPVOID pData, DWORD nBufferSize)
// Write a binary value into the registry. If the pointer to the buffer
// is NULL then the current value is deleted. This can be generally used
// for removing any value not just binary ones
//-------------------------------------------------------------------------
{
	CWinApp * pApp = AfxGetApp();
	ASSERT(pApp != NULL);
	ASSERT(lpszSection != NULL);
	ASSERT(lpszEntry != NULL);
	ASSERT(pApp->m_pszRegistryKey != NULL); // We must be using the registry not 
									  // INI files for binary to be supported
	LONG lRes;
	
	HKEY hSecKey = pApp->GetSectionKey(lpszSection);
	if (hSecKey == NULL)
		return FALSE;
	if (pData == NULL)
	{
		lRes = ::RegDeleteValue(hSecKey, (LPTSTR)lpszEntry);
	}
	else
	{
		lRes = RegSetValueEx(hSecKey, lpszEntry, NULL, REG_BINARY,
								(LPBYTE)pData, nBufferSize);
	}
	RegCloseKey(hSecKey);
	return (lRes == ERROR_SUCCESS) ? TRUE : FALSE;
}
开发者ID:Joincheng,项目名称:lithtech,代码行数:31,代码来源:FRAMEWND.CPP

示例2: MRCGetProfileBinary

//-------------------------------------------------------------------------
BOOL MRCGetProfileBinary(LPCTSTR lpszSection, LPCTSTR lpszEntry,
					LPVOID pData, DWORD nBufferSize)
// Read the registry for a binary value. 
// Various assertions fail if the size of the value does not match that
// which is asked for. We can assume that the registry data should always
// match the current software. Any conversion required between versions
// should have taken place when initializing the app 
//-------------------------------------------------------------------------
{
	CWinApp * pApp = AfxGetApp();
	ASSERT(lpszSection != NULL);
	ASSERT(lpszEntry != NULL);
	ASSERT(pApp->m_pszRegistryKey != NULL); // We must be using the registry not INI files 
									 //for binary to be supported

	HKEY hSecKey = pApp->GetSectionKey(lpszSection);
	if (hSecKey == NULL)
		return FALSE;
	DWORD dwType;
	DWORD dwCount = nBufferSize;
	LONG lRes = RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, (unsigned long *)&dwType,
					(LPBYTE)pData, (unsigned long *)&dwCount);
	RegCloseKey(hSecKey);
	ASSERT(lRes != ERROR_MORE_DATA); // Is Data in the registry larger than the buffer?
		 							 // We should have converted registry data on start up.
	if (lRes == ERROR_SUCCESS)
	{
		ASSERT(dwType == REG_BINARY);
		ASSERT(dwCount = nBufferSize); // The data should be the expected size
		return TRUE;
	}
	return FALSE;
}
开发者ID:Joincheng,项目名称:lithtech,代码行数:34,代码来源:FRAMEWND.CPP

示例3: OnInitDialog

BOOL CAuthDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	CWinApp* pApp = AfxGetApp();

	if (pApp->m_pszRegistryKey) {
		CRegKey hSecKey(pApp->GetSectionKey(IDS_R_LOGINS));

		if (hSecKey) {
			int i = 0;
			TCHAR username[256], password[256];

			for (;;) {
				DWORD unlen = _countof(username);
				DWORD pwlen = sizeof(password);
				DWORD type = REG_SZ;

				if (ERROR_SUCCESS == RegEnumValue(hSecKey, i++, username, &unlen, 0, &type, (BYTE*)password, &pwlen)) {
					m_logins[username] = DEncrypt(password);
					m_usernamectrl.AddString(username);
				} else {
					break;
				}
			}
		}
	} else {
		CAutoVectorPtr<TCHAR> buff;
		buff.Allocate(32767/sizeof(TCHAR));

		DWORD len = GetPrivateProfileSection(IDS_R_LOGINS, buff, 32767/sizeof(TCHAR), pApp->m_pszProfileName);

		TCHAR* p = buff;
		while (*p && len > 0) {
			CString str = p;
			p += str.GetLength()+1;
			len -= str.GetLength()+1;
			CAtlList<CString> sl;
			Explode(str, sl, '=', 2);

			if (sl.GetCount() == 2) {
				m_logins[sl.GetHead()] = DEncrypt(sl.GetTail());
				m_usernamectrl.AddString(sl.GetHead());
			}
		}
	}

	m_usernamectrl.SetFocus();

	return TRUE;
}
开发者ID:chinajeffery,项目名称:MPC-BE--1.2.3,代码行数:51,代码来源:AuthDlg.cpp


注:本文中的CWinApp::GetSectionKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。