Problem in opening document through double clicking!
The document file of my application is being opened successfully when opened through the File Open command of application and when opened through drag and drop method; but the same document is not being opened on double clicking it frm My Computer or Windows Explorer. When we double click the document, application starts but fails to open the document. What could be the possible reason for this failure of opening document through double clicking method, while other methods are opening document successfully?
[512 byte] By [
anwar4849] at [2007-11-20 11:04:32]

# 1 Re: Problem in opening document through double clicking!
I have been trying to solve this problem for years.
I believe that it has to do with the Registry entries for the particular file type that your application has registered as it's own.
For example, let us say that your app has registered the file type 'MTX' which is presumeably unique and has not been previously registered - that is, set in the Registry of a particular machine the very first time that it is run on that machine.
Open the Registry directory HKEY_CLASSES_ROOT. There you will find a listing of all the file types. Under most of these, you will find something like the following:
PersistentHandler
{098f2470-bae0-11cd-b579-08002b30bfeb} (a UID)
or
OpenWithList
mplayer2.exe
wmplayer.exe
or
ShellNew
FileName name.mtx
Now, where you run into problems is if you have registered that file type previously on your machine, then removed the original file and tried to re-register it with a new application (which often occurs in the process of development, at least the way I approach it).
So the real questions are:
1 - What does that unique identifer (UID) cross-reference?
2 - How does the operating system associate that UID with a particular application?
3 - How can one programatically change the UID to match the desired application?
4 - What is the proper Registry enty required to create an Operating System or Shell link?
5 - Do certain interfaces such as SDI with RichEditView require special handling in this regard?
Now, in addition, in the same Registry directory, below the file types section, there is a section dealing with registered applications.
Let us say that the application that is supposed to use the documents of type .mtx is called MtxApp. Provided that the file type was registered by this app, you should find an entry like:
MtxApp.Document MtxApp.Document
DefaultIcon
Shell
Open
Command
under the command heading you might find something like:
C:\DOCUME~1\jblow\MYDOCU~1\VC7~1.0\MTXAPP\MA439C~1\Release\MtxApp.exe "%1"
I believe that here is the key to clicking on your file document and getting it to load and run MtxApp.exe. As you indicate, you must properly serialize the loading of the document. This implies that you cannot do this unless you utilize the Doc-View architecture.
Well, that's what I know about it - but I still can't control it.
If any of you gurus out there have ansers to these questions, I am certain meny of the followers of this forum will be grateful.
Mike :)
# 2 Re: Problem in opening document through double clicking!
If your application opens when double-clicking the file it's most likely not a registry problem. VisualStudio's app wizard puts code in InitInstance() that looks something like this (VS6):
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
Is this code in your InitInstance()? Has it been modified in any way? I would suggest putting a break point after ParseCommandLine() and then examine the cmdLine object in the debugger. m_nShellCommand should be FileOpen and m_strFileName should contain the name of the file that you double-clicked on.
# 3 Re: Problem in opening document through double clicking!
I've tried all of the above without success.
My SDI app with a CRichEditView view and serialization of the registered file type. It has a registered file type 'MTX' and a ProgID 'MatCalc.Document' in the HKEY_CLASSES_ROOT registry.
The same program, run in Win2k and WinXPPro environments (different machines) acts differently.
Drag and drop sort of works in Win2k. Dragging an MTX file onto the window results in a framed picture of the file icon which, when double-clicked, will load the data into the view window as it is supposed to. Also, double-clicking on the Windows Explorer file icon results in the data being loaded properly, however, the application must be running, otherwise it errors and complains that it can't find the file that was just clicked.
Not so with the same app on the WinXPPro machine. Dragging an MTX file onto the screen provides a framed image of the file icon, but double clicking on the framed icon results in an error. Debugging the application at this point suggests that the break point is at the line : GetActiveView() in the Doc Serialize method.
else
{
ar >> m_fval;
m_nrows = (long)m_fval;
ar >> m_fval;
m_ncols = (long)m_fval;
M.newsize(m_nrows, m_ncols);
for(int i=1;i<=m_nrows;i++) {
for(int j=1;j<=m_ncols;j++) {
ar >> M(i,j);
}
}
CMainFrame *pmf = (CMainFrame*)AfxGetApp()->m_pMainWnd;
CMatCalcView * pView = (CMatCalcView*) pmf->GetActiveView();
Whether or not m_bRTF = FALSE; or not does not seem to make any difference in this behaviour.
I am very frustrated and puzzled by the lack of clear information on this subject.
Any ideas how to fix this problem or what may be the matter ?
Thanks.
Mike :confused:
# 4 Re: Problem in opening document through double clicking!
Another problem: The same application run on Windows Vista Ultimate appears to run OK but Drag and Drop and Shell click on Explorer file icon fails to work -- and there is no Registry entry in HKEY_CLASSES_ROOT for the ProgID which should be MatCalc.Document.
Go Figure. :confused:
# 5 Re: Problem in opening document through double clicking!
Interesting.
Pertaining Vista, have you run the application at least once as an administrator.
The wierd thing about the application is, it registers the document extension as part of InitInstance and the registries it touches might be protected. On Vista, with UAC enabled, this will require elevation. So, unless your application is run at least once with elevated privileges, those registry entries will never get in to the registry. ( Ideally, this first time thing should be part of installer . I am not sure if the VS2008's version of MFC would have done something about this )