Click here to Skip to main content
6,595,854 members and growing! (17,736 online)
Email Password   helpLost your password?
Desktop Development » Shell and IE programming » General     Intermediate

Associate File Extension with Shell OPEN command and Application

By Blake V. Miller

Registry entries and MFC class that associates a file extension with a program.
VC6Win2K, MFC, Dev
Posted:22 Jun 2000
Views:127,635
Bookmarked:36 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
20 votes for this article.
Popularity: 6.17 Rating: 4.74 out of 5

1

2

3
3 votes, 21.4%
4
11 votes, 78.6%
5
  • Download source files - 3 Kb
  • Download demo project - 17 Kb
  • Introduction

    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;
    
    TheFTA.SetExtension("CGFILETYPETEST");
    
    // just pass file path in quotes on command line
    
    csTempText  = szProgPath;
    csTempText += " \"%1\"";
    TheFTA.SetShellOpenCommand(csTempText);
    TheFTA.SetDocumentShellOpenCommand(csTempText);
    
    TheFTA.SetDocumentClassName("CGFileType.Document");
    
    // use first icon in program
    
    csTempText  = szProgPath;
    csTempText += ",0";
    TheFTA.SetDocumentDefaultIcon(csTempText);
    
    // set the necessary registry entries	
    
    TheFTA.RegSetAllInfo();
    

    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.

    License

    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


    Member

    Occupation: Web Developer
    Location: United States United States

    Other popular Shell and IE programming articles:

    Article Top
    You must Sign In to use this message board.
    FAQ FAQ 
     
    Noise Tolerance  Layout  Per page   
     Msgs 1 to 25 of 30 (Total in Forum: 30) (Refresh)FirstPrevNext
    GeneralDoes not work if the user has specified another default application Pinmemberdragomir7:20 5 Mar '09  
    QuestionOpen file error PinmemberRui Frazão7:51 26 Dec '06  
    GeneralDelphi applications PinmemberSyhon22:12 23 Nov '06  
    GeneralCool... now how do you receive the open command... PinmemberM i s t e r L i s t e r13:53 16 Oct '06  
    GeneralRe: Cool... now how do you receive the open command... PinmemberBadJerry1:04 2 Sep '09  
    GeneralSimple C# version Pinmembercristiscu10:14 21 Jul '06  
    QuestionRe: Simple C# version PinmemberFrEaK_CH8:35 25 Sep '06  
    AnswerRe: Simple C# version Pinmembercristiscu16:27 26 Sep '06  
    GeneralLong files names PinmemberKetinla1:21 26 Jan '06  
    Generalhow to check... Pinmembercreative0021:20 27 Nov '05  
    GeneralSetDocumentDefaultIcon Pinmemberehh8:49 15 Nov '05  
    GeneralRe: SetDocumentDefaultIcon PinmemberBlake V. Miller10:06 24 Nov '05  
    GeneralThanks a lot... PinmemberSreekanth Muralidharan20:07 13 Oct '05  
    GeneralHow to tell the explorer refresh the icon? PinmemberMichael Leung2:36 24 Jul '05  
    GeneralRe: How to tell the explorer refresh the icon? Pinmemberpo.coulet3:51 14 Sep '05  
    GeneralRe: How to tell the explorer refresh the icon? PinmemberMandrago3:44 10 Jul '07  
    GeneralRe: How to tell the explorer refresh the icon? Pinmembervigylant8:46 18 Jan '09  
    GeneralMultiple Files TOgether ??? Pinmembertot2ivn1:16 18 Feb '05  
    GeneralRe: Multiple Files TOgether ??? PinmemberBlake V. Miller17:12 24 Feb '05  
    GeneralRe: Multiple Files TOgether ??? Pinmembertot2ivn18:47 24 Feb '05  
    GeneralAutomatically open document extension? PinmemberAAntix0:00 11 Jan '05  
    GeneralRe: Automatically open document extension? PinmemberBlake V. Miller18:20 18 Jan '05  
    Generalfile names Pinmemberbrian scott7:23 14 Apr '04  
    GeneralRe: file names PinmemberBlake V. Miller18:11 18 Jan '05  
    GeneralRe: file names Pinmembercabaa9910:50 2 Aug '05  

    General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    PermaLink | Privacy | Terms of Use
    Last Updated: 22 Jun 2000
    Editor: Chris Maunder
    Copyright 2000 by Blake V. Miller
    Everything else Copyright © CodeProject, 1999-2009
    Web15 | Advertise on the Code Project