프로젝트

일반

사용자정보

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

markus / KCOM / MainWindow.xaml.cs @ 1c7f408a

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