vc++(sdk)定时器问题

settimer()执行后指定窗口马上会收到WM_TIMER消息?也就是我们设置定时器后,是马上收到wm_timer消息还是在间隔时间后收到?上面的问题我已经明白了,但是... settimer()执行后指定窗口马上会收到WM_TIMER消息?也就是我们设置定时器后,是马上收到wm_timer消息还是在间隔时间后收到?
上面的问题我已经明白了,但是为什么在swith-case中将case WM_TIMER,放在case WM_COMMAND(case IDOK)前就会达到我要目的(点击确定后在指定时间后弹出一个messagebox)。而顺序反过来就会一点击确定马上弹出对话框。请大家帮忙解答一下,菜鸟问题啊(break加了)
展开
 我来答
百度网友73d8a3d6b
2008-05-25 · TA获得超过650个赞
知道答主
回答量:245
采纳率:0%
帮助的人:329万
展开全部
-------------------
又帮你查到一个资料
------------------
CWnd::SetTimer():设置定时器。按设定的时间定时发送WM_TIMER消息。
说明:
UINT SetTimer( UINT nIDEvent, UINT nElapse, void (CALLBACK EXPORT* lpfnTimer)(HWND, UINT, UINT, DWORD) );
//nIDEvent定时器标示,nElapse消息发送间隔时间,void (CALLBACK EXPORT* lpfnTimer)(HWND, UINT, UINT, DWORD)设置回调函数,如果设置则由设置的回调函数处理WM_TIMER消息,如果没有设置回调函数设为NULL,这发送的WM_TIMER消息压入消息队列,交由相关联的窗口处理(添加WM_TIMER消息处理函数OnTimer())。
afx_msg void OnTimer( UINT nIDEvent );
//响应WM_TIMER消息,nIDEvent为消息对应定时器标示(可以设置不同的定时器发送WM_TIMER消息)
-----------------------
资料2
问题:
1,在CCareView类中添加WM_CREATE消息响应函数OnCreate(),WM_CREATE消息是在什么时候被检查到而被响应的呢?
(猜测:添加WM_CREATE消息后,消息被压入消息队列,然后经过消息循环进行分发到具体窗口,从而进行响应)
-----------------------
资料3
MSDN中的
CWnd::SetTimer
Example See Also Send Feedback

Installs a system timer.

UINT_PTR SetTimer(
UINT_PTR nIDEvent,
UINT nElapse,
void (CALLBACK* lpfnTimer
)(HWND,
UINT,
UINT_PTR,
DWORD
)
);

Parameters
nIDEvent
Specifies a nonzero timer identifier.

nElapse
Specifies the time-out value, in milliseconds.

lpfnTimer
Specifies 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.

Return Value
The 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.

Remarks
A time-out value is specified, and every time a time-out occurs, the system posts a WM_TIMER message to the installing application's message queue or passes the message to an application-defined TimerProc callback function.

The lpfnTimer callback function need not be named TimerProc, but it must be defined as follows:

void CALLBACK EXPORT TimerProc(

HWND hWnd, // handle of CWnd that called SetTimer

UINT nMsg, // WM_TIMER

UINT nIDEvent // timer identification

DWORD dwTime // system time

);

Example
This example uses CWnd::SetTimer, CWnd::OnTimer, and CWnd::KillTimer to handle WM_TIMER messages. A timer is set up to send a WM_TIMER message to the main frame window every 2 seconds in OnStartTimer. OnStopTimer will stop the timer by calling CWnd::KillTimer. OnTimer was set up to handle WM_TIMER messages for the main frame window. In this example, the PC speaker will beep every 2 seconds.

Visual C++ Copy Code
void CMainFrame::OnStartTimer()
{
m_nTimer = SetTimer(1, 2000, 0);
}

void CMainFrame::OnStopTimer()
{
KillTimer(m_nTimer);
}

void CMainFrame::OnTimer(UINT nIDEvent)
{
MessageBeep(0xFFFFFFFF); // Beep

// Call base class handler.
CMDIFrameWnd::OnTimer(nIDEvent);
}
//////////////////////////
SetTimer()
里的参数
nElapse
Specifies the time-out value, in milliseconds.
是毫秒级的!你定的值太小了吧!
你所谓的看到了延时应该是,消息被压入消息队列后,等待处理的时间吧.
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式