我用的vs2003,WTL8.0,再看实例的时候发现这么个问题:BEGIN_MSG_MAP_EX(CMyWindow)
......
MSG_WM_TIMER(OnTimer)
......
END_MSG_MAP()void OnTimer(UINT nIDEvent, TIMERPROC lpTimerFunc)
{
if ( 1 != nIDEvent )
SetMsgHandled(false);
else
RedrawWindow();
}错误:C2660: “CMyWindow::OnTimer” : 函数不接受 1 个参数书写都没有问题啊,为啥会这种出错呢?
......
MSG_WM_TIMER(OnTimer)
......
END_MSG_MAP()void OnTimer(UINT nIDEvent, TIMERPROC lpTimerFunc)
{
if ( 1 != nIDEvent )
SetMsgHandled(false);
else
RedrawWindow();
}错误:C2660: “CMyWindow::OnTimer” : 函数不接受 1 个参数书写都没有问题啊,为啥会这种出错呢?
2.void CMyWindow::OnTimer(UINT nIDEvent, TIMERPROC lpTimerFunc)
{
if ( 1 != nIDEvent )
SetMsgHandled(false);
else
RedrawWindow();
}
#define MYWINDOW_H_INCLUDED#include "resource.h" // resource IDsclass CMyWindow : public CFrameWindowImpl<CMyWindow>
{
public:
DECLARE_FRAME_WND_CLASS ( _T("First WTL window"), IDR_MAINFRAME ); BEGIN_MSG_MAP_EX(CMyWindow)
MSG_WM_CREATE(OnCreate)
MSG_WM_DESTROY(OnDestroy)
MSG_WM_ERASEBKGND(OnEraseBkgnd)
// MSG_WM_TIMER()
MSG_WM_TIMER(OnTimer)
COMMAND_ID_HANDLER_EX(IDC_EXIT, OnFileExit)
COMMAND_ID_HANDLER_EX(IDC_ABOUT, OnAbout)
CHAIN_MSG_MAP(CFrameWindowImpl<CMyWindow>)
END_MSG_MAP() LRESULT OnCreate ( LPCREATESTRUCT lpcs )
{
SetTimer ( 1, 1000 );
SetMsgHandled(false);
return 0;
} void OnDestroy()
{
KillTimer(1);
SetMsgHandled(false);
} LRESULT OnEraseBkgnd ( HDC hdc )
{
CDCHandle dc(hdc);
CRect rc;
SYSTEMTIME st;
CString sTime; // Get our window's client area.
GetClientRect ( rc ); // Build the string to show in the window.
GetLocalTime ( &st );
sTime.Format ( _T("The time is %d:%02d:%02d"), st.wHour, st.wMinute, st.wSecond ); // Set up the DC and draw the text.
dc.SaveDC();
dc.SetBkColor ( RGB(255,153,0) );
dc.SetTextColor ( RGB(0,0,0) );
dc.ExtTextOut ( 0, 0, ETO_OPAQUE, rc, sTime, sTime.GetLength(), NULL ); // Restore the DC.
dc.RestoreDC(-1);
return 1; // We erased the background (ExtTextOut did it)
} void OnTimer(UINT nIDEvent, TIMERPROC lpTimerFunc)
{
if ( 1 != nIDEvent )
SetMsgHandled(false);
else
RedrawWindow();
} void OnFileExit(UINT uCode, int nID, HWND hwndCtrl)
{
DestroyWindow();
return;
} void OnAbout(UINT uCode, int nID, HWND hwndCtrl)
{
CSimpleDialog<IDD_ABOUT> dlg; dlg.DoModal();
return;
}
};#endif // ndef MYWINDOW_H_INCLUDED
// void OnTimer(UINT_PTR nIDEvent)
#define MSG_WM_TIMER(func) \
if (uMsg == WM_TIMER) \
{ \
SetMsgHandled(TRUE); \
func((UINT_PTR)wParam); \
lResult = 0; \
if(IsMsgHandled()) \
return TRUE; \
}把void OnTimer(UINT nIDEvent, TIMERPROC lpTimerFunc)
改成void OnTimer(UINT nIDEvent)
就搞定了~
void OnTimer(UINT nIDEvent)你看看atlcrash.h里的定义就知道
#define MSG_WM_TIMER(func)if( uMsg == WM_TIMER )
{
...
func(wParam);
...
}
我估计你用的是WTLHelper
另,VisualFC这个插件不错!
BEGIN_MSG_MAP_EX
还是
BEGIN_MSG_MAP前者是crack后的message handle,不需要用原始的win32 api函数的signature。还是对WTL理解太少。其实WTL不知道要比MFC方便多少。
就行啊
或者
MSG_WM_TIMER(0,OnTimer)就不错了
不知原因
函数原型是:func((UINT_PTR)wParam);