Thread: MFC run application by clicking on file...

  1. #1
    Registered User dug's Avatar
    Join Date
    Jun 2003

    MFC run application by clicking on file...

    hi there,

    i've written a pretty simple MFC application for viewing floating point tif images. basically, by doing file->open, i create a child window that displays the image.

    what i want to do is to be able to associate these floating-point tiffs with my application, so that when i double click the file, it will run the application and open the file... at the moment it just runs the application but does not open the file.

    so, all i want to happen is when the file is double clicked and the application runs... is for the OnOpen() routine to be called the same as when the user does file->open from inside the application. if you know what i mean...?

    any suggestions would be greatly appreciated.
    "take the long road.... and walk it."

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Well there are various ways of associating a file type with a program.

    In XP, you just right-click on the file, choose "Open With..." and follow the dialogs to choose your program.

  3. #3
    Registered User
    Join Date
    Mar 2003
    In the WinApp::InitInstance() call GetCommandLine(), which returns a pointer to the command-line string for the current process. Load the file using the file name that’s contained within the 2nd set of quotes. e.g.:

    "C:\Program Files\MyApp.exe" "C:\Some Folder\Dragged.jpg"

  4. #4
    Registered User
    Join Date
    Sep 2004
    You add a registry key to HKEY_CLASSES_ROOT. More information here.

    Edit: oops, I misread the question. I thought you were asking how to associate a file with your program.
    Last edited by bithub; 12-01-2004 at 02:39 PM.

  5. #5
    Registered User dug's Avatar
    Join Date
    Jun 2003
    thanks scarlet!

    inside WinApp::InitInstance, here's what worked for me:

    char* buff;
    char* command_line = GetCommandLine();
    buff = strchr(command_line, ' ');
    if (buff != NULL)
    Last edited by dug; 12-02-2004 at 05:01 AM.
    "take the long road.... and walk it."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. Invoking MSWord
    By Donn in forum C Programming
    Replies: 21
    Last Post: 09-08-2001, 04:08 PM