Hi.
i'm writing a program without a window. i set a timer and then i go into a message queue. but nothing seems to happen any more. the timer doesn't seem to be executed (i do the timer with a timerproc not with timer window msgs). it looks like this:
if (!(TimerId = SetTimer(NULL, 1, 1000, (TIMERPROC) TimerProc)))
return FALSE;
while(TRUE)
{
GetMessage(&msg, NULL, 0, 0);
if (msg.message == WM_ENDSESSION || msg.message == WM_QUIT)
{
break;
}
}
return msg.wParam;
is there something wrong with it?
i'm writing a program without a window. i set a timer and then i go into a message queue. but nothing seems to happen any more. the timer doesn't seem to be executed (i do the timer with a timerproc not with timer window msgs). it looks like this:
if (!(TimerId = SetTimer(NULL, 1, 1000, (TIMERPROC) TimerProc)))
return FALSE;
while(TRUE)
{
GetMessage(&msg, NULL, 0, 0);
if (msg.message == WM_ENDSESSION || msg.message == WM_QUIT)
{
break;
}
}
return msg.wParam;
is there something wrong with it?
Your call to the SetTimer API has a NULL window handle so the timer will be passed to your procedure directly:
From the platform SDK:
hWnd
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
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
Specifies the time-out value, in milliseconds.
lpTimerFunc
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
From the platform SDK:
hWnd
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
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
Specifies the time-out value, in milliseconds.
lpTimerFunc
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
When you specify a TimerProc callback function, the DispatchMessage function simply calls the callback function instead of the window procedure. Therefore, you need to dispatch messages in the calling thread, even when you use TimerProc instead of processing WM_TIMER.
BTW, i'm not quite shure that you will recieve WM_ENDSESSION message from system.
.while TRUE
invoke GetMessage, addr msg, NULL, 0, 0
.break .if ( msg.message == WM_ENDSESSION || msg.message == WM_QUIT )
[color=blue]invoke DispatchMessage, addr msg[/color]
.endw
BTW, i'm not quite shure that you will recieve WM_ENDSESSION message from system.