News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Not satisfied SetTime?

Started by ikudesnik, September 03, 2015, 10:48:56 PM

Previous topic - Next topic

dedndave

приложение окно необходимо использовать SetTimer

dedndave

Эта программа создает и окно GUI и окно консоли.
Окно графического интерфейса используется для таймера, и окно консоли для отображения используется.
Окно GUI не видно.

TWell

#32
With another API function and C#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
//https://msdn.microsoft.com/en-us/library/windows/desktop/ms687003(v=vs.85).aspx
VOID CALLBACK TimerRoutine(PVOID lpParam, BOOLEAN TimerOrWaitFired)
{
printf("#");
}
int main(void)
{
HANDLE hQueue,hTimer;
if ((hQueue = CreateTimerQueue()) != 0) {
CreateTimerQueueTimer(&hTimer,hQueue,(WAITORTIMERCALLBACK)TimerRoutine,0,1000,1000,0);
while (getchar() != 10);
DeleteTimerQueueTimer(hQueue,hTimer,INVALID_HANDLE_VALUE);
DeleteTimerQueue(hQueue);
}
return 0;
}

jj2007

Quote from: TWell on September 05, 2015, 03:59:13 PM
With another API function and C#define WIN32_LEAN_AND_MEAN

Works like a charm BUT:
warning #2030: '=' used in a conditional expression:
   if (hQueue = CreateTimerQueue()) {

Is that intentional? When using == it stops working ::)

TWell

Fixed(hQueue = CreateTimerQueue()) != 0

jj2007

OK, so you are assigning and testing for errors at the same time.

Here is the assembler version:

include \masm32\include\masm32rt.inc

.code
TimerRoutine proc lParam, TimerOrWaitFired
  print "#"
  ret
TimerRoutine endp

start:
  print "Timer in console:", 13, 10
  invoke CreateTimerQueue
  push eax ; save hTimerQueue
  push eax ; create slot for hTimer
  mov ecx, esp
  invoke CreateTimerQueueTimer, ecx, eax, TimerRoutine, 0, 127, 127, 0
  push eax ; timer-queue timer
  .Repeat
getkey
push eax
print esp
pop eax
  .Until al==VK_ESCAPE
  print "*", 13, 10
  pop eax ; timer-queue timer
  pop ecx ; hTimer
  invoke DeleteTimerQueueTimer, eax, ecx, INVALID_HANDLE_VALUE
  call DeleteTimerQueue ; invoke DeleteTimerQueue, [esp]
  print LastError$()
  invoke Sleep, 2000
  exit
end start

TWell

Thanks, i forgot thatDeleteTimerQueueTimer(hQueue,hTimer,INVALID_HANDLE_VALUE);

jj2007

MSDN:
QuoteCompletionEvent [in, optional]

    If this parameter is INVALID_HANDLE_VALUE, the function waits for any running timer callback functions to complete before returning.

    If this parameter is NULL, the function marks the timer for deletion and returns immediately.

Programmers at work in Redmond:
Quote"Ok, let's take -1 for 'complete before returning'"
"No, you can't call it -1, give it a proper name"
"Oh well, -1... let me think ... INVALID_HANDLE_VALUE?"
;)