我用的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 个参数书写都没有问题啊,为啥会这种出错呢?

解决方案 »

  1.   

    1.你的OnTimer在CMyWindow中是如何定义的?
    2.void CMyWindow::OnTimer(UINT nIDEvent, TIMERPROC lpTimerFunc) 
      

  2.   

    直接写在MyWindow.h里~void OnTimer(UINT nIDEvent, TIMERPROC lpTimerFunc) 

            if ( 1 != nIDEvent ) 
                SetMsgHandled(false); 
            else 
                RedrawWindow(); 
      

  3.   

    整个MyWindow.h~#ifndef MYWINDOW_H_INCLUDED
    #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
      

  4.   

    看了一下WTL8.0 对MSG_WM_TIMER的宏定义
    // 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)
    就搞定了~ 
      

  5.   

    改成这 
    void OnTimer(UINT nIDEvent)你看看atlcrash.h里的定义就知道
    #define MSG_WM_TIMER(func)if( uMsg == WM_TIMER )
    {
        ...
        func(wParam);
        ...

    我估计你用的是WTLHelper
      

  6.   

    用WTL,需要看源码的。
    另,VisualFC这个插件不错!
      

  7.   

    WTL真怪,新版本就不支持旧版本
      

  8.   

    顶一个,我用WTL8.0的时候也遇到过这个问题:)          
      

  9.   

    要注意是用
    BEGIN_MSG_MAP_EX
    还是
    BEGIN_MSG_MAP前者是crack后的message handle,不需要用原始的win32 api函数的signature。还是对WTL理解太少。其实WTL不知道要比MFC方便多少。
      

  10.   

    貌似  //MSG_WM_TIMER(OnTimer)
    就行啊
    或者 
    MSG_WM_TIMER(0,OnTimer)就不错了 
    不知原因
      

  11.   

    wtl 8.x 的 wm_ontimer 消息的处理函数只有一个参数,
    函数原型是:func((UINT_PTR)wParam);