Disabling menu item

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
vihar123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jaime OlivaresSoftware ArchitectCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ZoppoCommented:
Or, if you have access to the dialog, i.e. via pointer, you can simply use CWnd::IsWindowVisible() instead of using a flag ...
0
vihar123Author Commented:
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
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

ZoppoCommented:
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
vihar123Author Commented:
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
ZoppoCommented:
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
vihar123Author Commented:
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
ZoppoCommented:
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
vihar123Author Commented:
Thank you for your reply. I implemented this by sending own message at the time of closing dialog.

Vihar123
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.