如何使用SetTimer和KillTimer函数?

fibbery 2005-11-29 09:32:42
没有窗口!请给一个完整的小例子!我试好久没有成功,不是却这个就是少那个!谢谢!
...全文
239 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
biss18 2005-11-30
  • 打赏
  • 举报
回复
映射WM_TIMER消息
freemme 2005-11-29
  • 打赏
  • 举报
回复
1. 指定回调函数
2. 调用settimer后循环调用getmessage捕捉WM_TIMER消息
alen_ghl 2005-11-29
  • 打赏
  • 举报
回复
直接指定回调函数
goodboyws 2005-11-29
  • 打赏
  • 举报
回复
如果不用回调函数,记得映射WM_TIMER消息
快乐鹦鹉 2005-11-29
  • 打赏
  • 举报
回复
UINT uResult; // SetTimer's return value
HICON hIcon1; // icon handle
POINT ptOld; // previous cursor location
HINSTANCE hinstance; // handle to current instance

//
// Perform application initialization here.
//

wc.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(400));
wc.hCursor = LoadCursor(hinstance, MAKEINTRESOURCE(200));

// Record the current cursor position.

GetCursorPos(&ptOld);

// Set the timer for the mousetrap.

uResult = SetTimer(hwnd, // handle to main window
IDT_MOUSETRAP, // timer identifier
10000, // 10-second interval
(TIMERPROC) MyTimerProc); // timer callback

if (uResult == 0)
{
ErrorHandler("No timer is available.");
}

LONG APIENTRY MainWndProc(
HWND hwnd, // handle to main window
UINT message, // type of message
WPARAM wParam, // additional information
LPARAM lParam) // additional information
{

HDC hdc; // handle to device context

switch (message)
{
//
// Process other messages.
//

case WM_DESTROY:
// Destroy the timer.

KillTimer(hwnd, IDT_MOUSETRAP);
PostQuitMessage(0);
break;

//
// Process other messages.
//

}

// MyTimerProc is an application-defined callback function that
// processes WM_TIMER messages.

VOID CALLBACK MyTimerProc(
HWND hwnd, // handle to window for timer messages
UINT message, // WM_TIMER message
UINT idTimer, // timer identifier
DWORD dwTime) // current system time
{

RECT rc;
POINT pt;

// If the window is minimized, compare the current
// cursor position with the one from 10 seconds earlier.
// If the cursor position has not changed, move the
// cursor to the icon.

if (IsIconic(hwnd))
{
GetCursorPos(&pt);

if ((pt.x == ptOld.x) && (pt.y == ptOld.y))
{
GetWindowRect(hwnd, &rc);
SetCursorPos(rc.left, rc.top);
}
else
{
ptOld.x = pt.x;
ptOld.y = pt.y;
}
}
}
goodboyws 2005-11-29
  • 打赏
  • 举报
回复
http://www.itsoul.net/article/list.asp?id=8
kugou123 2005-11-29
  • 打赏
  • 举报
回复
没有窗口,就采用回调函数的方式
lixiaosan 2005-11-29
  • 打赏
  • 举报
回复
http://www.yzcc.com/yzcc/vv/14390492158.html
DISCIP_1 2005-11-29
  • 打赏
  • 举报
回复
Settimer(0,200,NULL)
0为这个timer的index
200为毫秒单位
NULL为缺省值
killtimer相反
fibbery 2005-11-29
  • 打赏
  • 举报
回复
能够给一个没有窗口的例子?也不是用任何类!

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