浏览代码

window snaps to desktop sides

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@22 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 22 年之前
父节点
当前提交
fae2956cbc
共有 2 个文件被更改,包括 39 次插入0 次删除
  1. 38 0
      QPasteWnd.cpp
  2. 1 0
      QPasteWnd.h

+ 38 - 0
QPasteWnd.cpp

@@ -86,6 +86,7 @@ BEGIN_MESSAGE_MAP(CQPasteWnd, CWndEx)
 	ON_MESSAGE(NM_SELECT_INDEX, OnListSelect_Index)
 	ON_MESSAGE(NM_SELECT_INDEX, OnListSelect_Index)
 	ON_MESSAGE(WM_REFRESH_VIEW, OnRefreshView)
 	ON_MESSAGE(WM_REFRESH_VIEW, OnRefreshView)
 	ON_WM_NCLBUTTONDBLCLK()
 	ON_WM_NCLBUTTONDBLCLK()
+	ON_WM_WINDOWPOSCHANGING()
 END_MESSAGE_MAP()
 END_MESSAGE_MAP()
 
 
 
 
@@ -1087,3 +1088,40 @@ void CQPasteWnd::OnNcLButtonDblClk(UINT nHitTest, CPoint point)
 
 
 	CWndEx::OnNcLButtonDblClk(nHitTest, point);
 	CWndEx::OnNcLButtonDblClk(nHitTest, point);
 }
 }
+
+#define WNDSNAP_ALLOWANCE 12
+
+void CQPasteWnd::OnWindowPosChanging(WINDOWPOS* lpwndpos)
+{
+	CWndEx::OnWindowPosChanging(lpwndpos);
+
+	RECT rcScreen;
+
+	// Get cordinates of the working area on the screen
+	SystemParametersInfo (SPI_GETWORKAREA, 0, &rcScreen, 0);
+
+	// Snap X axis to left
+	if(abs(lpwndpos->x - rcScreen.left) <= WNDSNAP_ALLOWANCE)
+	{
+		lpwndpos->x = rcScreen.left;
+	}
+
+	// Snap X axis to right
+	if (abs(lpwndpos->x + lpwndpos->cx - rcScreen.right) <= WNDSNAP_ALLOWANCE)
+	{
+		lpwndpos->x = rcScreen.right - lpwndpos->cx;
+	}
+
+	// Snap Y axis to top
+	if (abs(lpwndpos->y - rcScreen.top) <= WNDSNAP_ALLOWANCE)
+	{
+		// Assign new cordinate
+		lpwndpos->y = rcScreen.top;
+	} 
+
+	// Snap Y axis to bottom
+	if (abs(lpwndpos->y + lpwndpos->cy - rcScreen.bottom) <= WNDSNAP_ALLOWANCE)
+	{
+		lpwndpos->y = rcScreen.bottom - lpwndpos->cy;
+	}
+}

+ 1 - 0
QPasteWnd.h

@@ -125,6 +125,7 @@ protected:
 	DECLARE_MESSAGE_MAP()
 	DECLARE_MESSAGE_MAP()
 public:
 public:
 	afx_msg void OnNcLButtonDblClk(UINT nHitTest, CPoint point);
 	afx_msg void OnNcLButtonDblClk(UINT nHitTest, CPoint point);
+	afx_msg void OnWindowPosChanging(WINDOWPOS* lpwndpos);
 };
 };