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