Browse Source

re added changes made by keven that i overwrote. Attache to the window thread before setting focus

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@446 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 17 years ago
parent
commit
47bb64fb12
1 changed files with 21 additions and 1 deletions
  1. 21 1
      CP_Main.cpp

+ 21 - 1
CP_Main.cpp

@@ -420,9 +420,29 @@ bool CCP_MainApp::TargetActiveWindow()
 
 bool CCP_MainApp::ActivateTarget()
 {
-	::SetForegroundWindow(m_hTargetWnd);
+	DWORD tidTarget = ::GetWindowThreadProcessId(m_hTargetWnd, NULL);
+	DWORD tidSelf = ::GetCurrentThreadId();
+
+	// We can't set the focus window from another thread,
+	// so we have to attach to the thread input first:
+	::AttachThreadInput(tidTarget, tidSelf, TRUE);
+
 	::SetFocus(m_hTargetWnd);
 
+	//	Log( StrF(
+	//		_T("ActivateTarget - AFTER:") \
+	//		_T("\n\tm_hTargetWnd = %s") \
+	//		_T("\n\tGetForegroundWindow = %s") \
+	//		_T("\n\tGetActiveWindow = %s") \
+	//		_T("\n\tGetFocus = %s\n"),
+	//			GetParentsString(m_hTargetWnd),
+	//			GetParentsString(::GetForegroundWindow()),
+	//			GetParentsString(::GetActiveWindow()),
+	//			GetParentsString(::GetFocus()) ) );
+
+	// Detach from thread input
+	::AttachThreadInput(tidTarget, tidSelf, FALSE);
+
 	return true;
 }