MFC run application by clicking on file...

This is a discussion on MFC run application by clicking on file... within the Windows Programming forums, part of the Platform Specific Boards category; hi there, i've written a pretty simple MFC application for viewing floating point tif images. basically, by doing file->open, i ...

  1. #1
    dug
    dug is offline
    Registered User dug's Avatar
    Join Date
    Jun 2003
    Posts
    66

    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.
    thanks.
    dug.
    "take the long road.... and walk it."

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,506
    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
    Location
    UK
    Posts
    169
    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
    Location
    California
    Posts
    3,246
    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 01:39 PM.

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

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

    Code:
    char* buff;
    char* command_line = GetCommandLine();
    
    buff = strchr(command_line, ' ');
    buff++;
    
    if (buff != NULL)
    {
    	pMainFrame->OpenFile(buff);
    }
    dug.
    Last edited by dug; 12-02-2004 at 04: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21