Browse Source

if GetGuiThreadInfo doesn't work use the attach to thread, getcaret, detach method to get caret position

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@523 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 15 years ago
parent
commit
fa388211b8
2 changed files with 18 additions and 1 deletions
  1. 17 0
      ExternalWindowTracker.cpp
  2. 1 1
      QuickPaste.cpp

+ 17 - 0
ExternalWindowTracker.cpp

@@ -322,6 +322,23 @@ CPoint ExternalWindowTracker::FocusCaret()
 				::ClientToScreen(m_focusWnd, &pt);
 			}
 		}
+
+		if(pt.x < 0 || pt.y < 0)
+		{
+			if(m_focusWnd != NULL &&
+				m_activeWnd != NULL &&
+				AttachThreadInput(GetWindowThreadProcessId(m_activeWnd, NULL), GetCurrentThreadId(), TRUE))
+			{
+				BOOL ret = GetCaretPos(&pt);
+				if(ret  && (pt.x > 0 || pt.y > 0))
+				{
+					ClientToScreen(m_focusWnd, &pt);
+					pt.y += 20;
+				}
+
+				AttachThreadInput(GetWindowThreadProcessId(m_activeWnd, NULL), GetCurrentThreadId(), FALSE);
+			}
+		}
 	}
 
 	return pt;

+ 1 - 1
QuickPaste.cpp

@@ -132,7 +132,7 @@ void CQuickPaste::ShowQPasteWnd(CWnd *pParent, bool bAtPrevPos, bool bFromKeyboa
 	if(ptCaret.x <= 0 || ptCaret.y <= 0)
 	{
 		CRect cr;
-		::GetWindowRect(theApp.m_activeWnd.FocusWnd(), cr);
+		::GetWindowRect(theApp.m_activeWnd.ActiveWnd(), cr);
 		if(cr.PtInRect(ptCaret) == FALSE)
 		{
 			ptCaret = cr.CenterPoint();