博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# WPF获取任务栏时间区域的Rectangle
阅读量:7045 次
发布时间:2019-06-28

本文共 1662 字,大约阅读时间需要 5 分钟。

[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;                    }

  

转载地址:http://bizol.baihongyu.com/

你可能感兴趣的文章
C# 多线程详解 Part.04(Lock、Monitor、生产与消费)
查看>>
HTTP协议之chunk介绍
查看>>
误区1:数据是可靠的
查看>>
根据IP找到计算机名字(小技巧)
查看>>
遍历jquery的对象
查看>>
system app 下面的apk 修改后不需要重新签名
查看>>
openoj的一个小比赛(F题解题报告)poj3978(dp+素数筛选)
查看>>
【转载】动态代理DynamicProxy 介绍
查看>>
读写cookie的方法
查看>>
淘宝技术发展(Oracle/支付宝/旺旺)
查看>>
分布式版本控制工具 Mercurial 使用教程
查看>>
使用Keil MDK运行第一个STM32程序
查看>>
同时寻找最大数和最小数的最优算法
查看>>
【Visual C++】游戏开发笔记十四 游戏画面绘图(四) 华丽的CImage类
查看>>
GDI+在VS2008 编译不过的解决方法
查看>>
强烈推荐一个超酷的wordpress状态信息图
查看>>
分区表、分区索引3(海量数据测试)
查看>>
AIX查看CPU核数
查看>>
Android 记录和恢复ListView滚动的位置的三种方法
查看>>
Silverlight和Metro中ListBox样式的添加及使用
查看>>