SidebarDiagnostics.Windows.AppBarWindow.SetAppBar C# (CSharp) Method

SetAppBar() public method

public SetAppBar ( int screen, DockEdge edge, WorkArea windowWA, WorkArea appbarWA, System.Action callback ) : void
screen int
edge DockEdge
windowWA WorkArea
appbarWA WorkArea
callback System.Action
return void
        public void SetAppBar(int screen, DockEdge edge, WorkArea windowWA, WorkArea appbarWA, Action callback)
        {
            if (edge == DockEdge.None)
            {
                throw new ArgumentException("This parameter cannot be set to 'none'.", "edge");
            }

            bool _init = false;

            APPBARDATA _data = NewData();

            if (!IsAppBar)
            {
                IsAppBar = _init = true;

                _callbackID = _data.uCallbackMessage = NativeMethods.RegisterWindowMessage("AppBarMessage");

                NativeMethods.SHAppBarMessage(APPBARMSG.ABM_NEW, ref _data);
            }

            Screen = screen;
            DockEdge = edge;
            
            _data.uEdge = (int)edge;
            _data.rc = new RECT()
            {
                Left = (int)Math.Round(appbarWA.Left),
                Top = (int)Math.Round(appbarWA.Top),
                Right = (int)Math.Round(appbarWA.Right),
                Bottom = (int)Math.Round(appbarWA.Bottom)
            };

            NativeMethods.SHAppBarMessage(APPBARMSG.ABM_QUERYPOS, ref _data);

            NativeMethods.SHAppBarMessage(APPBARMSG.ABM_SETPOS, ref _data);

            appbarWA.Left = _data.rc.Left;
            appbarWA.Top = _data.rc.Top;
            appbarWA.Right = _data.rc.Right;
            appbarWA.Bottom = _data.rc.Bottom;

            AppBarWidth = appbarWA.Width;

            Move(windowWA);

            if (_init)
            {
                Task.Delay(500).ContinueWith(_ =>
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, (Action)(() =>
                    {
                        HwndSource.AddHook(AppBarHook);

                        if (callback != null)
                        {
                            callback();
                        }
                    }));
                });
            }
            else if (callback != null)
            {
                callback();
            }
        }