프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / KCOM / MainWindow.xaml.cs @ 72424099

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