#include #include const WCHAR g_szClassName[] = L"TestProgram"; HINSTANCE g_hInstance; HWND g_hwnd; INT g_nCount; DWORD g_dwStyle = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_DLGFRAME | WS_POPUP; DWORD g_dwExStyle = WS_EX_TOPMOST | WS_EX_WINDOWEDGE; std::wstring g_str; LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { RECT rc; HWND hChild; switch(uMsg) { case WM_CREATE: if (g_nCount < 5) { g_nCount++; GetWindowRect(hwnd, &rc); hChild = CreateWindowExW( g_dwExStyle, g_szClassName, g_szClassName, g_dwStyle, rc.left + 10, rc.top + 10, 100, 100, hwnd, NULL, g_hInstance, NULL); ShowWindow(hChild, SW_SHOW); UpdateWindow(hChild); } else { SetTimer(hwnd, 999, 400, NULL); } break; case WM_TIMER: if (wParam == 999) { KillTimer(hwnd, 999); HWND hParent = GetParent(hwnd); if (hParent) { SetActiveWindow(hParent); DestroyWindow(hwnd); if (GetActiveWindow() == hParent) { g_str += L"success\n"; } else { g_str += L"failure\n"; } SetTimer(hParent, 999, 400, NULL); } else { DestroyWindow(hwnd); PostQuitMessage(0); } } break; default: return DefWindowProc(hwnd, uMsg, wParam, lParam); } return 0; } INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pszCmdLine, INT nCmdShow) { g_hInstance = hInstance; WNDCLASSW wc; wc.style = 0; wc.lpfnWndProc = WindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1); wc.lpszMenuName = NULL; wc.lpszClassName = g_szClassName; if (!RegisterClassW(&wc)) { MessageBoxW(NULL, L"Error: register class", NULL, MB_ICONERROR); return 1; } g_nCount = 0; g_hwnd = CreateWindowExW(g_dwExStyle, g_szClassName, g_szClassName, g_dwStyle, CW_USEDEFAULT, CW_USEDEFAULT, 100, 100, NULL, NULL, hInstance, NULL); if (g_hwnd == NULL) { MessageBoxW(NULL, L"Error: create window", NULL, MB_ICONERROR); return 2; } ShowWindow(g_hwnd, SW_SHOW); UpdateWindow(g_hwnd); MSG msg; while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } MessageBoxW(NULL, g_str.c_str(), L"result", MB_ICONINFORMATION); return (INT)msg.wParam; }