agreeBOOL CMyApp::InitInstance() { // ... CMultiDocTemplate* pDocTemplate; pDocTemplate = new CMultiDocTemplate( IDR_MYTYPE, RUNTIME_CLASS(CMyDoc), RUNTIME_CLASS(CMDIChildWnd), // standard MDI child frame RUNTIME_CLASS(CMyView)); AddDocTemplate(pDocTemplate); // Create main MDI Frame window. CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; // Save the pointer to the main frame window. This is the // only way the framework will have knowledge of what the // main frame window is. m_pMainWnd = pMainFrame; // enable file manager drag/drop and DDE Execute open EnableShellOpen(); RegisterShellFileTypes(); // ... // Show the main window using the nCmdShow parameter // passed to the application when it was first launched. pMainFrame->ShowWindow(m_nCmdShow); pMainFrame->UpdateWindow();
// ... }
char *sKeyName = "MyApp"; char *sKeyValue = "My Application" long lphKey; int ret = RegCreateKey( HKEY_CLASSES_ROOT, sKeyName, lphKey ); ret = RegSetValue( lphKey, "", REG_SZ, sKeyValue, 0 );
; 此 .REG 文件可由你的应用程序的安装程序(setup)使用。
; 也可以用
; CWinApp::RegisterShellFileTypes 和 COleObjectFactory::UpdateRegistryAll
; 在 InitInstance 中对下列项自动进行注册。
; t0是文件扩展名
; ttt是程序名
HKEY_CLASSES_ROOT\.t0 = 文档类型ID
HKEY_CLASSES_ROOT\ttt.Documenttid\shell\open\command = ttt.EXE %1
HKEY_CLASSES_ROOT\ttt.Documenttid\shell\open\ddeexec = [open("%1")]
HKEY_CLASSES_ROOT\ttt.Documenttid\shell\open\ddeexec\application = ttt
; 注意:此应用程序是可选的
;(默认为“命令”中的应用程序名)
HKEY_CLASSES_ROOT\ttt.Documenttid = 文档类型全称[HKEY_CLASSES_ROOT\ttt.Documenttid\DefaultIcon]
@="e:\\ttt.exe,1"
{
// ... CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_MYTYPE,
RUNTIME_CLASS(CMyDoc),
RUNTIME_CLASS(CMDIChildWnd), // standard MDI child frame
RUNTIME_CLASS(CMyView));
AddDocTemplate(pDocTemplate); // Create main MDI Frame window.
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
// Save the pointer to the main frame window. This is the
// only way the framework will have knowledge of what the
// main frame window is.
m_pMainWnd = pMainFrame; // enable file manager drag/drop and DDE Execute open
EnableShellOpen();
RegisterShellFileTypes();
// ... // Show the main window using the nCmdShow parameter
// passed to the application when it was first launched.
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
// ...
}
char *sKeyValue = "My Application"
long lphKey;
int ret = RegCreateKey( HKEY_CLASSES_ROOT, sKeyName, lphKey );
ret = RegSetValue( lphKey, "", REG_SZ, sKeyValue, 0 );