How to Register Another File Type for an Application

Last reviewed: July 17, 1997
Article ID: Q102666
1.00 1.50 WINDOWS kbtool

The information in this article applies to:

  • The ClassWizard included with: Microsoft Visual C++ for Windows, versions 1.0 and 1.5

SUMMARY

If you do not associate a file extension with a document when you create an application in App Wizard 1.0, App Wizard does not generate any code to register the file extension. The text below presents the changes necessary to register a file extension in the Registration database.

To define the default file extension for an application, use App Studio to change the application's string resources. For example, change the following:

   IDR_APPTYPE =
   \nApp\nApp Document

to read as follows:

   IDR_APPTYPE =
   \nApp\App Document\n.APP Files (*.app)\n.app\nAppFileType\nAppFileType

This code is required for the document template when the application calls AddDocTemplate(). You must also add the following code to the InitInstance() function:

Sample Code

/*
 * Compiler options needed: None
 */

// Cut and paste from line 155 of APPUI.CPP into your source file,
// before the InitInstance() call.
//
static BOOL NEAR PASCAL SetRegKey(LPCSTR lpszKey, LPCSTR lpszValue) {
   if (::RegSetValue(HKEY_CLASSES_ROOT, lpszKey, REG_SZ, lpszValue,
          lstrlen(lpszValue)) != ERROR_SUCCESS)
      {
      TRACE1("Warning: registration database update failed for key
          '%Fs'\n", lpszKey);
      return FALSE;
      }

  return TRUE;
}

// Modify your InitInstance() definition to include the
// following code:

BOOL CAppApp::InitInstance() {
   // Standard Initialization
     .
     .
     .
   m_pMainWnd = pMainFrame;

   // Add the follow code.
   m_pMainWnd->DragAcceptFiles();
   EnableShellOpen();
   RegisterShellFileTypes();

   // Registration Type Name
   CString      strFileTypeName;

   // Position used if more than one document template.
   POSITION     pos;
   CDocTemplate *pTemplate =
      (CDocTemplate*)m_templateList.GetNext(pos);
   pTemplate->GetDocString(strFileTypeName,
      CDocTemplate::regFileTypeName);

   // Add another file extension to registration database.
   // If you double-click a .APP or .SAV file in File Manager it
   // automatically starts this application.
   //
   // SetRegKey adds a file extension to the Registration Database
   ((void)SetRegKey(".sav", strFileTypeName);

   // create a new (empty) document)
   OnFileNew();
     .
     .
     .
   return TRUE;
}

MORE INFORMATION

In Visual C++ for Windows, version 1.5, if you create a project using App Wizard the code to register a file extension in the Registration database may be automatically generated by performing the following steps:

  1. Choose AppWizard from the Project menu to create a new project.

  2. Type in the Project Name.

  3. Click on the Classes button in the MFC AppWizard dialog box.

  4. Click on and select the document class to be created from the New Application Classes (the document class typically ends with doc).

  5. The new File Extension and Doc Type Name boxes should be displayed with suggested text in the Doc Type Name box.

  6. Fill in your file extension and doc type name.

    NOTE: If you do not enter any text in the file extensions box the code to register your file extension in the Registration database will NOT be automatically generated.

  7. Click OK.

  8. Click OK.

  9. Review the New Application Information and click Create to generate your application.


Additional reference words: kbinf 1.00 1.50 no32bit noupdate
KBCategory: kbtool
KBSubcategory: WizardIss
Keywords : kb16bitonly WizardIss kbtool
Version : 1.00 1.50
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.