public Taskbar()
        {
            IntPtr taskbarHandle = User32.FindWindow(ClassName, null);

            APPBARDATA data = new APPBARDATA
            {
                cbSize = (uint)Marshal.SizeOf(typeof(APPBARDATA)),
                hWnd   = taskbarHandle
            };
            IntPtr result = Shell32.SHAppBarMessage(ABM.GetTaskbarPos, ref data);

            if (result != IntPtr.Zero)
            {
                Position = (TaskbarPosition)data.uEdge;
                Bounds   = Rectangle.FromLTRB(data.rc.left, data.rc.top, data.rc.right, data.rc.bottom);

                data.cbSize = (uint)Marshal.SizeOf(typeof(APPBARDATA));
                result      = Shell32.SHAppBarMessage(ABM.GetState, ref data);
                int state = result.ToInt32();
                AlwaysOnTop = (state & ABS.AlwaysOnTop) == ABS.AlwaysOnTop;
                AutoHide    = (state & ABS.Autohide) == ABS.Autohide;
            }
            else
            {
                Position = TaskbarPosition.Unknown;
            }
        }
Beispiel #2
0
    public Taskbar()
    {
        IntPtr taskbarHandle = User32.FindWindow(Taskbar.ClassName, null);

        APPBARDATA data = new APPBARDATA();

        data.cbSize = (uint)Marshal.SizeOf(typeof(APPBARDATA));
        data.hWnd   = taskbarHandle;
        IntPtr result = Shell32.SHAppBarMessage(ABM.GetTaskbarPos, ref data);

        if (result == IntPtr.Zero)
        {
            throw new InvalidOperationException();
        }

        this.Position = (TaskbarPosition)data.uEdge;
        this.Bounds   = Rectangle.FromLTRB(
            data.rc.left,
            data.rc.top,
            data.rc.right,
            data.rc.bottom
            );

        data.cbSize = (uint)Marshal.SizeOf(typeof(APPBARDATA));
        result      = Shell32.SHAppBarMessage(ABM.GetState, ref data);
        int state = result.ToInt32();

        this.AlwaysOnTop = (state & ABS.AlwaysOnTop) == ABS.AlwaysOnTop;
        this.AutoHide    = (state & ABS.Autohide) == ABS.Autohide;
    }
Beispiel #3
0
        public static void AdjustForAutoHideTaskbar(IntPtr hAppMonitor, ref RECT workspace)
        {
            // NOTE: for xp the adjustment for autohidden taskbar makes maximized window movable
            // but I don't know the way to fix it.
            IntPtr htaskbar = User32.FindWindow("Shell_TrayWnd", null);

            if (htaskbar != IntPtr.Zero)
            {
                IntPtr monitorWithTaskbarOnIt = User32.MonitorFromWindow(htaskbar, MonitorOption.MONITOR_DEFAULTTONEAREST);
                if (hAppMonitor.Equals(monitorWithTaskbarOnIt))
                {
                    APPBARDATA abd = new APPBARDATA();
                    abd.cbSize = (uint)Marshal.SizeOf(abd);
                    abd.hWnd   = htaskbar;
                    bool autoHide = (Shell32.SHAppBarMessage(AppBarMessage.ABM_GETSTATE, ref abd).ToUInt32() & ABS_AUTOHIDE) == ABS_AUTOHIDE;

                    if (autoHide)
                    {
                        Shell32.SHAppBarMessage(AppBarMessage.ABM_GETTASKBARPOS, ref abd);
                        var uEdge = GetEdge(ref abd.rc);

                        switch (uEdge)
                        {
                        case AppBarEdge.ABE_LEFT:
                            workspace.left += 2;
                            break;

                        case AppBarEdge.ABE_RIGHT:
                            workspace.right -= 2;
                            break;

                        case AppBarEdge.ABE_TOP:
                            workspace.top += 2;
                            break;

                        case AppBarEdge.ABE_BOTTOM:
                            workspace.bottom -= 2;
                            break;
                        }
                    }
                }
            }
        }
Beispiel #4
0
        public Taskbar(WindowHandle taskbarWindowHandle)
        {
            this.taskbarWindowHandle = taskbarWindowHandle;
            className = taskbarWindowHandle.GetClassName();

            var appBarData = APPBARDATA.NewInstance();

            IntPtr getTaskbarPosMessageResult = Shell32.SHAppBarMessage(Shell32.ABM_GETTASKBARPOS, ref appBarData);

            if (getTaskbarPosMessageResult == IntPtr.Zero)
            {
                throw new InvalidOperationException("Error fetching taskbar data.");
            }

            this.Position = (TaskbarPosition)appBarData.uEdge;
            this.Bounds   = Rectangle.FromLTRB(appBarData.rc.Left, appBarData.rc.Top, appBarData.rc.Right, appBarData.rc.Bottom);

            appBarData.cbSize = APPBARDATA.GetSizeOfAPPBARDATAType();
            int taskbarState = Shell32.SHAppBarMessage(Shell32.ABM_GETSTATE, ref appBarData).ToInt32();

            this.IsAutoHideEnabled = (taskbarState & Shell32.ABS_AUTOHIDE) == Shell32.ABS_AUTOHIDE;
        }
Beispiel #5
0
            public Taskbar(bool secondary)
            {
                Handle = User32.FindWindow(!secondary ? ClassName : SecondaryClassName, null);

                if (Handle == IntPtr.Zero)
                {
                    return;
                }

                var data = new APPBARDATA {
                    cbSize = (uint)Marshal.SizeOf(typeof(APPBARDATA)), hWnd = Handle
                };
                var result = Shell32.SHAppBarMessage(ABM.GetTaskbarPos, ref data);

                if (result == IntPtr.Zero)
                {
                    throw new InvalidOperationException();
                }

                Position = (TaskbarPosition)data.uEdge;
                Bounds   = Rectangle.FromLTRB(data.rc.left, data.rc.top, data.rc.right, data.rc.bottom);

                data.cbSize = (uint)Marshal.SizeOf(typeof(APPBARDATA));
                result      = Shell32.SHAppBarMessage(ABM.GetState, ref data);
                var state = result.ToInt32();

                AlwaysOnTop = (state & ABS.AlwaysOnTop) == ABS.AlwaysOnTop;
                AutoHide    = (state & ABS.Autohide) == ABS.Autohide;

                var lpRect = new RECT();

                User32.GetWindowRect(Handle, ref lpRect);
                VisibleBounds = Rectangle.FromLTRB(lpRect.left, lpRect.top, lpRect.right, lpRect.bottom);

                /*Debug.WriteLine(this.Bounds);
                 * Debug.WriteLine(lpRect.top + "-------------------");*/
            }