能力值:
( LV3,RANK:30 )
2 楼
先看MSDN:
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.
控制台程序没有消息循环,自然处理不到WM_TIMER消息
能力值:
( LV9,RANK:210 )
3 楼
楼上理解好像有误, 并不是每一个定时器都需要消息循环的, 只要正确指定了定时处理的回调函数,我在VC下,经常这样用(完全没有窗口和消息循环).
建议LZ好好查检查一下程序,应该是可行的,Delphi程序语法格式我不是很清楚......
能力值:
( LV13,RANK:1050 )
4 楼
呵呵,不懂delphi.我用vc写了一个,你参考。这个可以运行。
#include "windows.h"
void CALLBACK ProgTimer(HWND hwnd,
UINT uMsg,
UINT idEvent,
DWORD dwTime )
{
MessageBeep(-1);
}
int main(int argc, char* argv[])
{
MSG msg;
SetTimer(NULL,100,1000,(TIMERPROC)ProgTimer);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
对于控制台的程序,只要在主程序中加入消息循环就可以了。
能力值:
( LV3,RANK:30 )
5 楼
楼上的combojiang兄已经给答案了
估计szdbg兄是在MFC程序里用的SetTimer,不是没有消息循环,是MFC把它给隐藏了
能力值:
( LV3,RANK:20 )
6 楼
问题已经解决,正如combojang兄所说的那样。
还是看雪高手多啊,我在盒子和csdn 发得帖都没有人回。。
能力值:
( LV9,RANK:430 )
7 楼
厉害,又学到点有用的东西了。
能力值:
( LV2,RANK:10 )
8 楼
定时器我不会用~~老大能不能解释一下呀!!!!!
能力值:
( LV4,RANK:50 )
9 楼
看雪的高人云集,路过,学习了!!
Delphi版本,测试通过,不知有没有其它问题
program TestDll;
uses
windows;
Var
MSG:TMSG;
procedure CallBack;
begin
MEssageBeep(0);
end;
begin
SetTimer(0,100,1000,@CallBack);
While GetMessage(Msg,0,0,0) do
begin
TranslateMessage(msg);
DispatchMessage(msg);
end;
end.
能力值:
( LV3,RANK:30 )
10 楼
楼上的兄弟正解
能力值:
( LV9,RANK:250 )
11 楼
不知道楼主这样去find drive是为了实现感染,还是实现免疫?