首页 > Windows开发 > 详细

C# WPF获取任务栏时间区域的Rectangle

时间:2016-02-20 10:21:56      阅读:666      评论:0      收藏:0      [点我收藏+]
原文:C# WPF获取任务栏时间区域的Rectangle

[StructLayout(LayoutKind.Sequential)]
        public struct WindowRect
        {
            public int left;
            public int top;
            public int right;
            public int bottom;
        }

        [DllImport("user32.dll")]
        private static extern IntPtr FindWindow(string ClassName, string WindowName);

        [DllImport("user32.dll")]
        private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string className, string windowName);

        [DllImport("user32.dll")]
        private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

        [DllImport("user32.dll")]
        static extern bool GetWindowRect(HandleRef hwnd, out WindowRect rect);

        const int SW_HIDE = 0;
        const int SW_SHOW = 5;


        [DllImport("user32.dll")]
        static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        public MainWindow()
        {
            InitializeComponent();
            this.Loaded += MainWindow_Loaded;
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            IntPtr taskBarWnd = FindWindow("Shell_TrayWnd", null);
            IntPtr tray = FindWindowEx(taskBarWnd, IntPtr.Zero, "TrayNotifyWnd", null);
            IntPtr trayclock = FindWindowEx(tray, IntPtr.Zero, "TrayClockWClass", null);
            WindowRect rect;
            GetWindowRect(new HandleRef(Application.Current.MainWindow, trayclock), out rect);
            //this.Top = rect.top;
            //this.Left = rect.left;
            //this.Width = rect.right - Left;
            //this.Height = rect.bottom - rect.top;
            //this.Topmost = true;            
        }

  

C# WPF获取任务栏时间区域的Rectangle

原文:http://www.cnblogs.com/lonelyxmas/p/5202686.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!