5,696,038 members and growing! (14,315 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.
VC6, C++Windows, NT4, Win2K, MFC, Visual Studio, Dev

Posted: 22 Jun 2000
Updated: 22 Jun 2000
Views: 108,542
Bookmarked: 28 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
21 votes for this Article.
Popularity: 5.70 Rating: 4.31 out of 5
1 vote, 6.7%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
3 votes, 20.0%
4
11 votes, 73.3%
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



    Occupation: Web Developer
    Location: United States United States

    Other popular Shell and IE programming articles:

    Article Top
    Sign Up to vote for this article
    You must Sign In to use this message board.
    FAQ FAQ Noise ToleranceSearch Search Messages 
     Layout  Per page   
     Msgs 1 to 25 of 27 (Total in Forum: 27) (Refresh)FirstPrevNext
    QuestionOpen file errormemberRui Frazão7:51 26 Dec '06  
    GeneralDelphi applicationsmemberSyhon22:12 23 Nov '06  
    GeneralCool... now how do you receive the open command...memberM i s t e r L i s t e r13:53 16 Oct '06  
    GeneralSimple C# versionmembercristiscu10:14 21 Jul '06  
    QuestionRe: Simple C# versionmemberFrEaK_CH8:35 25 Sep '06  
    AnswerRe: Simple C# versionmembercristiscu16:27 26 Sep '06  
    GeneralLong files namesmemberKetinla1:21 26 Jan '06  
    Generalhow to check...membercreative0021:20 27 Nov '05  
    GeneralSetDocumentDefaultIconmemberehh8:49 15 Nov '05  
    GeneralRe: SetDocumentDefaultIconmemberBlake V. Miller10:06 24 Nov '05  
    GeneralThanks a lot...memberSreekanth Muralidharan20:07 13 Oct '05  
    GeneralHow to tell the explorer refresh the icon?memberMichael Leung2:36 24 Jul '05  
    GeneralRe: How to tell the explorer refresh the icon?memberpo.coulet3:51 14 Sep '05  
    GeneralRe: How to tell the explorer refresh the icon?memberMandrago3:44 10 Jul '07  
    GeneralMultiple Files TOgether ???membertot2ivn1:16 18 Feb '05  
    GeneralRe: Multiple Files TOgether ???memberBlake V. Miller17:12 24 Feb '05  
    GeneralRe: Multiple Files TOgether ???membertot2ivn18:47 24 Feb '05  
    GeneralAutomatically open document extension?memberAAntix0:00 11 Jan '05  
    GeneralRe: Automatically open document extension?memberBlake V. Miller18:20 18 Jan '05  
    Generalfile namesmemberbrian scott7:23 14 Apr '04  
    GeneralRe: file namesmemberBlake V. Miller18:11 18 Jan '05  
    GeneralRe: file namesmembercabaa9910:50 2 Aug '05  
    GeneralThe Next StepsmemberJohn Ulvr3:09 10 Apr '03  
    GeneralRe: The Next StepsmemberBlake V. Miller18:16 18 Jan '05  
    Generallong file name problemmemberAnonymous0:51 12 Mar '02  

    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-2008
    Web07 | Advertise on the Code Project