还是关于ListBox的问题
大家早上好,昨天问了个相同的问题,虽然揭贴了,但是还是没大弄明白。
今天想请教前辈再给予些指教,给个简单的代码原型学习一下啊。
本人学习练习所编写的程序,只会用他来修改和创建注册表的数据(★★☆☆而不会读取并把他显示出来以便修改☆☆★★)而且新学,代码繁琐复杂不合理。
下面列出其中一些代码(太多发不出):
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Application-> MessageBox( "你已经保存了所作的修改 ", "保存完毕 ",65);
if(RadioButton1-> Checked==true)
{TRegistry®Key=*new TRegistry();
regKey.RootKey=HKEY_CURRENT_USER;
regKey.OpenKey( "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System ",true);
regKey.WriteInteger( "DisableRegistryTools ",1);
delete ®Key;}//禁止编辑注册表
if(RadioButton2-> Checked==true)
{TRegistry®Key=*new TRegistry();
regKey.RootKey=HKEY_CURRENT_USER;
regKey.OpenKey( "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System ",true);
regKey.WriteInteger( "DisableRegistryTools ",0);
delete ®Key;}//允许编辑注册表
int nDiskAll,DiskAll,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,nc=0,nd=0,ne=0,nf=0,ng=0,nh=0;//定义各个盘
if(CheckBox1-> Checked==true)
{
c=0X04;
}
if(CheckBox2-> Checked==true)
{
d=0X08;
}
if(CheckBox3-> Checked==true)
{
e=0X10;
}
if(CheckBox4-> Checked==true)
{
f=0X20;
}
if(CheckBox5-> Checked==true)
{
g=0X40;
}
if(CheckBox6-> Checked==true)
{
h=0X80;
}
if(CheckBox7-> Checked==true)
{
i=0X100;
}
if(CheckBox8-> Checked==true)
{
j=0X200;
}
if(CheckBox9-> Checked==true)
{
k=0X400;
}
if(CheckBox10-> Checked==true)
{
l=0X800;
} //给各个盘对应的定义赋值
DiskAll=c+d+e+f+g+h+i+j+k+l;
TRegistry®Key=*new TRegistry();
regKey.RootKey=HKEY_CURRENT_USER;
regKey.OpenKey( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer ",true);
regKey.WriteInteger( "NoDrives ",(DiskAll));
delete ®Key;
//隐藏多个驱动器
if(RadioButton5-> Checked==true)
{
TRegistry®Key=*new TRegistry();
regKey.RootKey=HKEY_CURRENT_USER;
regKey.OpenKey( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer ",true);
regKey.WriteInteger( "NoRun ",1);
delete ®Key;
}//禁止开始菜单的运行
if(RadioButton6-> Checked==true)
{
TRegistry®Key=*new TRegistry();
regKey.RootKey=HKEY_CURRENT_USER;
regKey.OpenKey( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer ",true);
regKey.WriteInteger( "NoRun ",0);
delete ®Key;
}//允许开始菜单的运行
if(RadioButton7-> Checked==true)
{
TRegistry®Key=*new TRegistry();
regKey.RootKey=HKEY_CURRENT_USER;
regKey.OpenKey( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer ",true);
regKey.WriteInteger( "NoTrayItemsDisplay ",1);
delete ®Key;
}//隐藏通知区域
if(RadioButton8-> Checked==true)
{
TRegistry®Key=*new TRegistry();
regKey.RootKey=HKEY_CURRENT_USER;
regKey.OpenKey( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer ",true);
regKey.WriteInteger( "NoTrayItemsDisplay ",0);
delete ®Key;
}//显示通知区域
/* if(CheckBox11-> Checked==true)
{TRegistry®Key=*new TRegistry();
regKey.RootKey=HKEY_CURRENT_USER;
regKey.OpenKey( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer ",true);
regKey.WriteInteger( "NoViewOnDrive ",0X04);
delete ®Key;
}//禁止使用c盘 */
if(CheckBox11-> Checked==true)
{
nc=0X04;
}
if(CheckBox12-> Checked==true)
{
nd=0X08;
}
if(CheckBox13-> Checked==true)
{
ne=0X10;
}
if(CheckBox14-> Checked==true)
{
nf=0X20;
}
if(CheckBox15-> Checked==true)
{
ng=0X40;
}
if(CheckBox16-> Checked==true)
{
nh=0X80;
}//给各个盘对应的定义赋值
nDiskAll=nc+nd+ne+nf+ng+nh;
{TRegistry®Key=*new TRegistry();
regKey.RootKey=HKEY_CURRENT_USER;
regKey.OpenKey( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer ",true);
regKey.WriteInteger( "NoViewOnDrive ",(nDiskAll));
delete ®Key;
}//禁止使用一个或多个盘
if(CheckBox17-> Checked==true)
{TRegistry®Key=*new TRegistry();
regKey.RootKey=HKEY_CURRENT_USER;
regKey.OpenKey( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer ",true);
regKey.WriteInteger( "NoViewOnDrive ",0);
delete ®Key;
}//允许使用所有盘
if(CheckBox20-> Checked==true)
{TRegistry®Key=*new TRegistry();
regKey.RootKey=HKEY_LOCAL_MACHINE;
regKey.DeleteKey( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\run ");
regKey.OpenKey( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\run ",true);
regKey.RootKey=HKEY_CURRENT_USER;
regKey.DeleteKey( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\run ");
regKey.OpenKey( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\run ",true);
delete ®Key;
}//清除run
}
//---------------------------------------
String c= " ",d= " ",e= " ",f= " ",g= " ",h= " ",i= " ",j= " ",k= " ",l= " ";
void __fastcall TForm1::CheckBox1Click(TObject *Sender)
{
if(CheckBox1-> Checked==true)
{
c= "C, ";
}
else
{
c= " ";
}
Edit1-> Text=c+d+e+f+g+h+i+j+k+l;
}
//---------------------------------------
void __fastcall TForm1::CheckBox2Click(TObject *Sender)
{
if(CheckBox2-> Checked==true)
{
d= "D, ";
}
else
{
d= " ";
}
Edit1-> Text=c+d+e+f+g+h+i+j+k+l;
}
以上上全是只能修改和创建的。而且基本是针对一个子项的特定的键值。
如果我想用个Listbox的列表选中后在ListView或者别的类似的组件里显示一个子项里所有的键值以便于修改应该怎么做呢?
比如HKEY_CURRENT_USER里面的
Software\\Microsoft\\Internet Explorer\\TypedURLs
读取TypedURLs子项,以显示ie地址栏里面的url列表。而且可以实时删除和修改的。谁能给段简单的代码原型学习一下呢?
问题重点重述:
1、★Listbox配合什么组件可以达到如上几行说明的效果并且恳请给予示范★
2、★解决问题的同时,感觉以上代码放在一个button事件里是不是太多太繁琐了请指教应该怎么做,是不是有更简便的书写方式呢?★
介于新学,希望各位前辈给予热心的指点在此感谢大家了。
在线等待ing...
[解决办法]
有点长了,没太看懂,提供一点建议吧
1.配合listview,设置ViewStyle为vsReport,CheckBoxes设为true.
2.如果感觉太多了,就单独写一个函数实现,然后在button事件里调用。
[解决办法]
读取:
if (regKey-> OpenKey( "Software\\Microsoft\\Internet Explorer\\TypedURLs ",false))
{
regKey-> GetValueNames(lt); //lt 全局TStringList
for (int i=0;i <lt-> Count;i++)
{
ListBox1-> Items-> Add(regKey-> ReadString(lt-> Strings[i]));
}
regKey-> DeleteValue(lt-> Strings[idx]); //删除
lt-> Delete(idx);
//regKey-> WriteString(lt-> Strings[idx], "newstring "); //编辑
}
[解决办法]
ListView 配合ValueListEditor1 实现编辑比较好.
#include <registry.hpp>
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ListBox1-> Items-> Add( "\\Software\\Microsoft\\Internet Explorer\\TypedURLs ");
ListBox1-> ShowHint = true;
}
//---------------------------------------
void __fastcall TForm1::ListBox1Click(TObject *Sender)
{
AnsiString as = ListBox1-> Items-> Strings[ListBox1-> ItemIndex ];
ListBox1-> Hint = as;
TStrings *strs = new TStringList;
TRegistry *reg = new TRegistry();
reg-> RootKey = HKEY_CURRENT_USER;
ValueListEditor1-> Strings-> Clear();
if (reg-> OpenKey(as, false))
{
reg-> GetValueNames(strs);
ValueListEditor1-> OnSetEditText = NULL;
for (int i = 0; i < strs-> Count; i++)
{
ValueListEditor1-> InsertRow(strs-> Strings[i], reg-> ReadString(strs-> Strings[i]), true);
}
ValueListEditor1-> OnSetEditText = ValueListEditor1SetEditText;
reg-> CloseKey();
}
delete reg;
delete strs;
}
//---------------------------------------
void __fastcall TForm1::ValueListEditor1SetEditText(TObject *Sender,
int ACol, int ARow, const AnsiString Value)
{
AnsiString as = ListBox1-> Items-> Strings[ListBox1-> ItemIndex ];
TRegistry *reg = new TRegistry();
reg-> RootKey = HKEY_CURRENT_USER;
if (reg-> OpenKey(as, false))
{
reg-> WriteString(ValueListEditor1-> Keys[ARow], Value);
reg-> CloseKey();
}
delete reg;
}