1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Windows;
5 using System.Windows.Controls;
6 using System.Windows.Data;
7 using System.Windows.Documents;
8 using System.Windows.Input;
9 using System.Windows.Media;
10 using System.Windows.Media.Imaging;
11 using System.Windows.Shapes;
12 using System.Windows.Interop;
13
14 namespace Windows
15 {
16 /// <summary>
17 /// Interaction logic for OfficeWindow.xaml
18 /// </summary>
19
20 public partial class ModernWindow : System.Windows.Window
21 {
22
23 public ModernWindow()
24 {
25 this.SourceInitialized += new EventHandler(Window1_SourceInitialized);
26 InitializeComponent();
27 }
28
29 void Window1_SourceInitialized(object sender, EventArgs e)
30 {
31
32 HwndSource hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource;
33
34 hwndSource.AddHook(new HwndSourceHook(WndProc));
35
36 }
37 private const int WM_NCHITTEST = 0x0084;
38
39 private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
40 {
41
42 if (msg == WM_NCHITTEST)
43 {
44
45 int xPos = GET_X_LPARAM(lParam.ToInt32());
46
47 int yPos = GET_Y_LPARAM(lParam.ToInt32());
48
49 double xIn = xPos - this.Left;
50
51 double yIn = yPos - this.Top;
52
53 System.Diagnostics.Debug.WriteLine("x:" + xIn.ToString() + " y:" + yIn.ToString());
54
55 if (xIn < 2)
56 {
57
58 handled = true;
59
60 return new IntPtr((int)HitTest.HTLEFT);
61
62 }
63
64 }
65
66 return IntPtr.Zero;
67
68 }
69
70 public static Int32 GET_X_LPARAM(int lParam)
71 {
72
73 return (lParam & 0xffff);
74
75 }
76
77 public static Int32 GET_Y_LPARAM(int lParam)
78 {
79
80 return (lParam >> 16);
81
82 }
83
84 public enum HitTest
85 {
86
87 HTERROR = -2,
88
89 HTTRANSPARENT = -1,
90
91 HTNOWHERE = 0,
92
93 HTCLIENT = 1,
94
95 HTCAPTION = 2,
96
97 HTSYSMENU = 3,
98
99 HTGROWBOX = 4,
100
101 HTSIZE = HTGROWBOX,
102
103 HTMENU = 5,
104
105 HTHSCROLL = 6,
106
107 HTVSCROLL = 7,
108
109 HTMINBUTTON = 8,
110
111 HTMAXBUTTON = 9,
112
113 HTLEFT = 10,
114
115 HTRIGHT = 11,
116
117 HTTOP = 12,
118
119 HTTOPLEFT = 13,
120
121 HTTOPRIGHT = 14,
122
123 HTBOTTOM = 15,
124
125 HTBOTTOMLEFT = 16,
126
127 HTBOTTOMRIGHT = 17,
128
129 HTBORDER = 18,
130
131 HTREDUCE = HTMINBUTTON,
132
133 HTZOOM = HTMAXBUTTON,
134
135 HTSIZEFIRST = HTLEFT,
136
137 HTSIZELAST = HTBOTTOMRIGHT,
138
139 HTOBJECT = 19,
140
141 HTCLOSE = 20,
142
143 HTHELP = 21,
144
145 }
146
147
148
149
150
151
152
153 bool isWiden = false;
154 private void window_initiateWiden(object sender, System.Windows.Input.MouseEventArgs e)
155 {
156 isWiden = true;
157 }
158 private void window_endWiden(object sender, System.Windows.Input.MouseEventArgs e)
159 {
160 isWiden = false;
161
162 // Make sure capture is released.
163 Rectangle rect = (Rectangle)sender;
164 rect.ReleaseMouseCapture();
165 }
166
167 private void window_Widen(object sender, System.Windows.Input.MouseEventArgs e)
168 {
169 Rectangle rect = (Rectangle)sender;
170 if (isWiden)
171 {
172 rect.CaptureMouse();
173 double newWidth = e.GetPosition(this).X + 2;
174 double newHeight = e.GetPosition(this).Y + 2;
175 if (newWidth > 0)
176 {
177 this.Width = newWidth;
178 this.Height = newHeight;
179 }
180 }
181 }
182
183 private void titleBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
184 {
185 this.DragMove();
186 }
187
188 private void cmdClose_Click(object sender, RoutedEventArgs e)
189 {
190 this.Close();
191 }
192 }
193 }