Click here to Skip to main content
11,409,138 members (49,948 online)
Click here to Skip to main content

Associate File Extension with Shell OPEN command and Application

, 22 Jun 2000
Rate this:
Please Sign up or sign in to vote.
Registry entries and MFC class that associates a file extension with a program.
<!-- Download Links -->
  • Download source files - 3 Kb
  • Download demo project - 17 Kb
  • <!-- Main HTML starts here -->


    This source contains a class CGCFileTypeAccess that can associate a file extension with a program.

    The association allows a new instance of the program to be activated when the icon is clicked upon in the Windows Explorer window. The full file path to the file will be sent to the program on the command line.

    The Open command also appears on the shell context menu for the file type. Selection of the open command from the context menu sends the file on the command line to a new instance of the program.

    An example of associating a file extension using the class would be done as follows, and can be found in the InitInstance of the demo program:

    CGCFileTypeAccess TheFTA;
    // get full file path to program executable file
    TCHAR	szProgPath[MAX_PATH * 2];
    ::GetModuleFileName(NULL, szProgPath, sizeof(szProgPath)/sizeof(TCHAR));
    CString csTempText;
    // just pass file path in quotes on command line
    csTempText  = szProgPath;
    csTempText += " \"%1\"";
    // use first icon in program
    csTempText  = szProgPath;
    csTempText += ",0";
    // set the necessary registry entries	

    The relevant registry entries are all under HKEY_CLASSES_ROOT. The two primary root keys are .'FileExtension' and 'Document Class Name'. Keys and values underneath these two primary keys control the file association and the shell open command.

    The demo program will execute the file association code listed above. After it has been run at least once, each time you 'open' one of the associated file types, the program will display the file path from the command line in a message box.


    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    About the Author

    Blake V. Miller
    Web Developer
    United States United States
    No Biography provided

    Comments and Discussions

    QuestionError Access Denied? Pinmemberbosfan10-Jul-13 1:27 
    QuestionGet path of a file clicked upon in windows explorer. PinmemberMahdi Nejadsahebi14-Nov-12 22:22 
    GeneralMy vote of 5 PinmemberMahdi Nejadsahebi14-Nov-12 22:09 
    Questionwin7 PinmemberMember 80653888-Dec-11 0:17 
    QuestionHow to change the default icon index Pinmemberkrishnakumartm27-Jun-11 1:22 
    GeneralDoesn't work Pinmemberdpreznik12-May-11 5:01 
    GeneralDoes not work if the user has specified another default application Pinmemberdragomir5-Mar-09 7:20 
    QuestionOpen file error PinmemberRui Frazão26-Dec-06 7:51 
    GeneralDelphi applications PinmemberSyhon23-Nov-06 22:12 
    GeneralCool... now how do you receive the open command... PinmemberM i s t e r L i s t e r16-Oct-06 13:53 
    GeneralRe: Cool... now how do you receive the open command... PinmemberBadJerry2-Sep-09 1:04 
    GeneralSimple C# version Pinmembercristiscu21-Jul-06 10:14 
    QuestionRe: Simple C# version PinmemberFrEaK_CH25-Sep-06 8:35 
    AnswerRe: Simple C# version Pinmembercristiscu26-Sep-06 16:27 
    GeneralLong files names PinmemberKetinla26-Jan-06 1:21 
    Questionhow to check... Pinmembercreative0027-Nov-05 21:20 
    GeneralSetDocumentDefaultIcon Pinmemberehh15-Nov-05 8:49 
    GeneralRe: SetDocumentDefaultIcon PinmemberBlake V. Miller24-Nov-05 10:06 
    GeneralThanks a lot... PinmemberSreekanth Muralidharan13-Oct-05 20:07 
    QuestionHow to tell the explorer refresh the icon? PinmemberMichael Leung24-Jul-05 2:36 
    AnswerRe: How to tell the explorer refresh the icon? Pinmemberpo.coulet14-Sep-05 3:51 
    GeneralRe: How to tell the explorer refresh the icon? PinmemberMandrago10-Jul-07 3:44 
    GeneralRe: How to tell the explorer refresh the icon? Pinmembervigylant18-Jan-09 8:46 
    QuestionMultiple Files TOgether ??? Pinmembertot2ivn18-Feb-05 1:16 
    AnswerRe: Multiple Files TOgether ??? PinmemberBlake V. Miller24-Feb-05 17:12 
    GeneralRe: Multiple Files TOgether ??? Pinmembertot2ivn24-Feb-05 18:47 
    QuestionAutomatically open document extension? PinmemberAAntix11-Jan-05 0:00 
    AnswerRe: Automatically open document extension? PinmemberBlake V. Miller18-Jan-05 18:20 
    Generalfile names Pinmemberbrian scott14-Apr-04 7:23 
    GeneralRe: file names PinmemberBlake V. Miller18-Jan-05 18:11 
    GeneralRe: file names Pinmembercabaa992-Aug-05 10:50 
    GeneralThe Next Steps PinmemberJohn Ulvr10-Apr-03 3:09 
    GeneralRe: The Next Steps PinmemberBlake V. Miller18-Jan-05 18:16 
    Generallong file name problem PinmemberAnonymous12-Mar-02 0:51 
    GeneralRe: long file name problem PinmemberBlake V. Miller18-Jan-05 18:18 
    GeneralRe: long file name problem PinmemberSreekanth Muralidharan28-Nov-05 18:33 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    | Advertise | Privacy | Terms of Use | Mobile
    Web01 | 2.8.150414.5 | Last Updated 23 Jun 2000
    Article Copyright 2000 by Blake V. Miller
    Everything else Copyright © CodeProject, 1999-2015
    Layout: fixed | fluid