在DOC/VIEW结构登陆系统前要弹出出个对话框,但是都弹出了两遍。我拦截了N个消息函数都是如此,问.....

解决方案 »

  1.   

    我拦截了CMYView的PreCreatWnd,在程序一启动时就弹出了密码对话框,确定后又弹出了一遍
      

  2.   

    不但创建的时候会弹出两遍,就是在你销毁窗口的时候,也会弹出两遍-----假如你在destroywindow函数里也使用"messagebox()"的话.
      其实,view和mainframe都有各自的创建过程,这就是为什么你的对话筐弹出两次的原因
      你尝试在你的app类中实现你的功能,应该就可以了.
      

  3.   

    同意楼上.
    楼主应该找个只会执行一遍的地方初始化. APP类确实是最好的地方了. 在BOOL YouClass::InitInstance() 里弹出对话框判断, 如果不成功直接返回假, 程序就结束了.
      

  4.   

    MyClass::InitInstance()
    楼上能不能说清楚一点,这个InitInstance()函数到底属于哪个类的?如果用DOC/VIEW结构,放在MYVIEW肯定要弹两遍。我是想在DOC/VIEW结构程序里放一个拦截对话框,APP里怎么写啊?小弟现在还不会
      

  5.   

    你调试的时候,确实会发现它会两次调用的.应该在应用程序类的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;
      ....
    }