Home > Back-end >  Code for Windows 7 or under doing, file associations
Code for Windows 7 or under doing, file associations

Time:10-09

This is the code under XP, under Win78 is useless,
Who give a support Win78 code, thank you, as long as the code, not theory, thank you)

 bool __stdcall WriteStringToReg (hkeys Root, AnsiString Key, AnsiString KeyName, AnsiString KeyValue) 
{
Bool OK=false;
TRegistry * Registry=new TRegistry ();
Registry - & gt; RootKey=Root;
If (Registry - & gt; OpenKey (Key, true)) {
Try {
Registry - & gt; WriteString (KeyName, KeyValue);
OK=true;
}
The catch (... ) {
}
}
Delete the Registry;
Return OK;
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Bool __stdcall RegFileType (AnsiString Ext,//extension, such as: "dyc"
AnsiString ExtTypeName,//file types, such as: "dyc file
"AnsiString AppFileName,//application name, such as "c: \ \ dyc exe"
AnsiString FileDescription,//file type description, such as: "dyc documents
"Int IconIndex)//icon indexes, such as 0
{
Bool RegOK;
RegOK=WriteStringToReg (HKEY_CLASSES_ROOT \ \ "" + Ext," ", ExtTypeName);
If (AppFileName. Pos (" ") & gt; 0 {
AppFileName="" "+ AppFileName +" \ "";
}
If (RegOK) {
RegOK=WriteStringToReg (HKEY_CLASSES_ROOT \ \ "" + ExtTypeName," ", FileDescription);
}
If (RegOK) {
RegOK=WriteStringToReg (HKEY_CLASSES_ROOT \ \ "" + ExtTypeName +" \ \ DefaultIcon ", "", AppFileName +", "+ IntToStr (IconIndex));
}
If (RegOK) {
RegOK=WriteStringToReg (HKEY_CLASSES_ROOT \ \ "" + ExtTypeName + \ \ Shell \ " Open \ \ command ", "", AppFileName +" \ "% 1 " ");
}
Return RegOK;
}
  • Related