|
-
October 28th, 2002, 03:30 PM
#1
associating file types with my program and more!
I know this has been answered before, but I am not sure how to search for it....
I want to associate a file type with my program, so that when the user double-clicks on a file of that type, my program runs and opens that file. In addition, I only want ONE instance of my app to run at a time. So, if my app is running, and the user double-clicks on the file, my app comes to the front and opens that file. My app is already MDI, so it can open multiple files at a time...
Can someone point me to an example?
thanx
-
October 28th, 2002, 07:52 PM
#2
There is an article, here on CG, about restricting your app to one instance. Search for "One instance application" to find it.
This article in MSDN describes how to do it in the registry.
"Creating a File Association"
I think you can register associations in the Doc/View architecture as well
-
October 28th, 2002, 09:37 PM
#3
In addition to Bill's answer...
1. Single instance
You need to create a named mutex semaphore when you start your application. When the second one starts it tries to get access to the mutex but will fail...
Code:
// app.h
class CYourApp : public CWinApp
{
...
private:
HANDLE hMutex;
};
// app.cpp
BOOL CYourApp::InitInstance()
{
// Create mutex
hMutex = ::CreateMutex(NULL, TRUE, "GlobalMutex");
switch(::GetLastError())
{
case ERROR_SUCCESS:
// Mutex created successfully. There is no instance running
break;
case ERROR_ALREADY_EXISTS:
// Mutex already exists so there is a running instance of our app.
return FALSE;
default:
// Failed to create mutex by unknown reason
return FALSE;
}
}
2. File association
Since I happen to have the mentioned article within my bookmarks...here is it....
-
October 28th, 2002, 10:30 PM
#4
Thanx everyone for all the help. Now that I can have only one instance of my MDI app running, when the user double-clicks on a file of the right type, I want my already running app to open that file in a new view. I am not sure I saw how to do that based on the readings in MSDN.
-
October 29th, 2002, 01:22 PM
#5
I don't know if this is the best way to do it, or not. The second instance could send a message to the first instance requesting the file to be opened by the first instance before the second instance exits.
-
October 29th, 2002, 02:21 PM
#6
Hmmmmmm, to tell the truth, I thought about that. Might work, but it is not a design I would want to show any of my old college professors 
I cannot believe that MS does not supply a cleaner way of doing this......
thanx
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|