我正在使用settimer來啓動定時器。每當計時器失效時,我都想更改定時器的值。 的代碼如下:無法更改定時器值
#include<iostream>
#include <windows.h>
#include <stdio.h>
#include<WinUser.h>
#pragma comment(lib, "user32.lib")
void main()
{
int id = 1;
static bool isStart = false;
static long l = 10000;
while(1)
{
int n;
MSG msg = {0};
{
SetTimer(NULL, id,l,NULL);
while(GetMessage(&msg,NULL, 0,0))
{
// Post WM_TIMER messages to the hwndTimer procedure.
if (msg.message == WM_TIMER)
{
std::cout << "Timer expired";
KillTimer(NULL, id);
msg.message = 0x0;
l = 20000;
break;
}
}
}
}
}
即使我的值更改爲20000它不是服用,計時器只設置一次。 需要幫助。
感謝
我想你的消息'msg'不會被調度到窗口。爲什麼在'GetMessage'循環不包括'在DispatchMessage(&msg);'? 此外,什麼是的#include''的需要,當你有'的#include '? –
ubuntugod
我用在DispatchMessage(&msg);還是它不工作 – anonymous
哪裏你的WM_TIMER檢查(如果(msg.message == WM_TIMER))在此塊 – ubuntugod