[Windows 7, MVS 2010]
Не удается активировать окно с помощью функции SetActiveWindow().
The SetActiveWindow function activates a window. The window must be attached to the calling thread's message queue.
By using the AttachThreadInput function, a thread can attach its input processing to another thread. This allows a thread to call SetActiveWindow to activate a window attached to another thread's message queue.
Имеется окно под многими остальными на рабочем столе. Задача — вывести его "наверх" и активировать. Следующий код не работает в конфигурации
Release, но работает в
Debug:
DWORD idAttach = GetWindowThreadProcessId(hwnd, &pid);
DWORD idAttachTo = GetCurrentThreadId();
bRes = AttachThreadInput(idAttach, idAttachTo, TRUE);
HWND hWndPrev = SetActiveWindow(hwnd);
AttachThreadInput(idAttach, idAttachTo, FALSE);
Т.е., при отладке нужное окно удается "вытащить" наверх активированным, а в релизе никакой реакции.
Если заменить весь вышеприведенный код одним вызовом SetForegroundWindow(hwnd), то окно просто начинает мигать в трее.