小弟是新手,现在在做一个登陆界面,
现在问题是,登陆的用户有不同身份,类似管理员和普通用户,
要把登陆界面放到哪里,才能在程序启动的时候,先启动登陆界面,
然后,在通过登陆的用户,来调用相关的窗口??麻烦各位大大们,给个方案啊,我是个菜鸟,麻烦讲解的时候,能说明是再那个函数中。万分感谢

解决方案 »

  1.   

    在 BOOL xxxxApp::InitInstance() 函数中显示登录界面
     
        
    CDiglogin dlg; //登陆对话框
    m_pMainWnd = &dlg;
    int nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {
                //okay 用户点击了“登陆“按钮,进行验证(包括密码 权限等)
                 if 验证成功 
                    //打开主界面
                 else
                   //验证失败
                    return FALSE;//关闭程序
          
    }
    else if (nResponse == IDCANCEL)
    {
               //用户点击的是取消 按钮
                //直接关闭程序
                return FALSE;
    }
     然后在主界面的初始化事件里根据权限动态显示权限菜单。
     
      

  2.   

    主界面就是看你的对话框等实现,如果是对话框,那么就DoModal打开
      

  3.   

    单文档格式的也是在 BOOL xxxxApp::InitInstance() 函数中显示登录界面BOOL CMFCCFormViewApp::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();  // 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(CMFCCFormViewDoc),
    RUNTIME_CLASS(CMainFrame),       // main SDI frame window
    RUNTIME_CLASS(CMFCCFormViewView));
    AddDocTemplate(pDocTemplate); // Parse command line for standard shell commands, DDE, file open
    CCommandLineInfo cmdInfo;
    ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line

    //登陆对话框
    CDigLogin dlg; //登陆对话框
        int nResponse = dlg.DoModal();
    if (nResponse == IDOK)
        {
                //okay 用户点击了“登陆“按钮,进行验证(包括密码 权限等)
                 if (1) //验证成功 
     {
    if (!ProcessShellCommand(cmdInfo))
    return FALSE;
                    m_pMainWnd->ShowWindow(SW_SHOW);
    m_pMainWnd->UpdateWindow();
     }
                 else
                   //验证失败
                    return FALSE;//关闭程序
                  
        }
        else if (nResponse == IDCANCEL)
        {
               //用户点击的是取消 按钮
                //直接关闭程序
                return FALSE;
        } return TRUE;
    }