如何处理 CWnd 中的 wm_print 消息(使用 MFC)?
Posted
技术标签:
【中文标题】如何处理 CWnd 中的 wm_print 消息(使用 MFC)?【英文标题】:How to handle wm_print message in a CWnd (using MFC)? 【发布时间】:2012-08-17 05:53:00 【问题描述】:有没有办法在 CWnd(使用 MFC)中处理 wm_print 消息?我正在尝试拦截此消息并阻止打印子控件。将 ON_WM_PRINT() 添加到我的消息映射会引发编译错误。
【问题讨论】:
【参考方案1】:MFC 只为最常见的消息定义了 ON_WM_XXXX() 宏,但也有一个通用的 ON_MESSAGE() 宏允许您处理其他情况。添加
ON_MESSAGE(WM_PRINT, OnPrint)
到你的消息映射,然后声明并实现一个成员函数
afx_msg LRESULT OnPrint(WPARAM, LPARAM);
设备上下文在 WPARAM 中传递,因此您的实现中需要这样的东西:
LRESULT MyWindowClass::OnPrint(WPARAM wp, LPARAM)
CDC* dc = CDC::FromHandle((HDC)wp);
// Do custom logic here ...
// Only call Default() if you want the default processing for this message too ...
return Default();
【讨论】:
以上是关于如何处理 CWnd 中的 wm_print 消息(使用 MFC)?的主要内容,如果未能解决你的问题,请参考以下文章