프로젝트

일반

사용자정보

개정판 d33ef543

IDd33ef54354e2b882cd173cea2e98c08174a0cd0e
상위 df00b3d0
하위 40a810fc

김태성이(가) 약 5년 전에 추가함

Main window style 변경

Change-Id: Idecdbcbe3743713536c151e5816c21fad4783f12

차이점 보기:

KCOM/MainWindow.xaml.cs
40 40
    public partial class MainWindow : Window
41 41
    {
42 42
        bool isSaveCheck = false;
43
        
43

  
44 44
        ProgressControl progressControl = null;
45 45
        string destfilepath = string.Empty;
46 46

  
......
50 50
            this.Loaded += MainWindow_Loaded;
51 51
            this.Unloaded += MainWindow_Unloaded;
52 52
            this.PreviewKeyDown += new KeyEventHandler(KeyEventDownAction);
53
            this.SourceInitialized += new EventHandler(win_SourceInitialized);
54 53
        }
55 54

  
56 55
        private void MainWindow_Unloaded(object sender, RoutedEventArgs e)
......
73 72
            {
74 73
                Owner = Application.Current.MainWindow,
75 74
                Content = new TextBlock()
76
                { 
75
                {
77 76
                    MinWidth = 400,
78 77
                    FontSize = 12,
79 78
                    Text = content,
......
89 88
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
90 89
        {
91 90
            InitializeComponent();
92
            
91

  
93 92
            //cursor change  
94 93
            this.Cursor = new Cursor(CursorChange().StreamSource);
95 94

  
96
            double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;
97
            double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight;
98
            //this.Width += 40;
99
            double windowWidth = this.Width;
100
            double windowHeight = this.Height;
101
            this.Left = (screenWidth / 2) - (windowWidth / 2);
102
            this.Top = (screenHeight / 2) - (windowHeight / 2);
95
            var point = GetScreenCenter();
96

  
97
            this.Left = point.X;
98
            this.Top = point.Y;
103 99

  
104 100
            ViewerDataModel.Instance.SystemMain = this;
105 101

  
......
191 187
            //this.dzMainMenu.SetView(App.ViewInfo);
192 188
        }
193 189

  
194
      
195
        bool restoreIfMove = false;
196

  
197
        private void WindowDragEvent(object sender, MouseButtonEventArgs e)
190
        private Point GetScreenCenter()
198 191
        {
199
            if(string.IsNullOrEmpty(destfilepath))
200
            {
201
                if (e.ClickCount == 2)
202
                {
203
                    if ((ResizeMode == ResizeMode.CanResize) ||
204
                        (ResizeMode == ResizeMode.CanResizeWithGrip))
205
                    {
206
                        SwitchState();
207
                    }
208
                }
209
                else
210
                {
211
                    if (WindowState == WindowState.Maximized)
212
                    {
213
                        restoreIfMove = true;
214
                    }
192
            Point result = new Point();
215 193

  
216
                    this.DragMove();
217
                }
218
            }            
219
        }   
194
            //first get all the screens 
195
            System.Drawing.Rectangle ret;
196
            int ScreenWidth = 0;
220 197

  
221
        private void WindowDragEventUp(object sender, MouseButtonEventArgs e)
222
        {
223
            restoreIfMove = false;
224
        }
198
            var mousePosition = System.Windows.Forms.Cursor.Position;
225 199

  
226
        private void WindowDragEventMove(object sender, MouseEventArgs e)
227
        {
228
            if (restoreIfMove)
200
            for (int i = 1; i <= System.Windows.Forms.Screen.AllScreens.Count(); i++)
229 201
            {
230
                if (Mouse.LeftButton == MouseButtonState.Pressed)
231
                {
232
                    //this.WindowState = WindowState.Normal;
202
                ret = System.Windows.Forms.Screen.AllScreens[i - 1].Bounds;
233 203

  
234
                    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
                    GetCursorPos(out lMousePosition);
244

  
245
                    Left = lMousePosition.X - targetHorizontal;
246
                    double top = lMousePosition.Y - targetVertical;
247
                    if(top < 10)
248
                    {
249
                        top = 10;
250
                    }
251
                    Top = lMousePosition.Y;
252

  
253

  
254
                    WindowState = WindowState.Normal;
204
                if (ret.Contains(mousePosition))
205
                {
206
                    result.X = ScreenWidth + (ret.Width / 2 - this.Width / 2);
207
                    result.Y = (ret.Height / 2 - this.Height / 2);
255 208

  
256
                    this.DragMove();
209
                    break;
210
                }
211
                else
212
                {
213
                    ScreenWidth += ret.Width;
257 214
                }
258
            }
259
        }
260 215

  
261
        [DllImport("user32.dll")]
262
        [return: MarshalAs(UnmanagedType.Bool)]
263
        static extern bool GetCursorPos(out POINT lpPoint);
216
            }
264 217

  
265
        [StructLayout(LayoutKind.Sequential)]
266
        public struct POINT
267
        {
268
            public int X;
269
            public int Y;
270 218

  
271
            public POINT(int x, int y)
272
            {
273
                this.X = x;
274
                this.Y = y;
275
            }
219
            return result;
276 220
        }
277 221

  
278
        private void SwitchState()
222
        protected override void OnStateChanged(EventArgs e)
279 223
        {
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
            }
224
            base.OnStateChanged(e);
293 225
        }
294 226

  
295
        private void RadButton_Click(object sender, RoutedEventArgs e)
227
        protected override void OnClosing(CancelEventArgs e)
296 228
        {
297
            Telerik.Windows.Controls.RadButton button = sender as Telerik.Windows.Controls.RadButton;
229
            base.OnClosing(e);
298 230

  
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
        }
231
            SaveCheck();
318 232

  
319
        private void WinState(object sender, MouseButtonEventArgs e)
320
        {
321
            switch ((e.Source as Image).Name)
233
            //Update Check 를 통해 update url 을 Get 하고 결과값이 있을 경우에는 SmartUpdater 실행.
234
            KeyValuePair<bool, string> updatecheck = UpdateCheck();
235
            if (updatecheck.Key && !string.IsNullOrEmpty(updatecheck.Value))
322 236
            {
323
                case ("Win_min"):
324
                    {
325
                        WindowState = WindowState.Minimized;
326
                    }
327
                    break;
328
                case ("Win_max"):
329
                    {
330
                        if (WindowState == WindowState.Maximized)
331
                        {
332
                            WindowState = WindowState.Normal;
333
                        }
334
                        else
335
                        {
336
                            WindowState = WindowState.Maximized;
337
                        }
338
                    }
339
                    break;
340
                case ("Win_Close"):
341
                    {
342
                        SaveCheck();
343
                        //Update Check 를 통해 update url 을 Get 하고 결과값이 있을 경우에는 SmartUpdater 실행.
344
                        KeyValuePair<bool, string> updatecheck = UpdateCheck();
345
                        if (updatecheck.Key && !string.IsNullOrEmpty(updatecheck.Value))
346
                        {
347
                            CallUpdateProcess(updatecheck.Value);
348
                        }
349
                        this.Close();
350
                    }
351
                    break;
237
                CallUpdateProcess(updatecheck.Value);
352 238
            }
353 239
        }
354
        
240

  
355 241
        private void SaveCheck()
356 242
        {
357 243
            if (ViewerDataModel.Instance.UndoDataList.Count > 0)
......
385 271
                else
386 272
                {
387 273
                    isSaveCheck = true;
388
                }                    
389
            }else
274
                }
275
            }
