server: Handle existing timer replacement when no window handle specified.

This commit is contained in:
Trent Waddington 2007-08-30 19:05:50 +10:00 committed by Alexandre Julliard
parent d4337f2b5e
commit fc635fa827
2 changed files with 48 additions and 5 deletions

View File

@ -6780,6 +6780,39 @@ static void test_timers(void)
ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
}
static int count = 0;
static VOID CALLBACK callback_count(
HWND hwnd,
UINT uMsg,
UINT_PTR idEvent,
DWORD dwTime
)
{
count++;
}
static void test_timers_no_wnd(void)
{
UINT_PTR id, id2;
MSG msg;
count = 0;
id = SetTimer(NULL, 0, 100, callback_count);
ok(id != 0, "did not get id from SetTimer.\n");
id2 = SetTimer(NULL, id, 200, callback_count);
ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
Sleep(150);
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
ok(count == 0, "did not get zero count as expected (%i).\n", count);
Sleep(150);
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
ok(count == 1, "did not get one count as expected (%i).\n", count);
KillTimer(NULL, id);
Sleep(250);
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
ok(count == 1, "killing replaced timer did not work (%i).\n", count);
}
/* Various win events with arbitrary parameters */
static const struct message WmWinEventsSeq[] = {
{ EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
@ -9617,6 +9650,7 @@ START_TEST(msg)
test_message_conversion();
test_accelerators();
test_timers();
test_timers_no_wnd();
test_set_hook();
test_DestroyWindow();
test_DispatchMessage();

View File

@ -1927,13 +1927,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 )))