Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Disabling menu item

Posted on 2004-10-22
9
Medium Priority
?
215 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
Comment
Question by:vihar123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 1000 total points
ID: 12380311
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 31

Expert Comment

by:Zoppo
ID: 12381970
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
ID: 12399321
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 31

Expert Comment

by:Zoppo
ID: 12399346
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
ID: 12399578
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 31

Expert Comment

by:Zoppo
ID: 12399653
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
ID: 12408650
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 31

Expert Comment

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

Vihar123
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

604 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