Skip to main content
Email Password   helpLost your password?
  • 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.

    You must Sign In to use this message board.
     
     
    Per page   
     FirstPrevNext
    GeneralDoes not work if the user has specified another default application Pin
    dragomir
    7:20 5 Mar '09  
    QuestionOpen file error Pin
    Rui Frazão
    7:51 26 Dec '06  
    GeneralDelphi applications Pin
    Syhon
    22:12 23 Nov '06  
    GeneralCool... now how do you receive the open command... Pin
    M i s t e r L i s t e r
    13:53 16 Oct '06  
    GeneralRe: Cool... now how do you receive the open command... Pin
    BadJerry
    1:04 2 Sep '09  
    GeneralSimple C# version Pin
    cristiscu
    10:14 21 Jul '06  
    QuestionRe: Simple C# version Pin
    FrEaK_CH
    8:35 25 Sep '06  
    AnswerRe: Simple C# version Pin
    cristiscu
    16:27 26 Sep '06  
    GeneralLong files names Pin
    Ketinla
    1:21 26 Jan '06  
    Generalhow to check... Pin
    creative00
    21:20 27 Nov '05  
    GeneralSetDocumentDefaultIcon Pin
    ehh
    8:49 15 Nov '05  
    GeneralRe: SetDocumentDefaultIcon Pin
    Blake V. Miller
    10:06 24 Nov '05  
    GeneralThanks a lot... Pin
    Sreekanth Muralidharan
    20:07 13 Oct '05  
    GeneralHow to tell the explorer refresh the icon? Pin
    Michael Leung
    2:36 24 Jul '05  
    GeneralRe: How to tell the explorer refresh the icon? Pin
    po.coulet
    3:51 14 Sep '05  
    GeneralRe: How to tell the explorer refresh the icon? Pin
    Mandrago
    3:44 10 Jul '07  
    GeneralRe: How to tell the explorer refresh the icon? Pin
    vigylant
    8:46 18 Jan '09  
    GeneralMultiple Files TOgether ??? Pin
    tot2ivn
    1:16 18 Feb '05  
    GeneralRe: Multiple Files TOgether ??? Pin
    Blake V. Miller
    17:12 24 Feb '05  
    GeneralRe: Multiple Files TOgether ??? Pin
    tot2ivn
    18:47 24 Feb '05  
    GeneralAutomatically open document extension? Pin
    AAntix
    0:00 11 Jan '05  
    GeneralRe: Automatically open document extension? Pin
    Blake V. Miller
    18:20 18 Jan '05  
    Generalfile names Pin
    brian scott
    7:23 14 Apr '04  
    GeneralRe: file names Pin
    Blake V. Miller
    18:11 18 Jan '05  
    GeneralRe: file names Pin
    cabaa99
    10:50 2 Aug '05  


    Last Updated 22 Jun 2000 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009