+static int Adjust( LONG *data, int new, int old , int vertical)\r
+{\r
+ // protect edges that also touch main window\r
+ if(!vertical && (old == mainRect.left || old == mainRect.right)) return 0;\r
+ if( vertical && (old == mainRect.top || old == mainRect.bottom)) return 0;\r
+ // if the coordinate was the same as the old, now make it the same as the new edge position\r
+ if(*data == old) { *data = new; return 1; }\r
+ return 0;\r
+}\r
+\r
+static void KeepTouching( int side, int new, int old, HWND hWnd )\r
+{ // if the mentioned window was touching on the moved edge, move its touching edge too\r
+ if( IsWindowVisible(hWnd) ) {\r
+ RECT rc;\r
+ int i = 0;\r
+\r
+ GetWindowRect( hWnd, &rc );\r
+\r
+ switch(side) { // figure out which edge we might need to drag along (if any)\r
+ case 1: i = Adjust(&rc.right, new, old, 0); break;\r
+ case 2: i = Adjust(&rc.left, new, old, 0); break;\r
+ case 3: i = Adjust(&rc.bottom, new, old, 1); break;\r
+ case 4: i = Adjust(&rc.top, new, old, 1); break;\r
+ }\r
+\r
+ if(i) { // the correct edge was touching, and is adjusted\r
+ SetWindowPos(hWnd, HWND_TOP, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER );\r
+ }\r
+ }\r
+}\r
+\r