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