markus / KCOM / MainWindow.xaml.cs @ 97cde7e3
이력 | 보기 | 이력해설 | 다운로드 (23.4 KB)
1 | 787a4489 | KangIngu | using KCOM.Common; |
---|---|---|---|
2 | 32af2c3b | djkim | using KCOM.Controls; |
3 | 264c9309 | ljiyeon | using KCOM.Views; |
4 | 787a4489 | KangIngu | using KCOMDataModel; |
5 | using KCOMDataModel.DataModel; |
||
6 | b0fb3ad7 | ljiyeon | using MarkupToPDF.Common; |
7 | 5529d2a2 | humkyung | using MarkupToPDF.Controls.Parsing; |
8 | b0fb3ad7 | ljiyeon | using MarkupToPDF.Serialize.Core; |
9 | using MarkupToPDF.Serialize.S_Control; |
||
10 | 787a4489 | KangIngu | using System; |
11 | using System.Collections.Generic; |
||
12 | 264c9309 | ljiyeon | using System.ComponentModel; |
13 | using System.Diagnostics; |
||
14 | 6707a5c7 | ljiyeon | using System.IO; |
15 | 787a4489 | KangIngu | using System.Linq; |
16 | 264c9309 | ljiyeon | using System.Net; |
17 | using System.Reflection; |
||
18 | 71bfd53e | ljiyeon | using System.Runtime.InteropServices; |
19 | 787a4489 | KangIngu | using System.Text; |
20 | 264c9309 | ljiyeon | using System.Threading; |
21 | using System.Threading.Tasks; |
||
22 | 787a4489 | KangIngu | using System.Windows; |
23 | using System.Windows.Controls; |
||
24 | using System.Windows.Data; |
||
25 | using System.Windows.Documents; |
||
26 | using System.Windows.Input; |
||
27 | using System.Windows.Media; |
||
28 | using System.Windows.Media.Imaging; |
||
29 | using System.Windows.Navigation; |
||
30 | using System.Windows.Shapes; |
||
31 | 6707a5c7 | ljiyeon | using System.Xml; |
32 | 992a98b4 | KangIngu | using Telerik.Windows.Controls; |
33 | 7e2d29a0 | ljiyeon | using WinInterop = System.Windows.Interop; |
34 | 787a4489 | KangIngu | |
35 | namespace KCOM |
||
36 | { |
||
37 | /// <summary> |
||
38 | /// MainWindow.xaml에 대한 상호 작용 논리 |
||
39 | /// </summary> |
||
40 | public partial class MainWindow : Window |
||
41 | { |
||
42 | 32af2c3b | djkim | bool isSaveCheck = false; |
43 | bool isUpdateCheck = false; |
||
44 | ProgressControl progressControl = null; |
||
45 | string destfilepath = string.Empty; |
||
46 | |||
47 | 787a4489 | KangIngu | public MainWindow() |
48 | { |
||
49 | e0cfc73c | ljiyeon | App.splashString(ISplashMessage.MAINWINDOW); |
50 | 787a4489 | KangIngu | this.Loaded += MainWindow_Loaded; |
51 | this.KeyDown += new KeyEventHandler(KeyEventDownAction); |
||
52 | this.KeyUp += new KeyEventHandler(KeyEventUpAction); |
||
53 | 7e2d29a0 | ljiyeon | this.SourceInitialized += new EventHandler(win_SourceInitialized); |
54 | 787a4489 | KangIngu | } |
55 | ca16abb2 | ljiyeon | |
56 | public static BitmapImage CursorChange() |
||
57 | { |
||
58 | BitmapImage bmp = new BitmapImage(); |
||
59 | bmp.BeginInit(); |
||
60 | bmp.StreamSource = System.Windows.Application.GetResourceStream(new Uri("/KCOM;Component/Resources/Cursor/customCursor2.cur", UriKind.Relative)).Stream; |
||
61 | return bmp; |
||
62 | } |
||
63 | |||
64 | 787a4489 | KangIngu | public void DialogMessage_Alert(string content, string header) |
65 | { |
||
66 | var box = new TextBlock(); |
||
67 | box.MinWidth = 400; |
||
68 | box.FontSize = 12; |
||
69 | box.Text = content; |
||
70 | box.TextWrapping = System.Windows.TextWrapping.Wrap; |
||
71 | |||
72 | Telerik.Windows.Controls.DialogParameters parameters = new Telerik.Windows.Controls.DialogParameters() |
||
73 | { |
||
74 | b9b01f8e | ljiyeon | Owner = Application.Current.MainWindow, |
75 | 787a4489 | KangIngu | Content = box, |
76 | Header = header, |
||
77 | Theme = new Telerik.Windows.Controls.VisualStudio2013Theme(), |
||
78 | ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 }, |
||
79 | }; |
||
80 | Telerik.Windows.Controls.RadWindow.Alert(parameters); |
||
81 | } |
||
82 | 7e2d29a0 | ljiyeon | |
83 | 787a4489 | KangIngu | private void MainWindow_Loaded(object sender, RoutedEventArgs e) |
84 | { |
||
85 | 0c997b99 | ljiyeon | InitializeComponent(); |
86 | ca16abb2 | ljiyeon | |
87 | //cursor change |
||
88 | this.Cursor = new Cursor(CursorChange().StreamSource); |
||
89 | |||
90 | 787a4489 | KangIngu | double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth; |
91 | double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight; |
||
92 | 9f473fb7 | KangIngu | //this.Width += 40; |
93 | 787a4489 | KangIngu | double windowWidth = this.Width; |
94 | double windowHeight = this.Height; |
||
95 | this.Left = (screenWidth / 2) - (windowWidth / 2); |
||
96 | this.Top = (screenHeight / 2) - (windowHeight / 2); |
||
97 | |||
98 | ViewerDataModel.Instance.SystemMain = this; |
||
99 | |||
100 | if (!App.ParameterMode) |
||
101 | { |
||
102 | //App.ViewInfo = new IKCOM.ViewInfo |
||
103 | //{ |
||
104 | // DocumentItemID = "11111112", |
||
105 | // //DocumentItemID = "10001", |
||
106 | // bPartner = false, |
||
107 | // CreateFinalPDFPermission = true, |
||
108 | // NewCommentPermission = true, |
||
109 | // ProjectNO = "000000", |
||
110 | // UserID = "H2011357", |
||
111 | // //UserID = "H2009115", |
||
112 | // //Mode = 0 , 1 , 2 |
||
113 | //}; |
||
114 | //DialogMessage_Alert("데모버전은 단독 실행모드를 지원하지 않습니다", "안내"); |
||
115 | |||
116 | 7e2d29a0 | ljiyeon | //#if DEBUG |
117 | // App.ViewInfo = new IKCOM.ViewInfo |
||
118 | // { |
||
119 | // DocumentItemID = "11111112", |
||
120 | // //DocumentItemID = "10001", |
||
121 | // bPartner = false, |
||
122 | // CreateFinalPDFPermission = true, |
||
123 | // NewCommentPermission = true, |
||
124 | // ProjectNO = "000000", |
||
125 | // UserID = "H2011357", |
||
126 | // //UserID = "H2009115", |
||
127 | // //Mode = 0 , 1 , 2 |
||
128 | // }; |
||
129 | // App.ParameterMode = true; |
||
130 | // this.dzMainMenu.ServiceOn(); |
||
131 | // this.dzMainMenu.SetView(App.ViewInfo); |
||
132 | //#else |
||
133 | 787a4489 | KangIngu | |
134 | DialogMessage_Alert("데모버전은 단독 실행모드를 지원하지 않습니다", "안내"); |
||
135 | this.dzMainMenu.pageNavigator.Visibility = Visibility.Collapsed; |
||
136 | this.dzMainMenu.historyPane.Visibility = Visibility.Collapsed; |
||
137 | this.dzMainMenu.infoListPane.Visibility = Visibility.Collapsed; |
||
138 | this.dzMainMenu.searchPane.Visibility = Visibility.Collapsed; |
||
139 | this.dzMainMenu.talkPane.Visibility = Visibility.Collapsed; |
||
140 | 7e2d29a0 | ljiyeon | //#endif |
141 | 787a4489 | KangIngu | } |
142 | else |
||
143 | { |
||
144 | this.dzMainMenu.ServiceOn(); |
||
145 | 992a98b4 | KangIngu | |
146 | if (!App.ViewInfo.CreateFinalPDFPermission && !App.ViewInfo.NewCommentPermission) |
||
147 | { |
||
148 | this.dzTopMenu.radRibbonView.HelpButtonVisibility = Visibility.Collapsed; |
||
149 | var list = this.dzTopMenu.ChildrenOfType<RadRibbonTab>().ToList(); |
||
150 | list.ForEach(item => item.Visibility = Visibility.Collapsed); |
||
151 | this.dzTopMenu.ribbontab_ReadOnly.Visibility = Visibility.Visible; |
||
152 | this.dzTopMenu.radRibbonView.SelectedItem = this.dzTopMenu.ribbontab_ReadOnly; |
||
153 | e0204db0 | djkim | //this.dzMainMenu.SymbolPane.Visibility = Visibility.Collapsed; |
154 | //this.dzMainMenu.FavoritePane.Visibility = Visibility.Collapsed; |
||
155 | //this.dzMainMenu.drawingRotateCanvas.IsHitTestVisible = false; |
||
156 | 992a98b4 | KangIngu | } |
157 | 787a4489 | KangIngu | this.dzMainMenu.SetView(App.ViewInfo); |
158 | 7e2d29a0 | ljiyeon | this.dzMainMenu.HubSet(); |
159 | 787a4489 | KangIngu | } |
160 | 6707a5c7 | ljiyeon | |
161 | 787a4489 | KangIngu | //App.ViewInfo = new IKCOM.ViewInfo |
162 | //{ |
||
163 | // DocumentItemID = "11111112", |
||
164 | // //DocumentItemID = "10001", |
||
165 | // bPartner = false, |
||
166 | // CreateFinalPDFPermission = true, |
||
167 | // NewCommentPermission = true, |
||
168 | // ProjectNO = "000000", |
||
169 | // UserID = "H2011357", |
||
170 | // //UserID = "H2009115", |
||
171 | // //Mode = 0 , 1 , 2 |
||
172 | //}; |
||
173 | |||
174 | //this.dzMainMenu.ServiceOn(); |
||
175 | //this.dzMainMenu.SetView(App.ViewInfo); |
||
176 | } |
||
177 | 6707a5c7 | ljiyeon | |
178 | 71bfd53e | ljiyeon | |
179 | 7e2d29a0 | ljiyeon | bool restoreIfMove = false; |
180 | 71bfd53e | ljiyeon | |
181 | 787a4489 | KangIngu | private void WindowDragEvent(object sender, MouseButtonEventArgs e) |
182 | { |
||
183 | 32af2c3b | djkim | if(string.IsNullOrEmpty(destfilepath)) |
184 | 787a4489 | KangIngu | { |
185 | 264c9309 | ljiyeon | if (e.ClickCount == 2) |
186 | 787a4489 | KangIngu | { |
187 | 264c9309 | ljiyeon | if ((ResizeMode == ResizeMode.CanResize) || |
188 | (ResizeMode == ResizeMode.CanResizeWithGrip)) |
||
189 | { |
||
190 | SwitchState(); |
||
191 | } |
||
192 | 787a4489 | KangIngu | } |
193 | 264c9309 | ljiyeon | else |
194 | 71bfd53e | ljiyeon | { |
195 | 264c9309 | ljiyeon | if (WindowState == WindowState.Maximized) |
196 | { |
||
197 | restoreIfMove = true; |
||
198 | } |
||
199 | 3933072f | ljiyeon | |
200 | 264c9309 | ljiyeon | this.DragMove(); |
201 | } |
||
202 | } |
||
203 | 787a4489 | KangIngu | } |
204 | |||
205 | 71bfd53e | ljiyeon | private void WindowDragEventUp(object sender, MouseButtonEventArgs e) |
206 | { |
||
207 | restoreIfMove = false; |
||
208 | } |
||
209 | |||
210 | private void WindowDragEventMove(object sender, MouseEventArgs e) |
||
211 | { |
||
212 | if (restoreIfMove) |
||
213 | { |
||
214 | if (Mouse.LeftButton == MouseButtonState.Pressed) |
||
215 | { |
||
216 | 3933072f | ljiyeon | //this.WindowState = WindowState.Normal; |
217 | |||
218 | 71bfd53e | ljiyeon | restoreIfMove = false; |
219 | |||
220 | double percentHorizontal = e.GetPosition(this).X / ActualWidth; |
||
221 | double targetHorizontal = RestoreBounds.Width * percentHorizontal; |
||
222 | |||
223 | double percentVertical = e.GetPosition(this).Y / ActualHeight; |
||
224 | double targetVertical = RestoreBounds.Height * percentVertical; |
||
225 | |||
226 | POINT lMousePosition; |
||
227 | 7e2d29a0 | ljiyeon | GetCursorPos(out lMousePosition); |
228 | 71bfd53e | ljiyeon | |
229 | Left = lMousePosition.X - targetHorizontal; |
||
230 | 7e2d29a0 | ljiyeon | double top = lMousePosition.Y - targetVertical; |
231 | if(top < 10) |
||
232 | { |
||
233 | top = 10; |
||
234 | } |
||
235 | Top = lMousePosition.Y; |
||
236 | 71bfd53e | ljiyeon | |
237 | 3933072f | ljiyeon | |
238 | 71bfd53e | ljiyeon | WindowState = WindowState.Normal; |
239 | |||
240 | this.DragMove(); |
||
241 | } |
||
242 | } |
||
243 | } |
||
244 | |||
245 | [DllImport("user32.dll")] |
||
246 | [return: MarshalAs(UnmanagedType.Bool)] |
||
247 | static extern bool GetCursorPos(out POINT lpPoint); |
||
248 | |||
249 | [StructLayout(LayoutKind.Sequential)] |
||
250 | public struct POINT |
||
251 | { |
||
252 | public int X; |
||
253 | public int Y; |
||
254 | |||
255 | public POINT(int x, int y) |
||
256 | { |
||
257 | this.X = x; |
||
258 | this.Y = y; |
||
259 | } |
||
260 | } |
||
261 | |||
262 | private void SwitchState() |
||
263 | { |
||
264 | switch (WindowState) |
||
265 | { |
||
266 | case WindowState.Normal: |
||
267 | { |
||
268 | WindowState = WindowState.Maximized; |
||
269 | break; |
||
270 | } |
||
271 | case WindowState.Maximized: |
||
272 | { |
||
273 | WindowState = WindowState.Normal; |
||
274 | break; |
||
275 | } |
||
276 | } |
||
277 | } |
||
278 | |||
279 | 787a4489 | KangIngu | private void RadButton_Click(object sender, RoutedEventArgs e) |
280 | { |
||
281 | Telerik.Windows.Controls.RadButton button = sender as Telerik.Windows.Controls.RadButton; |
||
282 | |||
283 | switch (button.CommandParameter.ToString()) |
||
284 | { |
||
285 | case ("Min"): |
||
286 | { |
||
287 | WindowState = WindowState.Minimized; |
||
288 | } |
||
289 | break; |
||
290 | case ("Max"): |
||
291 | { |
||
292 | WindowState = WindowState.Maximized; |
||
293 | } |
||
294 | break; |
||
295 | case ("Exit"): |
||
296 | { |
||
297 | |||
298 | } |
||
299 | break; |
||
300 | } |
||
301 | } |
||
302 | |||
303 | private void WinState(object sender, MouseButtonEventArgs e) |
||
304 | { |
||
305 | af177ca1 | djkim | switch ((e.Source as Image).Name) |
306 | 787a4489 | KangIngu | { |
307 | af177ca1 | djkim | case ("Win_min"): |
308 | 787a4489 | KangIngu | { |
309 | WindowState = WindowState.Minimized; |
||
310 | } |
||
311 | break; |
||
312 | af177ca1 | djkim | case ("Win_max"): |
313 | 787a4489 | KangIngu | { |
314 | af177ca1 | djkim | if (WindowState == WindowState.Maximized) |
315 | { |
||
316 | 787a4489 | KangIngu | WindowState = WindowState.Normal; |
317 | af177ca1 | djkim | } |
318 | 787a4489 | KangIngu | else |
319 | af177ca1 | djkim | { |
320 | 787a4489 | KangIngu | WindowState = WindowState.Maximized; |
321 | af177ca1 | djkim | } |
322 | 787a4489 | KangIngu | } |
323 | break; |
||
324 | af177ca1 | djkim | case ("Win_Close"): |
325 | 787a4489 | KangIngu | { |
326 | 32af2c3b | djkim | SaveCheck(); |
327 | UpdateCheck(); |
||
328 | if(isSaveCheck && isUpdateCheck) |
||
329 | 69ef0800 | KangIngu | { |
330 | 32af2c3b | djkim | this.Close(); |
331 | 316d0f5c | KangIngu | } |
332 | 32af2c3b | djkim | |
333 | //MainWindow_Close(); |
||
334 | 787a4489 | KangIngu | } |
335 | break; |
||
336 | } |
||
337 | } |
||
338 | 32af2c3b | djkim | |
339 | private void SaveCheck() |
||
340 | 264c9309 | ljiyeon | { |
341 | 32af2c3b | djkim | if (ViewerDataModel.Instance.UndoDataList.Count > 0) |
342 | { |
||
343 | DateTime undoTime = ViewerDataModel.Instance.UndoDataList.OrderByDescending(order => order.EventTime).FirstOrDefault().EventTime; |
||
344 | DateTime updatetime = DateTime.Now.AddDays(-1); |
||
345 | if (ViewerDataModel.Instance._markupInfoList.Count > 0) |
||
346 | { |
||
347 | updatetime = ViewerDataModel.Instance._markupInfoList.OrderByDescending(order => order.UpdateTime).FirstOrDefault().UpdateTime; |
||
348 | } |
||
349 | 264c9309 | ljiyeon | |
350 | 32af2c3b | djkim | if (undoTime > updatetime) |
351 | { |
||
352 | var box = new TextBlock(); |
||
353 | box.MinWidth = 400; |
||
354 | box.FontSize = 11; |
||
355 | box.Text = "저장되지 않은 코멘트가 있습니다. 저장 하시겠습니까?"; |
||
356 | box.TextWrapping = System.Windows.TextWrapping.Wrap; |
||
357 | 264c9309 | ljiyeon | |
358 | 32af2c3b | djkim | DialogParameters parameters = new DialogParameters() |
359 | { |
||
360 | Owner = Application.Current.MainWindow, |
||
361 | Content = box, |
||
362 | Header = "Confirm", |
||
363 | Theme = new VisualStudio2013Theme(), |
||
364 | ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 }, |
||
365 | Closed = OnClosingSave, |
||
366 | }; |
||
367 | RadWindow.Confirm(parameters); |
||
368 | } |
||
369 | else |
||
370 | { |
||
371 | isSaveCheck = true; |
||
372 | } |
||
373 | }else |
||
374 | 264c9309 | ljiyeon | { |
375 | 32af2c3b | djkim | isSaveCheck = true; |
376 | 264c9309 | ljiyeon | } |
377 | } |
||
378 | 32af2c3b | djkim | private void OnClosingSave(object sender, WindowClosedEventArgs e) |
379 | { |
||
380 | if (e.DialogResult == true) |
||
381 | { |
||
382 | dzTopMenu.SaveEventCallback(null, null); |
||
383 | } |
||
384 | isSaveCheck = true; |
||
385 | } |
||
386 | |||
387 | private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) |
||
388 | { |
||
389 | Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
390 | { |
||
391 | double bytesIn = double.Parse(e.BytesReceived.ToString()); |
||
392 | double totalBytes = double.Parse(e.TotalBytesToReceive.ToString()); |
||
393 | double percentage = bytesIn / totalBytes * 100; |
||
394 | progressControl.splashText.Text = "Download : " + Math.Truncate(percentage).ToString() + " %"; |
||
395 | progressControl.progressBar.Value = int.Parse(Math.Truncate(percentage).ToString()); |
||
396 | })); |
||
397 | } |
||
398 | |||
399 | private void UpdateCheck() |
||
400 | 264c9309 | ljiyeon | { |
401 | try |
||
402 | { |
||
403 | string url = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetVersionData(Environment.Is64BitProcess, Assembly.GetExecutingAssembly().GetName().Version.ToString()); |
||
404 | if (!string.IsNullOrEmpty(url)) |
||
405 | 97cde7e3 | ljiyeon | { |
406 | 32af2c3b | djkim | DialogParameters parameters = new DialogParameters() |
407 | 264c9309 | ljiyeon | { |
408 | 32af2c3b | djkim | Owner = Application.Current.MainWindow, |
409 | 97cde7e3 | ljiyeon | Content = new TextBlock() |
410 | { |
||
411 | MinWidth = 400, |
||
412 | FontSize = 11, |
||
413 | Text = "새로운 버전이 있습니다. \n업데이트 하시겠습니까?", |
||
414 | TextWrapping = System.Windows.TextWrapping.Wrap |
||
415 | }, |
||
416 | 32af2c3b | djkim | Header = "Confirm", |
417 | Theme = new VisualStudio2013Theme(), |
||
418 | ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 }, |
||
419 | Closed = delegate (object windowSender, WindowClosedEventArgs e) |
||
420 | 264c9309 | ljiyeon | { |
421 | 32af2c3b | djkim | if (e.DialogResult == true) |
422 | { |
||
423 | 97cde7e3 | ljiyeon | ProcessStartInfo proInfo = new ProcessStartInfo(); |
424 | var FileName = AppDomain.CurrentDomain.BaseDirectory + "SmartUpdate.exe"; |
||
425 | Process.Start(FileName, url); |
||
426 | this.Close(); |
||
427 | |||
428 | /* |
||
429 | 32af2c3b | djkim | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
430 | { |
||
431 | destfilepath = System.IO.Path.Combine(TempFile.TempFolder, System.IO.Path.GetFileName(url)); |
||
432 | progressControl = new ProgressControl(); |
||
433 | progressControl.splashText.Text = "Update Download Start..."; |
||
434 | progressControl.WindowStartupLocation = WindowStartupLocation.CenterScreen; |
||
435 | progressControl.Show(); |
||
436 | WebClient client = new WebClient(); |
||
437 | client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged); |
||
438 | client.DownloadFileCompleted += new AsyncCompletedEventHandler(Client_DownloadFileCompleted); |
||
439 | client.DownloadFileAsync(new Uri(url), destfilepath); |
||
440 | })); |
||
441 | 97cde7e3 | ljiyeon | */ |
442 | } |
||
443 | else |
||
444 | 32af2c3b | djkim | { |
445 | isUpdateCheck = true; |
||
446 | } |
||
447 | } |
||
448 | }; |
||
449 | 97cde7e3 | ljiyeon | RadWindow.Confirm(parameters); |
450 | |||
451 | 264c9309 | ljiyeon | } |
452 | else |
||
453 | { |
||
454 | 32af2c3b | djkim | isUpdateCheck = true; |
455 | 264c9309 | ljiyeon | } |
456 | } |
||
457 | catch (Exception) |
||
458 | { |
||
459 | 32af2c3b | djkim | throw; |
460 | 264c9309 | ljiyeon | } |
461 | } |
||
462 | |||
463 | 32af2c3b | djkim | private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) |
464 | { |
||
465 | 264c9309 | ljiyeon | try |
466 | { |
||
467 | 32af2c3b | djkim | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
468 | { |
||
469 | progressControl.splashText.Text = "Download Completed"; |
||
470 | })); |
||
471 | if(progressControl != null) |
||
472 | { |
||
473 | progressControl.Close(); |
||
474 | progressControl = null; |
||
475 | } |
||
476 | if(File.Exists(destfilepath)) |
||
477 | { |
||
478 | ProcessStartInfo update_msi = new ProcessStartInfo(); |
||
479 | update_msi.FileName = destfilepath; |
||
480 | Process.Start(update_msi); |
||
481 | } |
||
482 | this.Close(); |
||
483 | 264c9309 | ljiyeon | } |
484 | 32af2c3b | djkim | catch (Exception) |
485 | 69ef0800 | KangIngu | { |
486 | 32af2c3b | djkim | throw; |
487 | 69ef0800 | KangIngu | } |
488 | 32af2c3b | djkim | |
489 | 69ef0800 | KangIngu | } |
490 | 7e2d29a0 | ljiyeon | |
491 | void win_SourceInitialized(object sender, EventArgs e) |
||
492 | { |
||
493 | System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle; |
||
494 | WinInterop.HwndSource.FromHwnd(handle).AddHook(new WinInterop.HwndSourceHook(WindowProc)); |
||
495 | } |
||
496 | |||
497 | private static System.IntPtr WindowProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) |
||
498 | { |
||
499 | switch (msg) |
||
500 | { |
||
501 | case 0x0024: |
||
502 | WmGetMinMaxInfo(hwnd, lParam); |
||
503 | b0fb3ad7 | ljiyeon | handled = true; |
504 | 7e2d29a0 | ljiyeon | break; |
505 | } |
||
506 | return (System.IntPtr)0; |
||
507 | } |
||
508 | |||
509 | private static void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam) |
||
510 | { |
||
511 | MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO)); |
||
512 | int MONITOR_DEFAULTTONEAREST = 0x00000002; |
||
513 | System.IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); |
||
514 | |||
515 | if (monitor != System.IntPtr.Zero) |
||
516 | { |
||
517 | MONITORINFO monitorInfo = new MONITORINFO(); |
||
518 | GetMonitorInfo(monitor, monitorInfo); |
||
519 | RECT rcWorkArea = monitorInfo.rcWork; |
||
520 | RECT rcMonitorArea = monitorInfo.rcMonitor; |
||
521 | mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left); |
||
522 | mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top); |
||
523 | mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left); |
||
524 | mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top); |
||
525 | } |
||
526 | Marshal.StructureToPtr(mmi, lParam, true); |
||
527 | } |
||
528 | |||
529 | [StructLayout(LayoutKind.Sequential)] |
||
530 | public struct POINT2 |
||
531 | { |
||
532 | public int x; |
||
533 | public int y; |
||
534 | public POINT2(int x, int y) |
||
535 | { |
||
536 | this.x = x; |
||
537 | this.y = y; |
||
538 | } |
||
539 | } |
||
540 | |||
541 | [StructLayout(LayoutKind.Sequential)] |
||
542 | public struct MINMAXINFO |
||
543 | { |
||
544 | public POINT2 ptReserved; |
||
545 | public POINT2 ptMaxSize; |
||
546 | public POINT2 ptMaxPosition; |
||
547 | public POINT2 ptMinTrackSize; |
||
548 | public POINT2 ptMaxTrackSize; |
||
549 | }; |
||
550 | |||
551 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] |
||
552 | public class MONITORINFO |
||
553 | b0fb3ad7 | ljiyeon | { |
554 | public int cbSize = Marshal.SizeOf(typeof(MONITORINFO)); |
||
555 | public RECT rcMonitor = new RECT(); |
||
556 | public RECT rcWork = new RECT(); |
||
557 | 7e2d29a0 | ljiyeon | public int dwFlags = 0; |
558 | } |
||
559 | |||
560 | [StructLayout(LayoutKind.Sequential, Pack = 0)] |
||
561 | public struct RECT |
||
562 | { |
||
563 | public int left; |
||
564 | public int top; |
||
565 | b0fb3ad7 | ljiyeon | public int right; |
566 | 7e2d29a0 | ljiyeon | public int bottom; |
567 | |||
568 | public static readonly RECT Empty = new RECT(); |
||
569 | |||
570 | public int Width |
||
571 | { |
||
572 | get { return Math.Abs(right - left); } // Abs needed for BIDI OS |
||
573 | } |
||
574 | |||
575 | public int Height |
||
576 | { |
||
577 | get { return bottom - top; } |
||
578 | } |
||
579 | |||
580 | public RECT(int left, int top, int right, int bottom) |
||
581 | { |
||
582 | this.left = left; |
||
583 | this.top = top; |
||
584 | this.right = right; |
||
585 | this.bottom = bottom; |
||
586 | } |
||
587 | |||
588 | public RECT(RECT rcSrc) |
||
589 | { |
||
590 | this.left = rcSrc.left; |
||
591 | this.top = rcSrc.top; |
||
592 | this.right = rcSrc.right; |
||
593 | this.bottom = rcSrc.bottom; |
||
594 | } |
||
595 | |||
596 | public bool IsEmpty |
||
597 | { |
||
598 | get |
||
599 | { |
||
600 | // BUGBUG : On Bidi OS (hebrew arabic) left > right |
||
601 | return left >= right || top >= bottom; |
||
602 | } |
||
603 | } |
||
604 | |||
605 | public override bool Equals(object obj) |
||
606 | { |
||
607 | if (!(obj is Rect)) { return false; } |
||
608 | return (this == (RECT)obj); |
||
609 | } |
||
610 | |||
611 | public override int GetHashCode() |
||
612 | { |
||
613 | return left.GetHashCode() + top.GetHashCode() + right.GetHashCode() + bottom.GetHashCode(); |
||
614 | } |
||
615 | |||
616 | public static bool operator ==(RECT rect1, RECT rect2) |
||
617 | { |
||
618 | return (rect1.left == rect2.left && rect1.top == rect2.top && rect1.right == rect2.right && rect1.bottom == rect2.bottom); |
||
619 | } |
||
620 | |||
621 | public static bool operator !=(RECT rect1, RECT rect2) |
||
622 | { |
||
623 | return !(rect1 == rect2); |
||
624 | } |
||
625 | } |
||
626 | |||
627 | [DllImport("user32")] |
||
628 | internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi); |
||
629 | [DllImport("User32")] |
||
630 | internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags); |
||
631 | 787a4489 | KangIngu | } |
632 | } |