YOU CAN CODE!

 

With The Case Of UCanCode.net  Release The Power OF  Visual C++ !   HomeProducts | PurchaseSupport | Downloads  
Download Evaluation
Pricing & Purchase?
E-XD++Visual C++/ MFC Products
Overview
Features Tour 
Electronic Form Solution
Visualization & HMI Solution
Power system HMI Solution
CAD Drawing and Printing Solution

Bar code labeling Solution
Workflow Solution

Coal industry HMI Solution
Instrumentation Gauge Solution

Report Printing Solution
Graphical modeling Solution
GIS mapping solution

Visio graphics solution
Industrial control SCADA &HMI Solution
BPM business process Solution

Industrial monitoring Solution
Flowchart and diagramming Solution
Organization Diagram Solution

Graphic editor Source Code
UML drawing editor Source Code
Map Diagramming Solution

Architectural Graphic Drawing Solution
Request Evaluation
Purchase
ActiveX COM Products
Overview
Download
Purchase
Technical Support
  General Q & A
Discussion Board
Contact Us

Links

Get Ready to Unleash the Power of UCanCode .NET

 


UCanCode Software focuses on general application software development. We provide complete solution for developers. No matter you want to develop a simple database workflow application, or an large flow/diagram based system, our product will provide a complete solution for you. Our product had been used by hundreds of top companies around the world!

"100% source code provided! Free you from not daring to use components because of unable to master the key technology of components!"


VC++ MFC Tutorial: WM_INITMENUPOPUP,WM_INITMENUPOPUP,WM_INITMENUPOPUP, menu in dialog

 
 Q. Why are my pop-up menus disabled in dialogs?

Basically, when a menu is about to pop up, a WM_INITMENUPOP message is sent to the parent window. In the base class of the CMainFrame, there is already a handler for the WM_INITMENUPOPUP, and it sends the UPDATE_COMMAND_UI sequence to the mainframe, the view, and the App classes, but not to the dialog.

So, you have two options:
1. Have your view class for all the menu enabling for the dialog. I'm not crazy about this approach.
2. Have your view class pass of it's processing to the current dialog, if one exists. I like this.

So, in order to accomplish #2, let's first take a look at how your doing your dialog now:

void CWhateverView::OnButton1()
{
CSomeDlg X;
X.DoModal();
}

In order to accomplish #2 above, we need to have the OnCmdMsg() function (added via classwizard) for your view call the OnCmdMsg for your dialog. However, the OnCmdMsg function can't see the X object in OnButton1, because it's a local variable.

So, you would do the following:
Create a member variable in your view, called pDialog, thats a CDialog *:
CDialog* pDialog;

In your view constructor, set the pointer to 0.
pDialog = 0;

Change your OnButton1, so that it initializes the dialog pointer:
void CWhateverView::OnButton1()
{
pDialog = new CSomeDlg;
pDialog->DoModal();
delete pDialog;
pDialog = 0;
}

Finally, change your view so that it's OnCmdMsg look like the following (you may need to add OnCmdMsg):
BOOL CWhateverView::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
if( pDialog && pDialog->OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) )
return( TRUE );

return CFormView::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}

In addition to the above, in your dialog class you need to *manually* add the ON_UPDATE_COMMAND_UI and ON_COMMAND macros for the routines that will be responsible for enabling/disabling a menu item, and specifying the function to call when the menu item is invoked.

 

 

Copyright ?1998-2024 UCanCode.Net Software , all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.

Please direct your questions or comments to webmaster@ucancode.net