如何在mfc中循环注册表值 [英] How loop through registry values in mfc
本文介绍了如何在mfc中循环注册表值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个注册表项路径是HKEY_CURRENT_USER \\ SOFTWARE \\ MyRegDemo
因为我有6个DWORD值
我想打开键并循环读取值并从整数数组中获取和设置值。
我尝试过:
void CRegistryDemoDlg :: OnBnClickedSet()
{
// TODO :在这里添加您的控制通知处理程序代码
int values [6] = {0,0,0,0,0,0};
CRegKey reg;
HKEY m_hKeyParent = HKEY_CURRENT_USER;
LPCTSTR m_myKey = L\\Software \\ MyRegDemo;
reg.Create(m_hKeyParent,m_myKey);
if(reg.Open(m_hKeyParent,m_myKey)== ERROR_SUCCESS)
{
//这里我想从数组值设置每个条目的值..
//使用for循环
reg.Close();
}
}
void CRegistryDemoDlg :: OnBnClickedGet()
{
// TODO:在这里添加您的控制通知处理程序代码
CRegKey REG;
int values [6];
HKEY m_hkeyParent = HKEY_CURRENT_USER;
LPCTSTR m_myKey = L\\Software \\ MyRegDemo;
DWORD值;
if(reg.Open(m_hkeyParent,m_myKey)== ERROR_SUCCESS)
{
//这里我想通过循环中的值从
reg.Close获取注册表中的值);
}
}
解决方案
为了编写,您可以使用循环,在每次迭代时调用SetWORDValue
或SetQWORDValue
(视情况而定)或没有循环,只调用一次SetBinaryValue
(参见 CRegKey类 [ ^ ])。
你可能会以类似的方式回读数据。
您可能还会看一个(或更多)关于注册表主题的CodeProject文章 [ ^ 一>]。
I have a registry key the path is HKEY_CURRENT_USER\\SOFTWARE\\MyRegDemo
in that I have 6 DWORD Values
I want to open the key and loop through the values and get and set values from integer array.
What I have tried:
void CRegistryDemoDlg::OnBnClickedSet() { // TODO: Add your control notification handler code here int values[6]={0,0,0,0,0,0}; CRegKey reg; HKEY m_hKeyParent=HKEY_CURRENT_USER; LPCTSTR m_myKey=L"\\Software\\MyRegDemo"; reg.Create(m_hKeyParent,m_myKey); if(reg.Open(m_hKeyParent,m_myKey)==ERROR_SUCCESS) { //Here I want to set the values for each entry from array values.. //using for loop reg.Close(); } } void CRegistryDemoDlg::OnBnClickedGet() { // TODO: Add your control notification handler code here CRegKey reg; int values[6]; HKEY m_hkeyParent=HKEY_CURRENT_USER; LPCTSTR m_myKey=L"\\Software\\MyRegDemo"; DWORD dvalue; if(reg.Open(m_hkeyParent,m_myKey)==ERROR_SUCCESS) { //Here I want to get the values from registry through loop in values reg.Close(); } }
解决方案
In order to write, you may either use a loop, calling at each iterationSetWORDValue
orSetQWORDValue
(as appropriate) or, without the loop, calling just one timeSetBinaryValue
(see CRegKey Class[^]).
You may read back the data in a similar way.
You might also have a look at one (or more) CodeProject article(s) on the Registry topic[^].
这篇关于如何在mfc中循环注册表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文