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

简介: 原文:C# WPF获取任务栏时间区域的Rectangle [StructLayout(LayoutKind.Sequential)] public struct WindowRect { public int left; ...
原文: 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# Windows
C#实现无标题栏窗体点击任务栏图标正常最小化或还原的解决方法
对于无标题栏窗体,也就是FormBorderStyle等于System.Windows.Forms.FormBorderStyle.None的窗体,点击任务栏图标的时候,是不能象标准窗体那样最小化或还原的。
1160 0
|
C#
全网首发:C#中Form设置$this.Icon,任务栏图标错误的解决办法(bitmap转icon)
全网首发:C#中Form设置$this.Icon,任务栏图标错误的解决办法(bitmap转icon)
232 0
|
C#
wpf 自定义窗口,最大化时覆盖任务栏解决方案
原文:wpf 自定义窗口,最大化时覆盖任务栏解决方案 相信很多人使用wpf时会选择自定义美观的窗口,因此会设置WindowStyle="None" 取消自带的标题栏。但这样使用 WindowState="Maximized" 或者后台 this.WindowState = System.Windows.WindowState.Maximized; 最大化窗口会覆盖掉系统任务栏,即全屏了。
2361 0
|
C#
c#实现任务栏添加控制按钮
原文:c#实现任务栏添加控制按钮 Windows7Taskbar的使用 你需要引入3个文件VistaBridgeLibrary.dll、Windows7.DesktopIntegration.dll、Windows7.
884 0
|
C# Windows
WPF 4 开发Windows 7 任务栏(Overlay Icon、Thumbnail Toolbar、Progress Bar)
原文:WPF 4 开发Windows 7 任务栏(Overlay Icon、Thumbnail Toolbar、Progress Bar)      在上一篇我们介绍了如何在WPF 4 中开发Windows 7 跳转列表,本篇将继续针对WPF 4 中任务栏其他功能:覆盖图标(Overlay Icon)、进度条(Progress Bar)、缩略图工具栏(Thumbnail Toolbar)进行研究。
1143 0
|
C#
WPF自定义窗口最大化显示任务栏
原文:WPF自定义窗口最大化显示任务栏 当我们要自定义WPF窗口样式时,通常是采用设计窗口的属性 WindowStyle="None" ,然后为窗口自定义放大,缩小,关闭按钮的样式。 然而这样的话,当通过代码设置窗口(代码如下)放大时,窗口会把任务栏给遮档住。
1185 0
|
C#
WPF最大化避免覆盖任务栏
原文:WPF最大化避免覆盖任务栏 WPF当窗体WindowStyle=”None”时,最大化会覆盖掉任务栏。如何解决这个问题呢? 我在Google里面搜到一篇文章,要用到Win32 API,通过让WPF窗体WM_GETMINMAXINFO消息挂接一个钩子来处理。
1228 0
|
C#
WPF——TaskBarIconOverlay(任务栏图标叠加)
原文:WPF——TaskBarIconOverlay(任务栏图标叠加)     1 public partial class MainWindow : Window 2 { 3 public MainWi...
1102 0
|
C#
C# WPF获取任务栏时间区域的Rectangle
[StructLayout(LayoutKind.Sequential)] public struct WindowRect { public int left; public int top; ...
795 0