你调试的时候,确实会发现它会两次调用的.应该在应用程序类的InitInstance里面弹出对话框.#include "mypasswordDlg.h"BOOL CXXXApp::InitInstance() { 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("Local AppWizard-Generated Applications")); LoadStdProfileSettings(5); // Load standard INI file options (including MRU) CPassDlg dlg; if (dlg.DoModal() == IDOK) { 判断密码(); } else { return FALSE; }
// Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate; .... }
其实,view和mainframe都有各自的创建过程,这就是为什么你的对话筐弹出两次的原因
你尝试在你的app类中实现你的功能,应该就可以了.
楼主应该找个只会执行一遍的地方初始化. APP类确实是最好的地方了. 在BOOL YouClass::InitInstance() 里弹出对话框判断, 如果不成功直接返回假, 程序就结束了.
楼上能不能说清楚一点,这个InitInstance()函数到底属于哪个类的?如果用DOC/VIEW结构,放在MYVIEW肯定要弹两遍。我是想在DOC/VIEW结构程序里放一个拦截对话框,APP里怎么写啊?小弟现在还不会
{
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("Local AppWizard-Generated Applications")); LoadStdProfileSettings(5); // Load standard INI file options (including MRU)
CPassDlg dlg;
if (dlg.DoModal() == IDOK)
{
判断密码();
}
else
{
return FALSE;
}
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate;
....
}