Handle existing timer replacement when no window handle specified

Trent Waddington trent.waddington at gmail.com
Wed Aug 29 01:12:17 CDT 2007


Documentation at

http://msdn2.microsoft.com/en-us/library/ms644906.aspx

says:

nIDEvent
    [in] Specifies a nonzero timer identifier. If the hWnd parameter
is NULL, and the nIDEvent does not match an existing timer then it is
ignored and a new timer ID is generated. 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. If the call is not intended
to replace an existing timer, nIDEvent should be 0 if the hWnd is
NULL.

The requirement in the second sentence was not implemented.

Test case (also tests other SetTimer invokations):

http://rtfm.insomnia.org/~qg/testsettimer.cpp
http://rtfm.insomnia.org/~qg/testsettimer.exe

Patch attached.

Trent
-------------- next part --------------
From 72386f999883ca465c8a684ee87d1ec3bfbf065b Mon Sep 17 00:00:00 2001
From: Trent Waddington <trent.waddington at gmail.com>
Date: Wed, 29 Aug 2007 16:05:56 +1000
Subject: Handle existing timer replacement when no window handle specified.

---
 server/queue.c |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/server/queue.c b/server/queue.c
index 3220fcb..3efb44f 100644
--- a/server/queue.c
+++ b/server/queue.c
@@ -1925,13 +1925,22 @@ DECL_HANDLER(set_win_timer)
     else
     {
         queue = get_current_queue();
-        /* find a free id for it */
-        do
+        /* look for a timer with this id */
+        if (id && (timer = find_timer( queue, NULL, req->msg, id )))
         {
-            id = queue->next_timer_id;
-            if (++queue->next_timer_id >= 0x10000) queue->next_timer_id = 1;
+            /* free and reuse id */
+            free_timer( queue, timer );
+        }
+        else 
+        {
+            /* find a free id for it */
+            do
+            {
+                id = queue->next_timer_id;
+                if (++queue->next_timer_id >= 0x10000) queue->next_timer_id = 1;
+            }
+            while (find_timer( queue, 0, req->msg, id ));
         }
-        while (find_timer( queue, 0, req->msg, id ));
     }
 
     if ((timer = set_timer( queue, req->rate )))
-- 
1.4.4.3


More information about the wine-patches mailing list