Browse Source

check for empty rect if cursor position fails, if so center over active window

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@535 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 15 years ago
parent
commit
6eec0f2317
1 changed files with 23 additions and 3 deletions
  1. 23 3
      QuickPaste.cpp

+ 23 - 3
QuickPaste.cpp

@@ -136,9 +136,29 @@ void CQuickPaste::ShowQPasteWnd(CWnd *pParent, bool bAtPrevPos, bool bFromKeyboa
 		CRect cr;
 		::GetWindowRect(theApp.m_activeWnd.ActiveWnd(), cr);
 		
-		ptCaret = cr.CenterPoint();
-		ptCaret.x -= csSize.cx/2;
-		ptCaret.y -= csSize.cy/2;
+		if(cr.Width() > 0 && cr.Height() > 0)
+		{
+			ptCaret = cr.CenterPoint();
+			ptCaret.x -= csSize.cx/2;
+			ptCaret.y -= csSize.cy/2;
+		}
+		else
+		{
+			GetCursorPos(&point);
+
+			CRect crPoint(point, CSize(1, 1));
+
+			int nMonitor = GetMonitorFromRect(crPoint);
+			if(nMonitor >= 0)
+			{
+				CRect crMonitor;
+				GetMonitorRect(nMonitor, crMonitor);
+
+				ptCaret = crMonitor.CenterPoint();
+				ptCaret.x -= csSize.cx/2;
+				ptCaret.y -= csSize.cy/2;
+			}
+		}
 	}
 	
 	if(bAtPrevPos)