Skip to content

Commit

Permalink
Updated and cleaned some code. Added click through option. Changed se…
Browse files Browse the repository at this point in the history
…ttings update action to just close the old sidebar window and create a new one.
  • Loading branch information
ArcadeRenegade committed Jan 21, 2016
1 parent fc5059e commit 5a676c8
Show file tree
Hide file tree
Showing 12 changed files with 449 additions and 389 deletions.
3 changes: 3 additions & 0 deletions SidebarDiagnostics/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<setting name="UseAppBar" serializeAs="String">
<value>True</value>
</setting>
<setting name="ClickThrough" serializeAs="String">
<value>False</value>
</setting>
</SidebarDiagnostics.Properties.Settings>
</userSettings>
</configuration>
3 changes: 3 additions & 0 deletions SidebarDiagnostics/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

// CONFIG
ShutdownMode = ShutdownMode.OnExplicitShutdown;

// NOTIFY ICON
MenuItem _settingsMenuItem = new MenuItem()
{
Expand Down
43 changes: 13 additions & 30 deletions SidebarDiagnostics/AppBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class ClickThroughWindow
public static void SetClickThrough(Window window)
{
IntPtr hwnd = new WindowInteropHelper(window).Handle;
var extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
}
}
Expand All @@ -35,7 +35,7 @@ public enum ABEdge : int
None
}

internal static class AppBarFunctions
public static class AppBarFunctions
{
[StructLayout(LayoutKind.Sequential)]
private struct RECT
Expand Down Expand Up @@ -99,8 +99,7 @@ private enum ABNotify : int

[DllImport("User32.dll", CharSet = CharSet.Auto)]
private static extern bool GetMonitorInfo(IntPtr hMonitor, ref MONITORINFO mi);



private const int MONITOR_DEFAULTTONEAREST = 0x2;
private const int MONITORINFOF_PRIMARY = 0x1;

Expand All @@ -114,8 +113,7 @@ private class RegisterInfo
public Point OriginalPosition { get; set; }
public Size OriginalSize { get; set; }
public ResizeMode OriginalResizeMode { get; set; }



public IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam,
IntPtr lParam, ref bool handled)
{
Expand All @@ -137,6 +135,7 @@ public IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam,
private static RegisterInfo GetRegisterInfo(Window appbarWindow)
{
RegisterInfo reg;

if (s_RegisteredWindowInfo.ContainsKey(appbarWindow))
{
reg = s_RegisteredWindowInfo[appbarWindow];
Expand All @@ -157,24 +156,10 @@ private static RegisterInfo GetRegisterInfo(Window appbarWindow)
};
s_RegisteredWindowInfo.Add(appbarWindow, reg);
}
return reg;
}

private static void RestoreWindow(Window appbarWindow)
{
RegisterInfo info = GetRegisterInfo(appbarWindow);

appbarWindow.WindowStyle = info.OriginalStyle;
appbarWindow.ResizeMode = info.OriginalResizeMode;
appbarWindow.Topmost = false;

Rect rect = new Rect(info.OriginalPosition.X, info.OriginalPosition.Y,
info.OriginalSize.Width, info.OriginalSize.Height);
appbarWindow.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
new ResizeDelegate(DoResize), appbarWindow, rect);

return reg;
}

public static void SetAppBar(Window appbarWindow, ABEdge edge)
{
RegisterInfo info = GetRegisterInfo(appbarWindow);
Expand All @@ -192,7 +177,7 @@ public static void SetAppBar(Window appbarWindow, ABEdge edge)
SHAppBarMessage((int)ABMsg.ABM_REMOVE, ref abd);
info.IsRegistered = false;
}
//RestoreWindow(appbarWindow);

return;
}

Expand All @@ -203,9 +188,6 @@ public static void SetAppBar(Window appbarWindow, ABEdge edge)
abd.uCallbackMessage = info.CallbackId;

uint ret = SHAppBarMessage((int)ABMsg.ABM_NEW, ref abd);

//HwndSource source = HwndSource.FromHwnd(abd.hWnd);
//source.AddHook(new HwndSourceHook(info.WndProc));
}

appbarWindow.WindowStyle = WindowStyle.None;
Expand All @@ -215,6 +197,7 @@ public static void SetAppBar(Window appbarWindow, ABEdge edge)
}

private delegate void ResizeDelegate(Window appbarWindow, Rect rect);

private static void DoResize(Window appbarWindow, Rect rect)
{
appbarWindow.Width = rect.Width;
Expand All @@ -237,6 +220,7 @@ private static void GetActualScreenData(ABEdge edge, Window appbarWindow, ref in
{
return;
}

leftOffset = mi.rcWork.left;
topOffset = mi.rcWork.top;
actualScreenWidth = mi.rcWork.right - leftOffset;
Expand Down Expand Up @@ -292,12 +276,11 @@ private static void ABSetPos(ABEdge edge, Window appbarWindow)
SHAppBarMessage((int)ABMsg.ABM_QUERYPOS, ref barData);
SHAppBarMessage((int)ABMsg.ABM_SETPOS, ref barData);

Rect rect = new Rect((double)barData.rc.left, (double)barData.rc.top,
(double)(barData.rc.right - barData.rc.left), (double)(barData.rc.bottom - barData.rc.top));
Rect rect = new Rect((double)barData.rc.left, (double)barData.rc.top, (double)(barData.rc.right - barData.rc.left), (double)(barData.rc.bottom - barData.rc.top));

//This is done async, because WPF will send a resize after a new appbar is added.
//if we size right away, WPFs resize comes last and overrides us.
appbarWindow.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
new ResizeDelegate(DoResize), appbarWindow, rect);
appbarWindow.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new ResizeDelegate(DoResize), appbarWindow, rect);
}
}
}
6 changes: 5 additions & 1 deletion SidebarDiagnostics/AppBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
mc:Ignorable="d"
Loaded="Window_Loaded"
Closing="Window_Closing"
MouseEnter="Window_MouseEnter"
MouseLeave="Window_MouseLeave"
Title="Sidebar"
Height="680" Width="180"
AllowsTransparency="True"
Expand All @@ -27,11 +29,13 @@
</Grid.RowDefinitions>

<StackPanel
x:Name="WindowControlsStackPanel"
Grid.Row="0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Margin="10"
Orientation="Horizontal">
Orientation="Horizontal"
Visibility="Hidden">
<Button x:Name="SettingsButton"
Click="SettingsButton_Click"
HorizontalAlignment="Right"
Expand Down
Loading

0 comments on commit 5a676c8

Please sign in to comment.