#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; std::wstring c_str; LRESULT CALLBACK WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { RECT rc; RECT rcl; HDC hdc ; HWND hChild; PAINTSTRUCT ps ; switch(uMsg) { case WM_CREATE: if (g_nCount < 4) { g_nCount++; GetWindowRect(hwnd,&rc); hChild= CreateWindowEx( 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,5000,NULL); } break; case WM_PAINT: WCHAR cl[600]; hdc = BeginPaint (hwnd, &ps) ; wsprintf(cl,L"%i",hwnd); GetClientRect (hwnd, &rcl) ; DrawText (hdc, cl, -1, &rcl, DT_SINGLELINE | DT_CENTER | DT_VCENTER) ; EndPaint (hwnd, &ps) ; return 0 ; case WM_TIMER: if(wParam==999) { KillTimer(hwnd,999); HWND hParent=GetParent(hwnd); HWND hPrev; WCHAR chwnd[200]; if(hParent) { hPrev=SetActiveWindow(hParent); DestroyWindow(hwnd); wsprintf(chwnd,L"EXTRA hPrev: %i \n hwnd: %i \n hParent: %i \n GetActiveWindow: %i \n",hPrev,hwnd,hParent, GetActiveWindow()); g_str +=chwnd; if(GetActiveWindow()==hParent) { g_str +=L"success \n\n"; } else { g_str +=L"failure \n\n"; } SetTimer(hParent,999,5000,NULL); } else { DestroyWindow(hwnd); PostQuitMessage(0); } } break; default: return DefWindowProc(hwnd, uMsg, wParam, lParam); } return 0; } INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrecInstance, 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.lpszClassName=g_szClassName; if(!RegisterClass(&wc)) { MessageBoxW(NULL, L"Error: register class",NULL, MB_ICONERROR); return 1; } g_hwnd= CreateWindowExW(g_dwExStyle,g_szClassName, g_szClassName, g_dwStyle, CW_USEDEFAULT,CW_USEDEFAULT,300,300, NULL,NULL,hInstance, NULL); g_nCount=0; 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; }