Link to home
Start Free TrialLog in
Avatar of sunshine737
sunshine737

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Zoppo
Or, if you have access to the dialog, i.e. via pointer, you can simply use CWnd::IsWindowVisible() instead of using a flag ...
Avatar of sunshine737
sunshine737

ASKER

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

Vihar123