1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
int main()
{
HKEY hkey;
string extension=".002"; // file extension
string desc="my file type"; // file type description
string app="C:\\MyProgram.exe %1"; // Open with MyProgram.exe an pass filename as 1st argument (Probably)
string action="Open with my program";
string sub="\\shell\\";
string path=extension+
sub+
action+
"\\"
"command\\";
// 1: Create subkey for extension -> HKEY_CLASSES_ROOT\.002
if(RegCreateKeyEx(HKEY_CLASSES_ROOT,extension.c_str(),0,0,0,KEY_ALL_ACCESS,0,&hkey,0)!=ERROR_SUCCESS)
{
cerr <<"Could not create or open a registrty key\n";
return 1;
}
RegSetValueEx(hkey,"",0,REG_SZ,(BYTE*)desc.c_str(),sizeof(desc)); // default vlaue is description of file extension
RegCloseKey(hkey);
// 2: Create Subkeys for action ( "Open with my program" )
// HKEY_CLASSES_ROOT\.002\Shell\\open with my program\\command
if(RegCreateKeyEx(HKEY_CLASSES_ROOT,path.c_str(),0,0,0,KEY_ALL_ACCESS,0,&hkey,0)!=ERROR_SUCCESS)
{
cerr <<"Could not create or open a registrty key\n";
return 1;
}
RegSetValueEx(hkey,"",0,REG_SZ,(BYTE*)app.c_str(),app.length());
RegCloseKey(hkey);
return 0;
}
|