276
            else
390 277
            {
391 278
                isSaveCheck = true;
392 279
            }
......
399 286
            }
400 287
            isSaveCheck = true;
401 288
        }
402
                
289

  
403 290
        private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
404 291
        {
405 292
            Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
......
408 295
                double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
409 296
                double percentage = bytesIn / totalBytes * 100;
410 297
                progressControl.splashText.Text = "Download : " + Math.Truncate(percentage).ToString() + " %";
411
                progressControl.progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());                
298
                progressControl.progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());
412 299
            }));
413 300
        }
414 301

  
......
427 314
                bool is64bit = Environment.Is64BitProcess;
428 315
                string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
429 316
                updateurl = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetVersionData(is64bit, clientversion);
430
                
317

  
431 318
                if (Check_Uri.isUri(updateurl))
432
                {                          
319
                {
433 320
                    DialogParameters parameters = new DialogParameters()
434 321
                    {
435 322
                        Owner = Application.Current.MainWindow,
......
442 329
                        },
443 330
                        Header = "Confirm",
444 331
                        Theme = new VisualStudio2013Theme(),
445
                        ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },                        
332
                        ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
446 333
                        Closed = delegate (object windowSender, WindowClosedEventArgs e)
447 334
                        {
448 335
                            if (e.DialogResult == true)
449
                            {   
450
                                isUpdateCheck = true;                                
336
                            {
337
                                isUpdateCheck = true;
451 338
                            }
452 339
                            else
453 340
                            {
454 341
                                isUpdateCheck = false;
455
                            }                            
456
                        }                    
342
                            }
343
                        }
457 344
                    };
458
                    RadWindow.Confirm(parameters);       
459
                    
345
                    RadWindow.Confirm(parameters);
346

  
460 347
                }
461 348
                else
