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"); 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 */ /* Various win events with arbitrary parameters */
static const struct message WmWinEventsSeq[] = { static const struct message WmWinEventsSeq[] = {
{ EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 }, { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
@ -9617,6 +9650,7 @@ START_TEST(msg)
test_message_conversion(); test_message_conversion();
test_accelerators(); test_accelerators();
test_timers(); test_timers();
test_timers_no_wnd();
test_set_hook(); test_set_hook();
test_DestroyWindow(); test_DestroyWindow();
test_DispatchMessage(); test_DispatchMessage();

View File

@ -1927,6 +1927,14 @@ DECL_HANDLER(set_win_timer)
else else
{ {
queue = get_current_queue(); queue = get_current_queue();
/* look for a timer with this id */
if (id && (timer = find_timer( queue, NULL, req->msg, id )))
{
/* free and reuse id */
free_timer( queue, timer );
}
else
{
/* find a free id for it */ /* find a free id for it */
do do
{ {
@ -1935,6 +1943,7 @@ DECL_HANDLER(set_win_timer)
} }
while (find_timer( queue, 0, req->msg, id )); while (find_timer( queue, 0, req->msg, id ));
} }
}
if ((timer = set_timer( queue, req->rate ))) if ((timer = set_timer( queue, req->rate )))
{ {