框架CCtrlFrame
extern CReadyTestView *pReadyTestView;视图
BOOL CCtrlFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
// Create a context.
CCreateContext context;
pContext = &context; // Assign custom view.
pContext->m_pNewViewClass = RUNTIME_CLASS(CReadyTestView); // Create the view.
pReadyTestView = (CReadyTestView *) CreateView(pContext, AFX_IDW_PANE_FIRST);
if (pReadyTestView == NULL)
return FALSE; // Notify the view.
SetActiveView(pReadyTestView, FALSE); return TRUE;
}
但是在CCtrlFrame::start()
{
      pReadyTestView->SetTimer(0,100,NULL);}
这样都不启动SetTiemr(0,阿,请问为什么阿?

解决方案 »

  1.   

    你重载WM_TIMER处理timer消息了吗?
      

  2.   

    对,SetTimer()只对OnTimer()有效吧
      

  3.   

    已经重载了阿,具体如下
    void CReadyTestView::OnTimer(UINT nIDEvent) 
    {
    TestCount++;
    if(TestCount>(m_nTests-1))
    {
    TestCount=0;
    KillTimer(0);
    }
    Invalidate(false);

    CView::OnTimer(nIDEvent);
    }
    但是,在TestCount++;断点时没执行到这里,
    但却是我有pReadyTestView->SetTimer(0,100,NULL);
    并且反回值为1了。
      

  4.   

    BEGIN_MESSAGE_MAP(EasyTestView, CWnd)
    //{{AFX_MSG_MAP(EasyTestView)
    ON_WM_TIMER()//都有了阿
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
      

  5.   

    BEGIN_MESSAGE_MAP(CReadyTestView, CView)
    //{{AFX_MSG_MAP(CReadyTestView)
    ON_WM_TIMER()//都有了阿
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
      

  6.   

    faint!
    SetTimer 的第一个参数nIDEvent不能为0,MSDN里写得很明白:UINT SetTimer( UINT nIDEvent, UINT nElapse, void (CALLBACK EXPORT* lpfnTimer)(HWND, UINT, UINT, DWORD) );Return ValueThe timer identifier of the new timer if the function is successful. An application passes this value to the KillTimer member function to kill the timer. Nonzero if successful; otherwise 0.ParametersnIDEventSpecifies a nonzero timer identifier.nElapseSpecifies the time-out value, in milliseconds.lpfnTimerSpecifies the address of the application-supplied TimerProc callback function that processes the WM_TIMER messages. If this parameter is NULL, the WM_TIMER messages are placed in the application’s message queue and handled by the CWnd object.
      

  7.   

    楼上的同志说的很对!nID为UINT型参数,msdn中说的很明白了,从1开始。
      

  8.   

    其实nID=0,是可以的,不信你们试试看
    还有阿,并不是这个问题阿,我改nID=1,2,3,4,都不行阿?
      

  9.   

    是不是应该在CCtrlFrame中重载OnTimer啊?
      

  10.   

    void CReadyTestView::OnTimer(UINT nIDEvent) 
    {
    TestCount++;
    if(TestCount>(m_nTests-1))
    {
    TestCount=0;
    KillTimer(0);//因此这里会出问题.
    }
    Invalidate(false);

    CView::OnTimer(nIDEvent);
    }
    但是,在TestCount++;断点时没执行到这里,
    但却是我有pReadyTestView->SetTimer(0,100,NULL);
    并且反回值为1了。//返回1说明timer的nIDEvent == 1
      

  11.   

    you must override WM_TIMER message in CCtrlFrame class !void CCtrlFrame::OnTimer(UINT nIDEvent) 
    {
    TestCount++;
    if(TestCount>(m_nTests-1))
    {
    TestCount=0;
    KillTimer(0);
    }
    Invalidate(false);

    CCtrlFrame的基类::OnTimer(nIDEvent);
    }
      

  12.   

    killtimer(zz)
    zz是指向对应的timer的,因为你可以有多个timer
    关键是ontimer重载
      

  13.   

    ft,搞错对象了!你怎么可以在CCtrlFrame里SetTimer,在CReadyTestView里完成实现代码???晕呀...你自己吃的东西要别人帮你拉...可能吗????
      

  14.   

    楼上的,你看清人家的代码啊是在CCtrlFrame里调用CReadyTestView的SetTimer
      

  15.   

    可能是
    // Create a context.
    CCreateContext context;
    pContext = &context; // Assign custom view.
    pContext->m_pNewViewClass = RUNTIME_CLASS(CReadyTestView); // Create the view.
    pReadyTestView = (CReadyTestView *) CreateView(pContext, AFX_IDW_PANE_FIRST);
    if (pReadyTestView == NULL)
    return FALSE; // Notify the view.
    SetActiveView(pReadyTestView, FALSE);
    出问题,但我现在还没找出来
      

  16.   

    前段时间写一个俄罗斯方块游戏的时候我曾也出现了类似的情况,
    无论如何都不会使定时器有效,当时这样的情况:
    我在FrameWnd中把视图分为三个视图,开始的时候定时器有效,但
    不知怎么搞的,定时器突然不起作用了,(在三个视图中都不起作用了,
    甚至在FrameWnd中都没有作用!!)
    在一直没找到原因的情况下,我只好重新建立一个工程,把写的代码
    复制进新的工程中(这其间框架代码几乎没动过),奇怪,定时器一下
    子就可以用了,百思不得其解,现在只能拿出来给大家做个参考.
    我想如果兄弟还没有解决问题,可以试着重新建立一个工程并把代码
    复制过去试试,祝好运!
      

  17.   

    回superhackerlin(单身贵族) :
    在三个视图中都不起作用了,可能是指向视图指错了,检查一下就行了。
      

  18.   

    SetTimer 的第一个参数nIDEvent不能为0