C# WPF获取任务栏时间区域的Rectangle
2016-02-20 09:22
591 查看
原文: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 让你的窗口始终钉在桌面上
- [置顶]10年C#之旅,终获MVP,感谢博客园这个舞台。。。。。
- [置顶]群蚁算法理论与实践全攻略——旅行商等路径优化问题的新方法【附C#群蚁算法完整项目代码】
- [置顶]白话贝叶斯理论及在足球比赛结果预测中的应用和C#实现
- 【原创】C#搭建足球赛事资料库与预测平台(6) 赔率数据表设计2
- 【原创】机器学习之PageRank算法应用与C#实现(2)球队排名应用与C#代码
- 【原创】C#搭建足球赛事资料库与预测平台(5) 赔率数据表设计1
- 【原创】C#搭建足球赛事资料库与预测平台(4) 比赛信息数据表设计
- 【原创】C#搭建足球赛事资料库与预测平台(3) 基础数据表设计
- C#搭建足球赛事资料库与预测平台(1) 基本介绍
- 【原创】机器学习之PageRank算法应用与C#实现(1)算法介绍
- 【原创】开源Math.NET基础数学类库使用(17)C#计算矩阵条件数
- 【原创】开源Math.NET基础数学类库使用(16)C#计算矩阵秩
- 【目录】C#操作Excel组件Spire.XLS系列文章目录
- 【原创】开源Math.NET基础数学类库使用(15)C#计算矩阵行列式
- 【原创】C#玩高频数字彩快3的一点体会
- 【原创】开源Math.NET基础数学类库使用(14)C#生成安全的随机数
- 【原创】开源Math.NET基础数学类库使用(13)C#实现其他随机数生成器
- 【原创】开源Math.NET基础数学类库使用(12)C#随机数扩展方法
- 【原创】开源Math.NET基础数学类库使用(11)C#计算相关系数