带有模板的子类窗口 [英] Subclass window with template
问题描述
大家好,
我已经离开C ++几年了,现在又回来了.我必须使用VS2010处理其他人的旧代码.我想重写OnInitDialog()并将自己的菜单注入系统菜单,然后为WM_SYS_COMMAND添加消息处理程序.问题是我不确定如何连接消息映射.
这是我的代码的简化版本(为简洁起见):
Hello All,
I have been out of the C++ world for several years and have come back. I am having to work on someone else''s old code with VS2010. I would like to override OnInitDialog() and inject my own menu to the system menu and then add a message handler for WM_SYS_COMMAND. The problem is I am not sure how to hook up the message maps.
Here is a simplified (for the sake of brevity)version of my code:
template<class TBase>
class TSubclass : public TBase {
protected:
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
DECLARE_MESSAGE_MAP()
};
template<class TBase>
BOOL
TSubclass <TBase>::OnInitDialog() {
//... Code omitted
return TBase::OnInitDialog();
}
template<class TBase>
void
TSubclass <TBase>::OnSysCommand(UINT nID, LPARAM lParam) {
if ((nID & 0xFFF0) == (WM_USER + 100)) {
//... Code omitted
}
else {
TBase::OnSysCommand(nID, lParam);
}
}
BEGIN_TEMPLATE_MESSAGE_MAP(class TBase, TSubclass <TBase>, TBase)
ON_WM_SYSCOMMAND()
END_MESSAGE_MAP()
我已经使用自定义消息映射在VC 6.0/.Net中完成了与此类似的操作,但是这又是几年前的事了,我无法访问该旧代码.我看到了BEGIN_TEMPLATE_MESSAGE_MAP宏,并认为Microsoft现在已经实现了一些东西,但是我只是无法正确获取语法.
鉴于以上所述,有人可以向我指出BEGIN_TEMPLATE_MESSAGE_MAP的问题吗?
感谢您的帮助!
-Craig
I have done something similar to this in VC 6.0/.Net with custom message maps, but again that has been several years ago and I do not have access to that old code. I saw the BEGIN_TEMPLATE_MESSAGE_MAP macro and thought Microsoft had implemented something now, but I just can''t get the syntax correct.
Given the above can someone point out to me the problem with the BEGIN_TEMPLATE_MESSAGE_MAP?
Thanks for all your help!
-Craig
推荐答案
我现在对其进行编译,并成功调用OnInitDialog()和OnSysCommand().
我更改了此内容:
I have it compiling now and have it successfully calling OnInitDialog() and calling OnSysCommand().
I changed this:
BEGIN_TEMPLATE_MESSAGE_MAP(class TBase, TSubclass <tbase>, TBase)
ON_WM_SYSCOMMAND()
END_MESSAGE_MAP()
</tbase>
对此:
to this:
BEGIN_TEMPLATE_MESSAGE_MAP(TDebugConsole, TBase, TBase)
ON_WM_SYSCOMMAND()
END_MESSAGE_MAP()
这篇关于带有模板的子类窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!