Re: File Association in Dialog-Based Application
"Tom Serface" <tom.nospam@camaswood.com> wrote in message
news:180CBCDD-725B-4E44-9D08-268B8A7E13B9@microsoft.com...
One "modern" problem is that some users don't have access to this part of
the registry these days since it usually requires administrator
privileges. We've taken to adding these things in our setup programs
because those are typically run administrators anyway. Even the main code
in MFC fails for many applications, you just don't see it because it fails
elegantly (just doesn't always work as expected).
I wasn't aware that the MFC code often fails. But these are exactly the
types of concerns that were coming up when I thought about this.
I think this may be better under Vista because I think the associations
there are under HKCU rather than HKCR.
So existing association-relationship is not compatible under Vista?
If it were me, I'd just write a small routine to add the associations in
myself.
Here's some code I use, but it hasn't been updated for Vista and assumes
administrator privileges for at least one running of my program:
Thanks. I'll have to look into the Vista issues further.
Oh, and what is Registry in the code below? Is that one of your own classes?
void CMyApp::AddXXXRegistryType(void)
{
Registry qdReg(HKEY_CLASSES_ROOT, _T(".xxx"),true,false);
Registry qdRegMyKey(HKEY_CLASSES_ROOT,_T("MyApp.MyKey"),true,false);
Registry
qdRegDefaultIcon(HKEY_CLASSES_ROOT,_T("MyApp.MyKey\\DefaultIcon"),true,false);
Registry
qdRegShellCommand(HKEY_CLASSES_ROOT,_T("MyApp.MyKey\\Shell\\Open\\Command"),true,false);
CString csProgramPath, csDefaultIcon, csCommand;
AfxGetModuleShortFileName(AfxGetInstanceHandle(), csProgramPath);
csDefaultIcon = csProgramPath + _T(",28"); // Index of icon in EXE
csCommand = csProgramPath + _T(" \"%1\"");
if (qdReg.IsValidKey()) {
bool bSuccess = qdReg.SetString(_T(""), _T("MyApp.MyKey"));
bSuccess = qdRegMyKey.SetString(_T(""),_T("MyApp.MyKey));
bSuccess = qdRegMyKey.SetInt(_T("EditFlags"),0);
bSuccess = qdRegDefaultIcon.SetString(_T(""),csDefaultIcon);
bSuccess = qdRegShellCommand.SetString(_T(""),csCommand);
}
else
LogEvent("HKEY_CLASSES_ROOT\\.xxx reg key not valid");
}
Tom
"Jonathan Wood" <jwood@softcircuits.com> wrote in message
news:uBAcXjtNJHA.588@TK2MSFTNGP06.phx.gbl...
Has anyone seen any info on how to associated a file type with my
dialog-based application?
In order to use RegisterShellFileTypes(), I must add my document template
using AddDocTemplates(). But AddDocTemplates() can't be called without a
CDocument class.
Thanks for any thoughts.
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com