check the return code of CYourDocument::OnNewDocument()
//allow only one instance exist m_hOneInstance = ::CreateMutex(NULL,FALSE,UNIQE_NAME); if (GetLastError() == ERROR_ALREADY_EXISTS) { AfxMessageBox("PCT-32 already running!"); return FALSE; }// AfxOleInit(); AfxInitRichEdit(); AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need.#ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif // Change the registry key under which our settings are stored. // TODO: You should modify this string to be something appropriate // such as the name of your company or organization. SetRegistryKey(_T("PCT-32")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CProject3Doc), RUNTIME_CLASS(CMainFrame), // main SDI frame window RUNTIME_CLASS(CProject3View)); AddDocTemplate(pDocTemplate); // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE;
m_hOneInstance = ::CreateMutex(NULL,FALSE,UNIQE_NAME);
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
AfxMessageBox("PCT-32 already running!");
return FALSE;
}// AfxOleInit();
AfxInitRichEdit();
AfxEnableControlContainer(); // Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif // Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("PCT-32")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CProject3Doc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CProject3View));
AddDocTemplate(pDocTemplate); // Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
根本就没运行到这里来 -> CMyDocument::OnNewDocument()
我想我大概知道为什么了.
Resource->Dialog中,作为CMyActiveView(CFormView)模板的那个对话框VC认为损坏了.
其实没有,只是里面有个OCX控件它不认识.手工注册后就OK了.
至于为什么只有这一台机器不认识...我还不知道.
MyProject.exe发行版安装程序中有对该控件自动注册的,其他机器都没问题,就这台打不开,真怪.
CDocTemplate::CreateNewDocument和CDocTemplate::CreateNewFrame失败的话都会导致这个提示。在程序没有错误的情况下,除非内存不足,否则CDocTemplate::CreateNewDocument不太可能失败。CDocTemplate::CreateNewDocument new了一个Document,然后添加到CDocTemplate的文档列表里面)CDocTemplate::CreateNewFrame new了一个FrameWnd,调用了CFrameWnd::LoadFrame,而CFrameWnd::LoadFrame是可能失败的。FrameWnd在处理WM_CREATE的过程中失败就可能导致这种情况。通常的原因是CFrameWnd::CreateView失败。注册组件的时候,要注意组件的ProgID。为了安全起见,需要先撤销原有控件的注册,才能正常注册组件。