#define _WIN32_WINNT 0x0501 #define _WIN32_IE 0x0501 #include #include #define BUGGY_TIMER_ID 1 static HWND g_hwndButton; static HWND g_hwndTip; static HWND g_hwndMain; LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, msg, wParam, lParam); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { INITCOMMONCONTROLSEX icex; icex.dwSize = sizeof(INITCOMMONCONTROLSEX); icex.dwICC = ICC_WIN95_CLASSES | ICC_STANDARD_CLASSES; InitCommonControlsEx(&icex); WNDCLASSA wc; memset(&wc, 0, sizeof(wc)); wc.lpfnWndProc = WndProc; wc.hInstance = hInstance; wc.hCursor = LoadCursorA(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wc.lpszClassName = "TooltipBugClass"; if (!RegisterClassA(&wc)) { MessageBoxA(NULL, "Failed to register window class", "Error", MB_OK | MB_ICONERROR); return 1; } g_hwndMain = CreateWindowExA( 0, "TooltipBugClass", "Tooltip Race Condition Demo", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 450, 200, NULL, NULL, hInstance, NULL ); if (!g_hwndMain) { MessageBoxA(NULL, "Failed to create main window", "Error", MB_OK | MB_ICONERROR); return 1; } HWND hwndLabel = CreateWindowExA( 0, "STATIC", "BUG TEST: Hover over button for ~300ms, then click!\n\n" "Expected: Tooltip should abort when you click.\n" "Bug: Tooltip still appears because timer wasn't killed.", WS_CHILD | WS_VISIBLE, 20, 15, 400, 80, g_hwndMain, NULL, hInstance, NULL ); g_hwndButton = CreateWindowExA( 0, "BUTTON", "Hover ~300ms then CLICK me!", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 70, 95, 280, 35, g_hwndMain, (HMENU)1, hInstance, NULL ); g_hwndTip = CreateWindowExA( WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, g_hwndMain, NULL, hInstance, NULL ); TOOLINFOA ti; memset(&ti, 0, sizeof(ti)); ti.cbSize = sizeof(TOOLINFOA); ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS; ti.hwnd = g_hwndMain; ti.uId = (UINT_PTR)g_hwndButton; ti.lpszText = "BUG TRIGGERED! This tooltip should NOT show after click!"; SendMessageA(g_hwndTip, TTM_ADDTOOL, 0, (LPARAM)&ti); SendMessageA(g_hwndTip, TTM_SETDELAYTIME, TTDT_INITIAL, 300); MSG msg; while (GetMessageA(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessageA(&msg); } return (int)msg.wParam; }