462 349
                {
......
485 372
        {
486 373
            try
487 374
            {
488
                await Dispatcher.InvokeAsync(()=> progressControl.splashText.Text = "Download Completed");
375
                await Dispatcher.InvokeAsync(() => progressControl.splashText.Text = "Download Completed");
489 376

  
490
                if(progressControl != null)
377
                if (progressControl != null)
491 378
                {
492 379
                    progressControl.Close();
493 380
                    progressControl = null;
494 381
                }
495
                if(File.Exists(destfilepath))
382
                if (File.Exists(destfilepath))
496 383
                {
497 384
                    ProcessStartInfo update_msi = new ProcessStartInfo();
498 385
                    update_msi.FileName = destfilepath;
499 386
                    Process.Start(update_msi);
500
                }                
387
                }
501 388
                this.Close();
502 389
            }
503 390
            catch (Exception)
504 391
            {
505 392
                throw;
506 393
            }
507
            
508
        }
509

  
510
        void win_SourceInitialized(object sender, EventArgs e)
511
        {
512
            //System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle;
513
            //WinInterop.HwndSource.FromHwnd(handle).AddHook(new WinInterop.HwndSourceHook(WindowProc));
514
        }
515

  
516
        private static System.IntPtr WindowProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)
517
        {
518
            switch (msg)
519
            {
520
                case 0x0024:
521
                    WmGetMinMaxInfo(hwnd, lParam);
522
                    handled = true;
523
                    break;
524
            }
525
            return (System.IntPtr)0;
526
        }
527

  
528
        private static void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)
529
        {
530
            MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
531
            int MONITOR_DEFAULTTONEAREST = 0x00000002;
532
            System.IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
533

  
534
            if (monitor != System.IntPtr.Zero)
535
            {
536
                MONITORINFO monitorInfo = new MONITORINFO();
537
                GetMonitorInfo(monitor, monitorInfo);
538
                RECT rcWorkArea = monitorInfo.rcWork;
539
                RECT rcMonitorArea = monitorInfo.rcMonitor;
540
                mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
541
                mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
542
                mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left);
543
                mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
544
            }
545
            Marshal.StructureToPtr(mmi, lParam, true);
546
        }
547

  
548
        [StructLayout(LayoutKind.Sequential)]
549
        public struct POINT2
550
        {
551
            public int x;
552
            public int y;
553
            public POINT2(int x, int y)
554
            {
555
                this.x = x;
556
                this.y = y;
557
            }
558
        }
559

  
560
        [StructLayout(LayoutKind.Sequential)]
561
        public struct MINMAXINFO
562
        {
563
            public POINT2 ptReserved;
564
            public POINT2 ptMaxSize;
565
            public POINT2 ptMaxPosition;
566
            public POINT2 ptMinTrackSize;
567
            public POINT2 ptMaxTrackSize;
568
        };
569

  
570
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
571
        public class MONITORINFO
572
        {
573
            public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));
574
            public RECT rcMonitor = new RECT();
575
            public RECT rcWork = new RECT();
576
            public int dwFlags = 0;
577
        }
578

  
579
        [StructLayout(LayoutKind.Sequential, Pack = 0)]
580
        public struct RECT
581
        {
582
            public int left;
583
            public int top;
584
            public int right;
585
            public int bottom;
586

  
587
            public static readonly RECT Empty = new RECT();
588

  
589
            public int Width
590
            {
591
                get { return Math.Abs(right - left); }  // Abs needed for BIDI OS
592
            }
593 394

  
594
            public int Height
595
            {
596
                get { return bottom - top; }
597
            }
598

  
599
            public RECT(int left, int top, int right, int bottom)
600
            {
601
                this.left = left;
602
                this.top = top;
603
                this.right = right;
604
                this.bottom = bottom;
605
            }
606

  
607
            public RECT(RECT rcSrc)
608
            {
609
                this.left = rcSrc.left;
610
                this.top = rcSrc.top;
611
                this.right = rcSrc.right;
612
                this.bottom = rcSrc.bottom;
613
            }
614

  
615
            public bool IsEmpty
616
            {
617
                get
618
                {
619
                    // BUGBUG : On Bidi OS (hebrew arabic) left > right
620
                    return left >= right || top >= bottom;
621
                }
622
            }
623

  
624
            public override bool Equals(object obj)
625
            {
626
                if (!(obj is Rect)) { return false; }
627
                return (this == (RECT)obj);
628
            }
629

  
630
            public override int GetHashCode()
631
            {
632
                return left.GetHashCode() + top.GetHashCode() + right.GetHashCode() + bottom.GetHashCode();
633
            }
634

  
635
            public static bool operator ==(RECT rect1, RECT rect2)
636
            {
637
                return (rect1.left == rect2.left && rect1.top == rect2.top && rect1.right == rect2.right && rect1.bottom == rect2.bottom);
638
            }
639

  
640
            public static bool operator !=(RECT rect1, RECT rect2)
641
            {
642
                return !(rect1 == rect2);
643
            }
644 395
        }
645

  
646
        [DllImport("user32")]
647
        internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);
648
        [DllImport("User32")]
649
        internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags);
650 396
    }
651 397
}

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)