Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Assigning different Menu to the application based on login information Collapse All
Subject Author Date
Saroj Acharya May 2, 2005 - 11:13 AM

Hi Customer Support,


I have a MDI application. When it starts, it will have one menu where the user can just login, see About or Exit the application. However, when the user logs-in, I would like to assign a different Menus to the application based on his access rights. I had used the following lines of code in pure MFC application but it does not work with Prof-UIS. Could you pleaseme know what I should do to make it work:


Thanks,


Saroj


 


void CMainFrame::onApplicationLogin()


{


CUserLoginDlg dlgApplicationLogin;


CMenu AdminMenu;


if(dlgApplicationLogin.DoModal() == IDOK)


{


intLoginLevel = dlgApplicationLogin.GetAccessLevel();


switch(intLoginLevel)


{


case OPTIVIEW_USER_LEVEL1:


AdminMenu.LoadMenu(IDR_USER1_MENU);


SetMenu(&AdminMenu);


AdminMenu.Detach();


break;


case OPTIVIEW_ADMIN_LEVEL:


AdminMenu.LoadMenu(IDR_DRAWCLTYPE);


SetMenu(&AdminMenu);


AdminMenu.Detach();


break;


}


}


}

Technical Support May 3, 2005 - 8:58 AM

The source code you provided will work correctly only if the CWnd::SetMenu() method is called for the main frame window before the CExtMenuControlBar window is created. To provide you with advice or a solution, we need more details: Is your application MDI or SDI and whether the document view architecture is used? Is it customizable, i.e. whether the CExtCustomizeSite class is used in your project?

Saroj Acharya May 3, 2005 - 9:22 AM

Hi,


I have already created the menubar in OnCreate() function in the MainFrame window. So the menu is already created. And that time the menu is very simple one with not a whole lot of options. When the user logs-in, he will do so by selecting one of the menu option available at that time.


1.  My application is MDI modified from your DrawCLI sample application.


2.  CExtCustomizeSite is used in my application.


3.  Document view architecture is definitely used.


Please let me know if you need further information.


Regards,


Saroj


 

Technical Support May 4, 2005 - 7:55 AM

The application configuration used in your project allows you to implement any number of menu lines for any number of users easily. Your application initializes the instance of CExtCustomizeSite in CMainFrame::OnCreate() in which all the menu lines are registered by calling the CExtCustomizeSite::MenuInfoAdd() methods. You can add more invocations of this method to register any required number of menu lines for all user types. To make menu bar using appropriate named menu line, override the CExtCustomizeSite::MenuInfoFindForMenuBar() virtual method like as follows:

CExtCustomizeSite::CCmdMenuInfo *
    CMainFrame::MenuInfoFindForMenuBar()
{
    ASSERT( this != NULL );
    // if we are in the customize mode
CCmdMenuInfo * pMenuInfo =
        MenuInfoActiveGet();
    if( pMenuInfo != NULL )
        return pMenuInfo;
    // in other case we need to return
    // an appropriate menu line
    pMenuInfo =
        MenuInfoGetByName(
            _T("Appropriate Name")
            );
    return pMenuInfo;
}
Of course, this approach assumes your code knows names of all menus registered in the customize site and simply returns the menu info object which corresponds to the currently logged in user type.

Saroj Acharya May 5, 2005 - 10:40 AM

Hi,


I added the following lines of code in my OnCreate() function of MainFrame.cpp to add the menu resource. But I get an ASSERT at line #2666 of ExtCustomize.cpp file.


VERIFY(CExtCustomizeSite::MenuInfoAdd(this, _T("Default"), IDR_MAINFRAME, true, false, RUNTIME_CLASS(CMainFrame)) );


VERIFY(CExtCustomizeSite::MenuInfoAdd(this, _T("AdministratorMenu"), IDR_DRAWCLTYPE, false, false, RUNTIME_CLASS(CMDIChildWnd), RUNTIME_CLASS(CView), RUNTIME_CLASS(CDocument)) );


VERIFY(CExtCustomizeSite::MenuInfoAdd(this, _T("UserLevel1Menu"), IDR_USER1_MENU, false, false);


Please help me to get this problem resolved.


Saroj

Technical Support May 6, 2005 - 3:23 AM

This line gets a CMenu pointer from the HMENU handle corresponding to the loaded menu sub-level. This can happen only if something damages memory in your application. Does this assertion occur for this menu only? Could we take a look at your source code and help you find out what causes the problem?