Solved

Disabling menu item

Posted on 2004-10-22
211 Views
Last Modified: 2013-11-20
Dear fiends,

I added one new menu item for for standard SDI application. I am opening one dialog window, if i click that menu item. I would like disable that menu item, if i opens dialog window. How can i do this. Please help me.

Thanking you

Vihar123
0
Question by:vihar123
    9 Comments
     
    LVL 55

    Accepted Solution

    by:
    You must have a flag to indicate if dialog is opened, this flag must be cleared when dialog is closed.
    Then you have to create a handler for the dialog item using the ClassWizard (Ctrl-W), select your app class, and the identifier of the menu option. Create an UPDATE_COMMAND_UI  event for this identifier. Will generate a function like:

    void CYourApp::OnUpdateYourOption(CCmdUI* pCmdUI)
    {
          pCmdUI->Enable(m_YourFlag ? FALSE : TRUE);   // Is dialog open?
    }
    0
     
    LVL 30

    Expert Comment

    by:Zoppo
    Or, if you have access to the dialog, i.e. via pointer, you can simply use CWnd::IsWindowVisible() instead of using a flag ...
    0
     

    Author Comment

    by:vihar123
    Thank you for your reply. The above tip is quite working well. But the problem is, once i close the dialog i can not open the dialog again . i have to retstart the complete application. Please give me solution.

    Thanking you,
    vihar123
    0
     
    LVL 30

    Expert Comment

    by:Zoppo
    hm ... seems as if you didn't reset the flag when dialog closed ... therefore I meant IsWindowVisible to be the better way because you don't need to care about such a flag ...
    0
     

    Author Comment

    by:vihar123
    Thank you for your reply. And i am sorry to  ask you again. I did't reset the flag while closing dialog. Because i was unble to access the flag variable in Dialog class. And i could't under stand to use CWnd::IsWindowVisible() method. please look into this.

    Thanking you
    Vihar123
    0
     
    LVL 30

    Expert Comment

    by:Zoppo
    Well, it's easy if you can somehow make the dialog accessible in the class in which you implemented the ::OnUpdate...(CCmdUI* pCmdUI).

    This depends on how the dialog is implemented, so I can only show how I would do it (BTW, I assume it's a modeless dialog):

    In the CWinApp derived class I would add a pointer to an instance of my dialog, i.e.:

    class CMyApp : public CWinApp
    {
     CDialog* m_pMyDlg; // you can even use the class of the dialog you have if you need it, but for this approach we don't need it ...
     ...
    }

    // in CMyApp constructor we create the instance, i.e.
    CMyApp::CMyApp()
    {
     ...
     m_pMyDlg = new CMyDialog;
     ...
    }

    // then here's the menu-item's update handle
    void CMyApp::OnUpdateMyDialogMenu( CCmdUI* pCmdUI )
    {
     BOOL bVisible = ( NULL != m_pMyDlg && NULL != m_pMyDlg->m_hWnd && FALSE != ::IsWindow( m_pMyDlg->m_hWnd ) && FALSE != m_pMyDlg->IsWindowVisible );

     pCmdUI->Enable( bVisible );
    }

    // then you can create the dialog as usual with Create, i.e.
    ...
    CMyApp* pApp = (CMyApp*)AfxGetApp();
    pApp->m_pMyDlg->Create(...);
    pApp->m_pMyDlg->ShowWindow( SW_SHOW );
    ...



    ZOPPO
    0
     

    Author Comment

    by:vihar123
    Thank you for your reply. I could't able to follow the above method. Please tell me how can i reset my flag while closing the window. I think i have to send my own message while closing. How can i proceed for this.

    Thanking you. Looking forward for your reply.

    Vihar
    0
     
    LVL 30

    Expert Comment

    by:Zoppo
    Well, the method I mentioned above doesn't use such a flag, so there's no need to set/reset one ...

    It's hard to say more exactly what you should do since I don't know anything about how you implemented what you have ...
    0
     

    Author Comment

    by:vihar123
    Thank you for your reply. I implemented this by sending own message at the time of closing dialog.

    Vihar123
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Suggested Solutions

    Title # Comments Views Activity
    Importing  SSL Certificate into Firefox using GPO 28 167
    Running shell command from Access 3 55
    Host to IP 7 58
    FizzBuzz challenge 9 54
    This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
    Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

    856 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now