在我的CWinFormsControl派生的MFC类中未调用WM_COMMAND消息处理程序. [英] WM_COMMAND message handler not getting called in my CWinFormsControl-derived MFC class.

查看:189
本文介绍了在我的CWinFormsControl派生的MFC类中未调用WM_COMMAND消息处理程序.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在MFC 9.0应用程序中使用WinForms(.NET)控件.

问题:在我的"CWinFormsControl< n:c>"派生的MFC类中未调用我的WM_COMMAND消息处理程序"OnStartTestMode()".
"pWnd-> PostMessage(WM_COMMAND,IDM_START_CMD);"响应菜单项的选择,将WM_COMMAND消息从视图类发布到子控件"NAnalogMeter".
请参见下面Winforms派生的控件类"NAnalogMeter",以及消息映射的命令消息声明:(注意:在代码中直接用"CWinFormsControl< C"替换中间的"CEnhGauge"类不能解决问题)- -
-------------------------------------------------- --------------
NAnalogMeter.h头文件:

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()
};


-------------------------------------------------- ----------------
及其实现文件NAnalogMeter.cpp:


------------------------------------------------------------------
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 ***/
}


-------------------------------------------------- --------------
我已经使用Spy ++监视到我的MFC应用程序中子Winforms控件的消息-我可以看到WM_COMMAND消息出现在子窗口的Spy ++消息日志中,但是可惜我的"OnStartTestMode"处理程序从未被调用过.
非常感谢您为解决此问题提供的帮助.
汤姆
================================================== =====


----------------------------------------------------------------
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
=======================================================

推荐答案

您是否真的在发布IDM_START_CMD命令,但在消息映射条目中寻找IDM_START_TEST_MODE?它们具有相同的值吗?
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?


我现在可以正常使用了-我更改了"Postmessage()/GetNextWindow()"循环(将msg发送给View的所有子级)一次调用"pView-> SendMessageToDescendents(WM_COMMAND,msg,0,FALSE,TRUE)",现在所有子窗口(包括基于CWinFormsControl的窗口)都将正确调用其OnStartTestMode()处理程序-谢谢.
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.


这篇关于在我的CWinFormsControl派生的MFC类中未调用WM_COMMAND消息处理程序.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