Click here to Skip to main content
15,902,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello- I'm Using a WinForms (.NET) control within an MFC 9.0 application.

Problem: My WM_COMMAND message handler "OnStartTestMode()" is not getting called in my "CWinFormsControl<n:c>"-derived MFC class.
A "pWnd->PostMessage(WM_COMMAND, IDM_START_CMD);" is posting the WM_COMMAND message to the child control "NAnalogMeter" from the view class, in response to a menu item selection.
See the Winforms-derived control class "NAnalogMeter" below, along with the command message declaration for message map: (note: replacing the intermediate "CEnhGauge" class directly with "CWinFormsControl<>" in the code does not resolve the issue) --
----------------------------------------------------------------
NAnalogMeter.h header file:

#include "afxwinforms.h"
class CEnhGauge : public CWinFormsControl<AquaControls::AquaGauge>
{
};
/////////////////////////////////////////////////////////////////////
// NAnalogMeter window - used to show a value as a round dial/gauge instrument meter.
class NAnalogMeter : public CEnhGauge
{
	// Construction
	public:
	  NAnalogMeter (const CRect& r, CWnd *pParent );
	
	// Implementation
	public:
	     virtual ~NAnalogMeter();
	// Generated message map functions
	protected:
		//{{AFX_MSG(NAnalogMeter)
		afx_msg void OnPaint();
		afx_msg void OnSize(UINT nType, int cx, int cy);
		afx_msg BOOL OnEraseBkgnd(CDC* pDC);
		//}}AFX_MSG
		afx_msg void OnStartTestMode();
		DECLARE_MESSAGE_MAP()
};

------------------------------------------------------------------
And its implementation file, NAnalogMeter.cpp:

BEGIN_MESSAGE_MAP(NAnalogMeter, CEnhGauge)  
 //{{AFX_MSG_MAP(NAnalogMeter)
 ON_WM_PAINT()
 //}}AFX_MSG_MAP
 ON_COMMAND(IDM_START_TEST_MODE, OnStartTestMode)
END_MESSAGE_MAP()
NAnalogMeter::NAnalogMeter (const CRect& r, CWnd *pParent )
{
  BOOL bCreatedOK = this->CreateManagedControl(WS_VISIBLE | WS_CHILD //*style*/, r /*rect*/, pParent, 0 /*ID*/); // pParent is the view-class
}
void NAnalogMeter::OnStartTestMode ( )
{
	// handler code here .....
	// ***PROBLEM: This handler is NOT GETTING CALLED ***/
}

----------------------------------------------------------------
I've used Spy++ to monitor the messages to the child Winforms control in my MFC app -- I could see the WM_COMMAND message appear in the Spy++ message log for the child window, but alas my "OnStartTestMode" handler is never getting invoked.
Thank you very much for any help in resolving this.
Tom
=======================================================
Posted
Updated 24-Aug-10 11:17am
v2

Are you really posting a IDM_START_CMD command but looking for a IDM_START_TEST_MODE in the message map entry? Do they have the same value?
 
Share this answer
 
Comments
Member 1914662 25-Aug-10 9:53am    
Sorry about that discrepancy in the command message#, it is actually the same value, and in the code they are now both "IDM_START_TEST_MODE" (=173 dec). To provide more info: When this code for NAnalogMeter control used the original MFC (owner-draw) gauge control instead of the Winforms one, the base class for it was simply 'CStatic' and the code within "NAnalogMeter" class would draw using GDI functions to render the dial/needle/etc. (looked very bad) -- And with "CStatic" base class the StartTestMode command handler worked fine -- trouble seemed to start when I derived from the "CWinFormsControl" class (based on CWnd) -- and now the handler is never called.
Could it be related somehow to the "CWinFormsControl's" internal handling/interop as an ActiveX control that is messing up the message map? Thanks again for your reply.Tom
Member 1914662 27-Aug-10 12:46pm    
Reason for my vote of 3
typo
I Got it to work now -- I changed the "Postmessage()/GetNextWindow()" loop (to send msgs to all children of the View) into a single call to "pView->SendMessageToDescendents(WM_COMMAND, msg, 0, FALSE, TRUE)" and now all child windows (including the CWinFormsControl-based one) are getting their OnStartTestMode() handlers called properly - Thanks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900