private IntPtr AppBarHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == _callbackID)
{
switch (wParam.ToInt32())
{
case APPBARNOTIFY.ABN_POSCHANGED:
if (_cancelReposition != null)
{
_cancelReposition.Cancel();
}
_cancelReposition = new CancellationTokenSource();
Task.Delay(TimeSpan.FromMilliseconds(100), _cancelReposition.Token).ContinueWith(_ =>
{
if (_.IsCanceled)
{
return;
}
Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
{
int _screen;
DockEdge _edge;
WorkArea _windowWA;
WorkArea _appbarWA;
Monitor.GetWorkArea(this, out _screen, out _edge, out _windowWA, out _appbarWA);
SetAppBar(_screen, _edge, _windowWA, _appbarWA, null);
}));
_cancelReposition = null;
});
break;
case APPBARNOTIFY.ABN_FULLSCREENAPP:
if (lParam.ToInt32() == 1)
{
_wasTopMost = IsTopMost;
if (IsTopMost)
{
SetBottom(false);
}
}
else if (_wasTopMost)
{
SetTopMost(false);
}
break;
}
handled = true;
}
return IntPtr.Zero;
}