激活_目标窗口
1、http://blog.csdn.net/oxunfeng/article/details/52681279
1. ::ShowWindow(m_hWnd, SW_SHOWNORMAL); 2. ::SetActiveWindow(main_window_->m_hWnd); 3. ::SetForegroundWindow(main_window_->m_hWnd); 4. ::SwitchToThisWindow(main_window_->m_hWnd, TRUE); 5. ::SetWindowPos // 以上几种方法在部分系统下仍旧可能出问题,推荐以下方法 兼容性较好 HWND hCurWnd = ::GetForegroundWindow(); DWORD dwMyID = ::GetCurrentThreadId(); DWORD dwCurID = ::GetWindowThreadProcessId(hCurWnd, NULL); ::AttachThreadInput(dwCurID, dwMyID, TRUE); ::SetForegroundWindow(main_window_->m_hWnd); ::AttachThreadInput(dwCurID, dwMyID, FALSE);
2、我的代码:(_hDestWnd 是要激活的目标窗口的窗口句柄)
procedure TfrmMain.Wnd_Active(_hDestWnd: HWnd); var dwMyThreadID :DWORD; dwDestThreadID :DWORD; begin// http://blog.csdn.net/oxunfeng/article/details/52681279 dwMyThreadID := GetCurrentThreadId(); dwDestThreadID := GetWindowThreadProcessId(_hDestWnd, nil); AttachThreadInput(dwDestThreadID, dwMyThreadID, TRUE); SetForegroundWindow(_hDestWnd); AttachThreadInput(dwDestThreadID, dwMyThreadID, FALSE); end;
3、