描述:
用WTL向导生成一个SDI程序,改变其中的viewXXXX文件如下.
// WtlNewMenuView.h : interface of the CWtlNewMenuView class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_WTLNEWMENUVIEW_H__C340430A_ABD4_44FE_8F31_C1B45BCA52B6__INCLUDED_)
#define AFX_WTLNEWMENUVIEW_H__C340430A_ABD4_44FE_8F31_C1B45BCA52B6__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
template <class T, COLORREF t_crBrushColor>
class CPaintBkgnd : public CMessageMap
{
public:
CPaintBkgnd() { m_hbrBkgnd = CreateSolidBrush(t_crBrushColor); }
~CPaintBkgnd() { DeleteObject ( m_hbrBkgnd ); }
BEGIN_MSG_MAP(CPaintBkgnd)
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
END_MSG_MAP()
LRESULT OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
T* pT = static_cast<T*>(this);
HDC dc = (HDC) wParam;
RECT rcClient;
pT->GetClientRect ( &rcClient );
FillRect ( dc, &rcClient, m_hbrBkgnd );
return 1; // we painted the background
}
protected:
HBRUSH m_hbrBkgnd;
};
class CWtlNewMenuView : public CWindowImpl<CWtlNewMenuView>,
public CPaintBkgnd<CWtlNewMenuView,RGB(200,0,0)>
{
public:
DECLARE_WND_CLASS(NULL)
BOOL PreTranslateMessage(MSG* pMsg);
typedef CPaintBkgnd<CWtlNewMenuView, RGB(0,0,255)> CPaintBkgndBase;
BEGIN_MSG_MAP(CWtlNewMenuView)
MESSAGE_HANDLER(WM_PAINT, OnPaint)
CHAIN_MSG_MAP(CPaintBkgndBase)
END_MSG_MAP()
// Handler prototypes (uncomment arguments if needed):
// LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
// LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
// LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)
LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_WTLNEWMENUVIEW_H__C340430A_ABD4_44FE_8F31_C1B45BCA52B6__INCLUDED_)
结果出现了三个相同的错误:
--------------------Configuration: WtlNewMenu - Win32 Debug--------------------
Compiling...
mainfrm.cpp
f:\临时目录\wtlnewmenu\wtlnewmenuview.h(48) : error C2352: 'CPaintBkgnd<class CWtlNewMenuView,16711680>::ProcessWindowMessage' : illegal call of non-static member function
f:\临时目录\wtlnewmenu\wtlnewmenuview.h(19) : see declaration of 'ProcessWindowMessage'
Generating Code...
Compiling...
WtlNewMenu.cpp
f:\临时目录\wtlnewmenu\wtlnewmenuview.h(48) : error C2352: 'CPaintBkgnd<class CWtlNewMenuView,16711680>::ProcessWindowMessage' : illegal call of non-static member function
f:\临时目录\wtlnewmenu\wtlnewmenuview.h(19) : see declaration of 'ProcessWindowMessage'
Generating Code...
Compiling...
WtlNewMenuview.cpp
f:\临时目录\wtlnewmenu\wtlnewmenuview.h(48) : error C2352: 'CPaintBkgnd<class CWtlNewMenuView,16711680>::ProcessWindowMessage' : illegal call of non-static member function
f:\临时目录\wtlnewmenu\wtlnewmenuview.h(19) : see declaration of 'ProcessWindowMessage'
Generating Code...
Error executing cl.exe.
WtlNewMenu.exe - 3 error(s), 0 warning(s)
为什么出现这个错误?
解决方案1:
class CWtlNewMenuView : public CWindowImpl<CWtlNewMenuView>,
public CPaintBkgnd<CWtlNewMenuView,RGB(200,0,0)>
typedef CPaintBkgnd<CWTLAppView,RGB(200,0,0)> CPaintBkgndBase;
要一样都是RGB(200,0,0)参数要一样
您可能想查找下面的文章:
- 看了一下WTL,对这个代码看不懂
- 要用atl写个控件,涉及到界面的,怎么将wtl和atl结合起来用呐?用wtl来做控件的界面
- 在ATL中使用WTL中的CFileDialog实现预览功能出现的不刷新问题,高手进
- 使用WTL库,编译提示“cannotopenincludefile"atlresh"”,这是怎么回事?
- WTL能否用于ATL做COM组件的界面?需要注意什么?
- WTL中,怎么改变lineto画线的颜色和粗细?
- WTL问题,MainFrame加一个Destory响应怎么会这样
- 请大家帮忙看看这个:关于wtl
- WTL,CCodePageCombo继承CComboBoxT<ATL::CWindow>类,需要响应下拉菜单CloseUp的消息
- WTL下如何添加Mediaplayer控件