Skip to content

Commit

Permalink
Core, win, wpf version 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dsafa committed Oct 4, 2018
2 parents 91a3569 + 6f06691 commit 4f7ce21
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 25 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ Use `CSDeskBandWin` for winforms or `CSDeskBandWpf` for wpf
- For a winforms usercontrol, inherit the `CSDeskBandWin` base class. _See Sample.Win_
- For a wpf usercontol, Set `CSdeskBandWpf` as the root element in the XAML. _See Sample.Wpf_

Add `[ComVisible(true)]`, `[Guid("xx-xx-xx-xx-xx")]`, `[CSDeskBandRegistration()]` attributes to the class
Add `[ComVisible(true)]`, `[Guid("xx-xx-xx-xx-xx")]`, `[CSDeskBandRegistration()]` attributes to the class.
The `CSDeskBandRegistration` attribute allows you to configure:
- Name : The name of the deskband shown in the toolbars menu
- ShowDeskBand : True if the deskband should be shown automatically after registration


```C#
Expand All @@ -31,7 +34,7 @@ using CSDeskBand;

[ComVisible(true)]
[Guid("5731FC61-8530-404C-86C1-86CCB8738D06")]
[CSDeskBandRegistration(Name = "Sample Winforms Deskband")]
[CSDeskBandRegistration(Name = "Sample Winforms Deskband", ShowDeskBand = True)]
public partial class UserControl1 : CSDeskBandWin
{
...
Expand All @@ -43,8 +46,7 @@ Now you are ready to start working on it like a normal user control.
**Patch notes will be in the [release](https://github.com/dsafa/CSDeskBand/releases) page**
### Deskband Installation
You need to start an elevated command prompt and be able to use `regasm.exe`
An easy way to do this is use the Developer Command Prompt for Visual Studio. Make sure that you use the correct version of regasm that matches your platform (x86/x64).
You need to start an elevated command prompt and be able to use `regasm.exe`. Make sure that you use the correct version of regasm that matches your platform (x86/x64).
```
cd Sample.Win\bin\Debug

