在VC的Cwnd中用SetTimer, KillTimer和OnTimer可以很简单的设置出定时器
但在自己写的全局函数中要设置一个定时器,它的消息机制如何传递呢?
急切知道如何应用!
有原代码更好!
[email protected]
谢谢

解决方案 »

  1.   


    1。m_nTimerId = SetTimer(1, 50, TimerProc);2。void CALLBACK C???Ctrl::TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
    {
    ::PostMessage(hwnd, WM_MYHELLO, 0, 0);
    //  
    }
    3。
    if(m_nTimerId)
    KillTimer(m_nTimerId);4。static UINT m_nTimerId = 0;static void CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime);
      

  2.   

    SetTimer重载OnTimer   WM_TIMERKillTimer
      

  3.   

    void CALLBACK C???Ctrl::TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime) ???我的函数是全局函数,没有继承基类,那这个声明应该怎么写呀?
      

  4.   

    全局函数,单独的,如何写hWnd: handle to window
    这个函数什么基类都没有继承!!!!
    完成定时器的功能!
    TimerProc到底该怎么写呀!
      

  5.   

    MSDN:TimerProc
    The TimerProc function is an application-defined callback function that processes WM_TIMER messages. The TIMERPROC type defines a pointer to this callback function. TimerProc is a placeholder for the application-defined function name. VOID CALLBACK TimerProc(
      HWND hwnd,         // handle to window
      UINT uMsg,         // WM_TIMER message
      UINT_PTR idEvent,  // timer identifier
      DWORD dwTime       // current system time
    );
    Parameters
    hwnd 
    [in] Handle to the window associated with the timer. 
    uMsg 
    [in] Specifies the WM_TIMER message. 
    idEvent 
    [in] Specifies the timer's identifier. 
    dwTime 
    [in] Specifies the number of milliseconds that have elapsed since the system was started. This is the value returned by the GetTickCount function. 
    Return Values
    This function does not return a value. Requirements 
      Windows NT/2000: Requires Windows NT 3.1 or later.
      Windows 95/98: Requires Windows 98 or later.
      Header: Declared in Winuser.h; include Windows.h.See Also
    Timers Overview, Timer Functions, GetTickCount, KillTimer, SetTimer, WM_TIMER 
      

  6.   

    我在调用TimerProc的时候
    m_nTimerId = ::SetTimer( NULL, 1, 50, ( CALLBACK TimerProc(NULL, WM_MYHELLO, 1, NULL) ) );
    总是出现:error C2059: syntax error : '__stdcall'
    是为什么呀!
    如何将WM_MYHELLO的消息传给函数响应呢?
    在一般继承MFC类的类中
    可以将WM_MYHELLO和关联的函数如OnMyHello在
    BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
    //{{AFX_MSG_MAP(CMainFrame)
                 ON_MESSAGE( WN_MYHELLO, OnMyHello )
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()但在我这,没有任何的MFC的信息,如何传递信息呢?
    或如何重载OnTimer   WM_TIMER呢?或有什么简单的方法呢?
      

  7.   

    SetTimer(NULL, 1, 50, TimerProc);
      

  8.   

    这个问题如何解决呢?请教 Skt32(荒城之月) 如何将WM_MYHELLO的消息传给函数响应呢?
    在一般继承MFC类的类中
    可以将WM_MYHELLO和关联的函数如OnMyHello在
    BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
    //{{AFX_MSG_MAP(CMainFrame)
                 ON_MESSAGE( WN_MYHELLO, OnMyHello )
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()但在我这,没有任何的MFC的信息,如何传递信息呢?
    或如何重载OnTimer   WM_TIMER呢?或有什么简单的方法呢?
      

  9.   

    sun_li_cn(的的):Skt32(荒城之月)说的对,他做的是定时器回调,没有用到消息机制,不用你上面的做法