コード例 #1
0
ファイル: Win32Proc.cs プロジェクト: zhourongfu/NtMiner
        /// <summary>
        /// 获取windows任务栏的方位和工作区距离屏幕边缘的距离。
        /// </summary>
        /// <param name="margin">任务栏与工作区的接触边距离屏幕边的距离</param>
        /// <returns></returns>
        public static WindowsTaskbarEdge GetWindowsTaskbarEdge(out double margin)
        {
            IntPtr hwnd = SafeNativeMethods.FindWindow("Shell_TrayWnd", null);
            var    abd  = new SafeNativeMethods.APPBARDATA();

            abd.cbSize = Marshal.SizeOf(abd);
            abd.hWnd   = hwnd;
            SafeNativeMethods.SHAppBarMessage(5, ref abd);
            switch (abd.uEdge)
            {
            case (int)WindowsTaskbarEdge.Left:
                margin = Math.Abs(abd.rc.Left - abd.rc.Right);
                return(WindowsTaskbarEdge.Left);

            case (int)WindowsTaskbarEdge.Top:
                margin = Math.Abs(abd.rc.Top - abd.rc.Bottom);
                return(WindowsTaskbarEdge.Top);

            case (int)WindowsTaskbarEdge.Right:
                margin = Math.Abs(abd.rc.Left - abd.rc.Right);
                return(WindowsTaskbarEdge.Right);

            case (int)WindowsTaskbarEdge.Bottom:
                margin = Math.Abs(abd.rc.Top - abd.rc.Bottom);
                return(WindowsTaskbarEdge.Bottom);

            default:
                margin = 0;
                return(WindowsTaskbarEdge.Bottom);
            }
        }