How to Register Another File Type for an ApplicationID: Q102666
|
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:
/*
* 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;
}
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:
Additional query words: kbinf 1.00 1.50 no32bit
Keywords : kb16bitonly kbwizard kbMFC kbVC
Version : 1.00 1.50
Platform : WINDOWS
Issue type :
Last Reviewed: August 8, 1999