[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

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
0
vihar123
Asked:
vihar123
  • 4
  • 4
1 Solution
 
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
 
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now