Expand All @@ -61,8 +63,10 @@ regasm Sample.Win.dll
```
_Note that GAC installation requires the assemblies to be [Strong-Named](https://docs.microsoft.com/en-us/dotnet/framework/app-domains/strong-named-assemblies)_
Here is an [example .bat file](./tools/install-example.bat) for installing a deskband.

## Examples
There are examples included for Winforms and WPF in the Sample.Win and Sample.Wpf projects
There are example deskbands included for Winforms and WPF in the [Sample.Win](https://github.com/dsafa/CSDeskBand/tree/master/src/Sample.Win) and [Sample.Wpf](https://github.com/dsafa/CSDeskBand/tree/master/src/Sample.Wpf) projects.

### Compatibility
Tested on Windows 10 x64
6 changes: 0 additions & 6 deletions build/install-examples.cmd

This file was deleted.

6 changes: 0 additions & 6 deletions build/uninstall-examples.cmd

This file was deleted.

2 changes: 1 addition & 1 deletion src/CSDeskBand.Win/CSDeskband.Win.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<copyright>Copyright 2018</copyright>
<tags>Deskband</tags>
<dependencies>
<dependency id="CSDeskBand" version="2.0.1" />
<dependency id="CSDeskBand" version="2.1.0" />
</dependencies>
<frameworkAssemblies>
<frameworkAssembly assemblyName="System.Windows.Forms"/>
Expand Down
2 changes: 1 addition & 1 deletion src/CSDeskBand.Wpf/CSDeskband.Wpf.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<copyright>Copyright 2018</copyright>
<tags>Deskband</tags>
<dependencies>
<dependency id="CSDeskBand" version="2.0.1" />
<dependency id="CSDeskBand" version="2.1.0" />
</dependencies>
<frameworkAssemblies>
<frameworkAssembly assemblyName="PresentationFramework"/>
Expand Down
53 changes: 49 additions & 4 deletions src/CSDeskBand/CSDeskBandImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ private void Options_PropertyChanged(object sender, System.ComponentModel.Proper
}
_logger.Debug("Deskband options have changed");

var parent = (IOleCommandTarget) _parentSite;
var parent = (IOleCommandTarget)_parentSite;
// Set pvaln to the id that was passed in SetSite
// When int is marshalled to variant, it is marshalled as VT_i4. See default marshalling for objects
parent.Exec(ref CGID_DeskBand, (uint) tagDESKBANDCID.DBID_BANDINFOCHANGED, 0, IntPtr.Zero, IntPtr.Zero);
parent.Exec(ref CGID_DeskBand, (uint)tagDESKBANDCID.DBID_BANDINFOCHANGED, 0, IntPtr.Zero, IntPtr.Zero);
}

public int GetWindow(out IntPtr phwnd)
Expand Down Expand Up @@ -223,6 +223,46 @@ public static void Register(Type t)
subKey.CreateSubKey(ComponentCategoryManager.CATID_DESKBAND.ToString("B"));

Console.WriteLine($"Succesfully registered deskband `{GetToolbarName(t)}` - GUID: {guid}");

if (GetToolbarRequestToShow(t))
{
Console.WriteLine($"Request to show deskband.");
///https://www.pinvoke.net/default.aspx/Interfaces.ITrayDeskband
ITrayDeskband csdeskband = null;
try
{
Type trayDeskbandType = System.Type.GetTypeFromCLSID(new Guid("E6442437-6C68-4f52-94DD-2CFED267EFB9"));
Guid deskbandGuid = t.GUID;
csdeskband = (ITrayDeskband)Activator.CreateInstance(trayDeskbandType);
if (csdeskband != null)
{
csdeskband.DeskBandRegistrationChanged();

if (csdeskband.IsDeskBandShown(ref deskbandGuid) == HRESULT.S_FALSE)
{
if (csdeskband.ShowDeskBand(ref deskbandGuid) != HRESULT.S_OK)
{
Console.WriteLine($"Error while trying to show deskband.");
}
if(csdeskband.DeskBandRegistrationChanged() == HRESULT.S_OK)
{
Console.WriteLine($"The deskband was Succesfully shown with taskbar.{Environment.NewLine}You may see the alert notice box from explorer call.");
}
}
}
}
catch (Exception e)
{
Console.WriteLine($"Error while trying to show deskband: {e.ToString()}");
}
finally
{
if (csdeskband != null && Marshal.IsComObject(csdeskband))
{
Marshal.ReleaseComObject(csdeskband);
}
}
}
}
catch (Exception)
{
Expand Down Expand Up @@ -257,12 +297,17 @@ internal static string GetToolbarName(Type t)
return t.GetCustomAttribute<CSDeskBandRegistrationAttribute>(true)?.Name ?? t.Name;
}

internal static bool GetToolbarRequestToShow(Type t)
{
return t.GetCustomAttribute<CSDeskBandRegistrationAttribute>(true)?.ShowDeskBand ?? false;
}

public int QueryContextMenu(IntPtr hMenu, uint indexMenu, uint idCmdFirst, uint idCmdLast, QueryContextMenuFlags uFlags)
{
_logger.Debug($"Was queried for context menu - index: {indexMenu} cmd first: {idCmdFirst}, cmd last: {idCmdLast}, flags: {uFlags}");
if (uFlags.HasFlag(QueryContextMenuFlags.CMF_DEFAULTONLY))
{
return HRESULT.MakeHResult((uint) HRESULT.S_OK, 0, 0);
return HRESULT.MakeHResult((uint)HRESULT.S_OK, 0, 0);
}

_menutStartId = idCmdFirst;
Expand Down Expand Up @@ -358,7 +403,7 @@ public int Save(object pStm, bool fClearDirty)

public void CloseDeskBand()
{
var bandSite = (IBandSite) _parentSite;
var bandSite = (IBandSite)_parentSite;
bandSite.RemoveBand(_id);
}

Expand Down
5 changes: 5 additions & 0 deletions src/CSDeskBand/CSDeskBandRegistrationAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ public sealed class CSDeskBandRegistrationAttribute : Attribute
/// The name is used to select the deskband from the toolbars menu.
/// </value>
public string Name { get; set; }

/// <summary>
/// Request ShowDeskBand after succesfully registered deskband
/// </summary>
public bool ShowDeskBand { get; set; }
}
}
1 change: 1 addition & 0 deletions src/CSDeskBand/CSDeskband.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<Compile Include="Interop\COM\IInputObject.cs" />
<Compile Include="Interop\COM\IPersist.cs" />
<Compile Include="Interop\COM\IPersistStream.cs" />
<Compile Include="Interop\COM\ITrayDeskband.cs" />
<Compile Include="Interop\HRESULT.cs" />
<Compile Include="ICSDeskBand.cs" />
<Compile Include="Interop\APPBARDATA.cs" />
Expand Down
23 changes: 23 additions & 0 deletions src/CSDeskBand/Interop/COM/ITrayDeskband.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace CSDeskBand.Interop.COM
{
[ComImport, Guid("6D67E846-5B9C-4db8-9CBC-DDE12F4254F1"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface ITrayDeskband
{
[PreserveSig]
int ShowDeskBand([In, MarshalAs(UnmanagedType.Struct)] ref Guid clsid);
[PreserveSig]
int HideDeskBand([In, MarshalAs(UnmanagedType.Struct)] ref Guid clsid);
[PreserveSig]
int IsDeskBandShown([In, MarshalAs(UnmanagedType.Struct)] ref Guid clsid);
[PreserveSig]
int DeskBandRegistrationChanged();
}
}
2 changes: 1 addition & 1 deletion src/Sample.Win/UserControl1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Sample.Win
/// </summary>
[ComVisible(true)]
[Guid("5731FC61-8530-404C-86C1-86CCB8738D06")]
[CSDeskBandRegistration(Name = "Sample Winforms Deskband")]
[CSDeskBandRegistration(Name = "Sample Winforms Deskband", ShowDeskBand = true)]
public partial class UserControl1 : CSDeskBandWin
{
private readonly WinEventDelegate _delegate;
Expand Down
2 changes: 1 addition & 1 deletion src/Sample.Wpf/UserControl1.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Sample.Wpf
/// </summary>
[ComVisible(true)]
[Guid("89BF6B36-A0B0-4C95-A666-87A55C226986")]
[CSDeskBandRegistration(Name = "Sample WPF Deskband")]
[CSDeskBandRegistration(Name = "Sample WPF Deskband", ShowDeskBand = true)]
public partial class UserControl1 : INotifyPropertyChanged
{
private Orientation _taskbarOrientation;
Expand Down
23 changes: 23 additions & 0 deletions tools/install-example.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@echo OFF
title Install DeskBand
@echo ON
@setlocal enableextensions
@cd /d "%~dp0"

rem Check permissions
net session >nul 2>&1
if %errorLevel% == 0 (
echo Administrative permissions confirmed.
) else (
echo Please run this script with administrator permissions.
pause
goto EXIT
)

if defined %PROGRAMFILES(x86)% (
rem use /unregister to uninstall
%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\regasm.exe /nologo /codebase "Sample.Win.dll"
) else (
%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\regasm.exe /nologo /codebase "Sample.Win.dll"
)
pause

0 comments on commit 4f7ce21

Please sign in to comment.