形容天色昏暗的句子:请问,谁知道VC中的SetTimer怎么用?

来源:百度文库 编辑:神马品牌网 时间:2024/05/03 07:45:55
rt.能不能说的详细些.

MSDN的详细说明,看不懂去查字典
SetTimer Function

--------------------------------------------------------------------------------

The SetTimer function creates a timer with the specified time-out value.

Syntax

UINT_PTR SetTimer( HWND hWnd,
UINT_PTR nIDEvent,
UINT uElapse,
TIMERPROC lpTimerFunc
);
Parameters

hWnd
[in] Handle to the window to be associated with the timer. This window must be owned by the calling thread. If this parameter is NULL, no window is associated with the timer and the nIDEvent parameter is ignored.
nIDEvent
[in] Specifies a nonzero timer identifier. If the hWnd parameter is NULL, this parameter is ignored. If the hWnd parameter is not NULL and the window specified by hWnd already has a timer with the value nIDEvent, then the existing timer is replaced by the new timer. When SetTimer replaces a timer, the timer is reset. Therefore, a message will be sent after the current time-out value elapses, but the previously set time-out value is ignored.
uElapse
[in] Specifies the time-out value, in milliseconds.
Windows NT/2000/XP: If uElapse is greater than 0x7fffffff, the timeout is set to 1.

Windows 2000/XP: If uElapse is less than 10, the timeout is set to 10.

Windows Server 2003: If uElapse is greater than 0x7fffffff, the timeout is set to 0x7fffffff.

lpTimerFunc
[in] Pointer to the function to be notified when the time-out value elapses. For more information about the function, see TimerProc. If lpTimerFunc is NULL, the system posts a WM_TIMER message to the application queue. The hwnd member of the message's MSG structure contains the value of the hWnd parameter.
Return Value

If the function succeeds and the hWnd parameter is NULL, the return value is an integer identifying the new timer. An application can pass this value to the KillTimer function to destroy the timer.

If the function succeeds and the hWnd parameter is not NULL, then the return value is a nonzero integer. An application can pass the value of the nIDEvent parameter to the KillTimer function to destroy the timer.

If the function fails to create a timer, the return value is zero. To get extended error information, call GetLastError.

Remarks

An application can process WM_TIMER messages by including a WM_TIMER case statement in the window procedure or by specifying a TimerProc callback function when creating the timer. When you specify a TimerProc callback function, the default window procedure calls the callback function when it processes WM_TIMER. Therefore, you need to dispatch messages in the calling thread, even when you use TimerProc instead of processing WM_TIMER.

The wParam parameter of the WM_TIMER message contains the value of the nIDEvent parameter.

The timer identifier, nIDEvent, is specific to the associated window. Another window can have its own timer which has the same identifier as a timer owned by another window. The timers are distinct.

SetTimer can reuse timer IDs in the case where hWnd is NULL.

Example

For an example, see Creating a Timer.

Function Information

Header Declared in Winuser.h, include Windows.h
Import library User32.lib
Minimum operating systems Windows 95, Windows NT 3.1

最简单的使用方法

SetTimer( hWnd, 1, 1000, NULL);

定义一个一秒的定时器(1000 就是一秒,100就是0.1秒),NULL比表示不使用函数过程,相应WM_TIMER 消息。 hWnd 为窗口的句柄,此窗体接受WM_TIMER 消息. 也就是说你的要没一秒重运行的东西放到这个消息的过程里就行了。

例如
…………
case WM_TIMER : //假如这是一个消息循环处理过程。。

MessageBox(hWnd,…………); //没秒钟出来一个提示框

break;

1 为定时器标号,用于不需要定时器时调用 KillTimer释放。

函数名: settime
功 能: 设置系统时间
用 法: void settime(struct time *timep);
程序例:

#include <stdio.h>
#include <dos.h>

int main(void)
{
struct time t;

gettime(&t);
printf("The current minute is: %d\n", t.ti_min);
printf("The current hour is: %d\n", t.ti_hour);
printf("The current hundredth of a second is: %d\n", t.ti_hund);
printf("The current second is: %d\n", t.ti_sec);

/* Add one to the minutes struct element and then call settime */
t.ti_min++;
settime(&t);

return 0;
}

1. SetTimer ---The SetTimer function creates a timer with the specified time-out value.
(这个函数创建一个指定时间值的定时器)
2.SetTimer原型:(摘于MSDN)
UINT_PTR SetTimer(
HWND hWnd, // handle to window(与那个窗口建立联系)
UINT_PTR nIDEvent, // timer identifier(该定时器的标志)
UINT uElapse, // time-out value(触发时间)
TIMERPROC lpTimerFunc // timer procedure(回调函数,若NULL则发WM_TIMER消息)
);
3.细讲定时器:
第一个参数:1、NULL,则第二个参数随之被忽视
2、窗口句柄,则与该窗口建立联系,会向该窗口发送消息(当第四个参数为NULL)
第二个参数:窗口的标志,如果创建了多个定时器,如果标志一样,那么系统会采用标志最高的那位。(也就是给每一个定时器取个名字,用于系统分别)
第三个参数:触发时间
第四个参数:如果NULL则向建立窗口的函数发送WM_TIMIER消息,如果指定函数,由系统自动调用该回调函数
回调函数原型:
UINT SetTimer
(
HWND hWnd,
UINT nIDEvent,
UINT uElapse,
TIMERPROC lpTimerFunc
);

嗯,SetTimer 这个函数嘛
它是用来实现VC,VB中托管代码程序中的 时钟控件的的功能的
哈哈,它不像楼上说的什么,设置系统的时间

看哈,我来教你
BOOL CMy121Dlg::OnInitDialog()
{
......
SetTimer(0,100,NULL);
.......
}
我添加了这个函数在初使化的函数里
这个函数的意义是
SetTimer(
参数一:每个周期触发的事件代号,数字形,如 1 为事件一
参数二:发生这个事件的周期
参数三:每发生这个事件时,要执行的函数
)
每发生一次事件,这个函数会向窗口发送一个WM_TIMER 消息,这个消息的WPARAM 参数就是 参数一 :)
可以在消息映射里加入代码来周期执行某件事
我只是介绍了这个函数的用法,有关其它的,具体的是例,你可以加我QQ:1125591 我可以教你,反正署假无聊,不过过了署假,就没时间了,高三了,要好好读书了