框架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,阿,请问为什么阿?
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,阿,请问为什么阿?
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了。
//{{AFX_MSG_MAP(EasyTestView)
ON_WM_TIMER()//都有了阿
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//{{AFX_MSG_MAP(CReadyTestView)
ON_WM_TIMER()//都有了阿
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
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.
还有阿,并不是这个问题阿,我改nID=1,2,3,4,都不行阿?
{
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
{
TestCount++;
if(TestCount>(m_nTests-1))
{
TestCount=0;
KillTimer(0);
}
Invalidate(false);
CCtrlFrame的基类::OnTimer(nIDEvent);
}
zz是指向对应的timer的,因为你可以有多个timer
关键是ontimer重载
// 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);
出问题,但我现在还没找出来
无论如何都不会使定时器有效,当时这样的情况:
我在FrameWnd中把视图分为三个视图,开始的时候定时器有效,但
不知怎么搞的,定时器突然不起作用了,(在三个视图中都不起作用了,
甚至在FrameWnd中都没有作用!!)
在一直没找到原因的情况下,我只好重新建立一个工程,把写的代码
复制进新的工程中(这其间框架代码几乎没动过),奇怪,定时器一下
子就可以用了,百思不得其解,现在只能拿出来给大家做个参考.
我想如果兄弟还没有解决问题,可以试着重新建立一个工程并把代码
复制过去试试,祝好运!
在三个视图中都不起作用了,可能是指向视图指错了,检查一下就行了。