프로젝트

일반

사용자정보

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

markus / KCOM / MainWindow.xaml.cs @ 20bb0e09

이력 | 보기 | 이력해설 | 다운로드 (24.3 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 1c7f408a taeseongkim
    public partial class MainWindow : RadWindow, System.Windows.Markup.IComponentConnector
41 787a4489 KangIngu
    {
42 32af2c3b djkim
        bool isSaveCheck = false;
43 310eff8b djkim
        
44 32af2c3b djkim
        ProgressControl progressControl = null;
45
        string destfilepath = string.Empty;
46 b10671a4 taeseongkim
        static MainWindow()
47
        {
48
            StyleManager.ApplicationTheme = new VisualStudio2013Theme();
49
            RadRibbonWindow.IsWindowsThemeEnabled = false;
50
        }
51 32af2c3b djkim
52 787a4489 KangIngu
        public MainWindow()
53
        {
54 e0cfc73c ljiyeon
            App.splashString(ISplashMessage.MAINWINDOW);
55 787a4489 KangIngu
            this.Loaded += MainWindow_Loaded;
56 b35682c3 taeseongkim
57
            this.AddHandler(Keyboard.KeyDownEvent,
58
                        new KeyEventHandler((sender, e) =>KeyEventDownAction(sender, e)),true);
59
60
            //this.PreviewKeyDown += new KeyEventHandler(KeyEventDownAction);
61 1c7f408a taeseongkim
            //this.SourceInitialized += new EventHandler(win_SourceInitialized);
62 787a4489 KangIngu
        }
63 ca16abb2 ljiyeon
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 787a4489 KangIngu
        public void DialogMessage_Alert(string content, string header)
73
        {
74
            Telerik.Windows.Controls.DialogParameters parameters = new Telerik.Windows.Controls.DialogParameters()
75
            {
76 b9b01f8e ljiyeon
                Owner = Application.Current.MainWindow,
77 0d32593b ljiyeon
                Content = new TextBlock()
78
                { 
79
                    MinWidth = 400,
80
                    FontSize = 12,
81
                    Text = content,
82
                    TextWrapping = System.Windows.TextWrapping.Wrap
83
                },
84 787a4489 KangIngu
                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 7e2d29a0 ljiyeon
91 787a4489 KangIngu
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
92
        {
93 0c997b99 ljiyeon
            InitializeComponent();
94 3d31db34 송근호
            
95 ca16abb2 ljiyeon
            //cursor change  
96
            this.Cursor = new Cursor(CursorChange().StreamSource);
97
98 787a4489 KangIngu
            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 3d31db34 송근호
158
                try
159
                {
160
                    this.dzMainMenu.HubSet();
161
                    this.dzMainMenu.SetView(App.ViewInfo);
162
                }
163 3724d2a2 송근호
                catch (Exception)
164 3d31db34 송근호
                {
165 3724d2a2 송근호
                    MessageBox.Show("웹 서비스에 연결을 할 수 없습니다.");
166
167
                    System.Environment.Exit(0);
168 3d31db34 송근호
                }
169 787a4489 KangIngu
            }
170 6707a5c7 ljiyeon
171 1c7f408a taeseongkim
            //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 787a4489 KangIngu
            //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 6707a5c7 ljiyeon
206 1c7f408a taeseongkim
207 7e2d29a0 ljiyeon
        bool restoreIfMove = false;
208 71bfd53e ljiyeon
209 787a4489 KangIngu
        private void WindowDragEvent(object sender, MouseButtonEventArgs e)
210
        {
211 1c7f408a taeseongkim
            //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 3d31db34 송근호
        }   
232 787a4489 KangIngu
233 71bfd53e ljiyeon
        private void WindowDragEventUp(object sender, MouseButtonEventArgs e)
234
        {
235
            restoreIfMove = false;
236
        }
237
238
        private void WindowDragEventMove(object sender, MouseEventArgs e)
239
        {
240 1c7f408a taeseongkim
            //if (restoreIfMove)
241
            //{
242
            //    if (Mouse.LeftButton == MouseButtonState.Pressed)
243
            //    {
244
            //        //this.WindowState = WindowState.Normal;
245 3933072f ljiyeon
246 1c7f408a taeseongkim
            //        restoreIfMove = false;
247 71bfd53e ljiyeon
248 1c7f408a taeseongkim
            //        double percentHorizontal = e.GetPosition(this).X / ActualWidth;
249
            //        double targetHorizontal = RestoreBounds.Width * percentHorizontal;
250 71bfd53e ljiyeon
251 1c7f408a taeseongkim
            //        double percentVertical = e.GetPosition(this).Y / ActualHeight;
252
            //        double targetVertical = RestoreBounds.Height * percentVertical;
253 71bfd53e ljiyeon
254 1c7f408a taeseongkim
            //        POINT lMousePosition;
255
            //        GetCursorPos(out lMousePosition);
256 71bfd53e ljiyeon
257 1c7f408a taeseongkim
            //        Left = lMousePosition.X - targetHorizontal;
258
            //        double top = lMousePosition.Y - targetVertical;
259
            //        if(top < 10)
260
            //        {
261
            //            top = 10;
262
            //        }
263
            //        Top = lMousePosition.Y;
264 71bfd53e ljiyeon
265 3933072f ljiyeon
266 1c7f408a taeseongkim
            //        WindowState = WindowState.Normal;
267 71bfd53e ljiyeon
268 1c7f408a taeseongkim
            //        this.DragMove();
269
            //    }
270
            //}
271 71bfd53e ljiyeon
        }
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 787a4489 KangIngu
        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 af177ca1 djkim
            switch ((e.Source as Image).Name)
334 787a4489 KangIngu
            {
335 af177ca1 djkim
                case ("Win_min"):
336 787a4489 KangIngu
                    {
337
                        WindowState = WindowState.Minimized;
338
                    }
339
                    break;
340 af177ca1 djkim
                case ("Win_max"):
341 787a4489 KangIngu
                    {
342 af177ca1 djkim
                        if (WindowState == WindowState.Maximized)
343
                        {
344 787a4489 KangIngu
                            WindowState = WindowState.Normal;
345 af177ca1 djkim
                        }
346 787a4489 KangIngu
                        else
347 af177ca1 djkim
                        {
348 787a4489 KangIngu
                            WindowState = WindowState.Maximized;
349 af177ca1 djkim
                        }
350 787a4489 KangIngu
                    }
351
                    break;
352 af177ca1 djkim
                case ("Win_Close"):
353 787a4489 KangIngu
                    {
354 32af2c3b djkim
                        SaveCheck();
355 310eff8b djkim
                        //Update Check 를 통해 update url 을 Get 하고 결과값이 있을 경우에는 SmartUpdater 실행.
356
                        KeyValuePair<bool, string> updatecheck = UpdateCheck();
357
                        if (updatecheck.Key && !string.IsNullOrEmpty(updatecheck.Value))
358 69ef0800 KangIngu
                        {
359 310eff8b djkim
                            CallUpdateProcess(updatecheck.Value);
360 316d0f5c KangIngu
                        }
361 310eff8b djkim
                        this.Close();
362 787a4489 KangIngu
                    }
363
                    break;
364
            }
365
        }
366 32af2c3b djkim
        
367
        private void SaveCheck()
368 264c9309 ljiyeon
        {
369 32af2c3b djkim
            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 264c9309 ljiyeon
378 32af2c3b djkim
                if (undoTime > updatetime)
379
                {
380
                    DialogParameters parameters = new DialogParameters()
381
                    {
382
                        Owner = Application.Current.MainWindow,
383 0d32593b ljiyeon
                        Content = new TextBlock()
384
                        {
385
                            MinWidth = 400,
386
                            FontSize = 11,
387
                            Text = "저장되지 않은 코멘트가 있습니다. 저장 하시겠습니까?",
388
                            TextWrapping = System.Windows.TextWrapping.Wrap
389
                        },
390 32af2c3b djkim
                        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 264c9309 ljiyeon
            {
403 32af2c3b djkim
                isSaveCheck = true;
404 264c9309 ljiyeon
            }
405
        }
406 32af2c3b djkim
        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 310eff8b djkim
        }
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 264c9309 ljiyeon
        {
435 310eff8b djkim
            bool isUpdateCheck = false;
436
            string updateurl = string.Empty;
437 264c9309 ljiyeon
            try
438
            {
439 ffddbe4e djkim
                bool is64bit = Environment.Is64BitProcess;
440
                string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
441
                updateurl = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetVersionData(is64bit, clientversion);
442 d71b4688 ljiyeon
                
443 ffddbe4e djkim
                if (Check_Uri.isUri(updateurl))
444 97cde7e3 ljiyeon
                {                          
445 32af2c3b djkim
                    DialogParameters parameters = new DialogParameters()
446 264c9309 ljiyeon
                    {
447 32af2c3b djkim
                        Owner = Application.Current.MainWindow,
448 97cde7e3 ljiyeon
                        Content = new TextBlock()
449
                        {
450
                            MinWidth = 400,
451
                            FontSize = 11,
452
                            Text = "새로운 버전이 있습니다. \n업데이트 하시겠습니까?",
453
                            TextWrapping = System.Windows.TextWrapping.Wrap
454
                        },
455 32af2c3b djkim
                        Header = "Confirm",
456
                        Theme = new VisualStudio2013Theme(),
457
                        ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },                        
458
                        Closed = delegate (object windowSender, WindowClosedEventArgs e)
459 264c9309 ljiyeon
                        {
460 32af2c3b djkim
                            if (e.DialogResult == true)
461 310eff8b djkim
                            {   
462 ffddbe4e djkim
                                isUpdateCheck = true;                                
463 97cde7e3 ljiyeon
                            }
464
                            else
465 32af2c3b djkim
                            {
466 310eff8b djkim
                                isUpdateCheck = false;
467 32af2c3b djkim
                            }                            
468
                        }                    
469
                    };
470 97cde7e3 ljiyeon
                    RadWindow.Confirm(parameters);       
471
                    
472 264c9309 ljiyeon
                }
473
                else
474
                {
475 310eff8b djkim
                    isUpdateCheck = false;
476 264c9309 ljiyeon
                }
477
            }
478
            catch (Exception)
479
            {
480 32af2c3b djkim
                throw;
481 310eff8b djkim
            }
482
            return new KeyValuePair<bool, string>(isUpdateCheck, updateurl);
483 264c9309 ljiyeon
        }
484
485 310eff8b djkim
        /// <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 32af2c3b djkim
        private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
497
        {
498 264c9309 ljiyeon
            try
499
            {
500 32af2c3b djkim
                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 264c9309 ljiyeon
            }
517 32af2c3b djkim
            catch (Exception)
518 69ef0800 KangIngu
            {
519 32af2c3b djkim
                throw;
520 69ef0800 KangIngu
            }
521 32af2c3b djkim
            
522 69ef0800 KangIngu
        }
523 7e2d29a0 ljiyeon
524
        void win_SourceInitialized(object sender, EventArgs e)
525
        {
526 1c7f408a taeseongkim
            //System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle;
527
            //WinInterop.HwndSource.FromHwnd(handle).AddHook(new WinInterop.HwndSourceHook(WindowProc));
528 7e2d29a0 ljiyeon
        }
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 b0fb3ad7 ljiyeon
                    handled = true;
537 7e2d29a0 ljiyeon
                    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 b0fb3ad7 ljiyeon
        {
587
            public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));
588
            public RECT rcMonitor = new RECT();
589
            public RECT rcWork = new RECT();
590 7e2d29a0 ljiyeon
            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 b0fb3ad7 ljiyeon
            public int right;
599 7e2d29a0 ljiyeon
            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 787a4489 KangIngu
    }
665
}
클립보드 이미지 추가 (최대 크기: 500 MB)