Skip to content

Commit 2ca2ae0

Browse files
committed
A little more work on the deskbands
1 parent 4f1f935 commit 2ca2ae0

File tree

4 files changed

+53
-36
lines changed

4 files changed

+53
-36
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Runtime.InteropServices;
2+
using System.Security;
3+
4+
namespace SharpShell.Interop
5+
{
6+
/// <summary>
7+
/// Exposes methods that change UI activation and process accelerators for a user input object contained in the Shell.
8+
/// </summary>
9+
[ComImport]
10+
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
11+
[Guid("68284faa-6a48-11d0-8c78-00c04fd918b4")]
12+
[SuppressUnmanagedCodeSecurity]
13+
public interface IInputObject
14+
{
15+
/// <summary>
16+
/// UI-activates or deactivates the object.
17+
/// </summary>
18+
/// <param name="fActivate">Indicates if the object is being activated or deactivated. If this value is nonzero, the object is being activated. If this value is zero, the object is being deactivated.</param>
19+
/// <param name="msg">A pointer to an MSG structure that contains the message that caused the activation change. This value may be NULL.</param>
20+
/// <returns>If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
21+
[PreserveSig]
22+
int UIActivateIO(int fActivate, ref MSG msg);
23+
24+
/// <summary>
25+
/// Determines if one of the object's windows has the keyboard focus.
26+
/// </summary>
27+
/// <returns>Returns S_OK if one of the object's windows has the keyboard focus, or S_FALSE otherwise.</returns>
28+
[PreserveSig]
29+
int HasFocusIO();
30+
31+
/// <summary>
32+
/// Enables the object to process keyboard accelerators.
33+
/// </summary>
34+
/// <param name="msg">The address of an MSG structure that contains the keyboard message that is being translated.</param>
35+
/// <returns>Returns S_OK if the accelerator was translated, or S_FALSE otherwise.</returns>
36+
[PreserveSig]
37+
int TranslateAcceleratorIO(ref MSG msg);
38+
}
39+
}

SharpShell/SharpShell/Interop/IPersistStream.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
22
using System.Runtime.InteropServices;
3-
using System.Runtime.InteropServices.ComTypes;
4-
53
namespace SharpShell.Interop
64
{
75
/// <summary>
@@ -28,7 +26,7 @@ public interface IPersistStream : IPersist
2826
/// <param name="pStm">An IStream pointer to the stream from which the object should be loaded.</param>
2927
/// <returns>This method can return the following values. S_OK, E_OUTOFMEMORY, E_FAIL.</returns>
3028
[PreserveSig]
31-
int Load(IStream pStm);
29+
int Load([In, MarshalAs(UnmanagedType.Interface)] object pStm);
3230

3331
/// <summary>
3432
/// Saves an object to the specified stream.
@@ -37,14 +35,14 @@ public interface IPersistStream : IPersist
3735
/// <param name="fClearDirty">Indicates whether to clear the dirty flag after the save is complete. If TRUE, the flag should be cleared. If FALSE, the flag should be left unchanged.</param>
3836
/// <returns>This method can return the following values. S_OK, STG_E_CANTSAVE, STG_E_MEDIUMFULL.</returns>
3937
[PreserveSig]
40-
int Save(IStream pStm, bool fClearDirty);
38+
int Save([In, MarshalAs(UnmanagedType.Interface)] IntPtr pStm, bool fClearDirty);
4139

4240
/// <summary>
4341
/// Retrieves the size of the stream needed to save the object.
4442
/// </summary>
4543
/// <param name="pcbSize">The size in bytes of the stream needed to save this object, in bytes.</param>
4644
/// <returns>This method returns S_OK to indicate that the size was retrieved successfully.</returns>
4745
[PreserveSig]
48-
int GetSizeMax(out UInt64 pcbSize);
46+
int GetSizeMax(out ulong pcbSize);
4947
}
5048
}

SharpShell/SharpShell/SharpDeskBand/SharpDeskBand.cs

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Drawing;
4-
using System.Linq;
5-
using System.Security.AccessControl;
6-
using System.Text;
7-
using Microsoft.Win32;
83
using SharpShell.Attributes;
94
using SharpShell.Components;
10-
using SharpShell.Extensions;
115
using SharpShell.Interop;
126
using System.Windows.Forms;
137
using SharpShell.ServerRegistration;
@@ -38,11 +32,6 @@ protected SharpDeskBand()
3832
/// The handle to the parent window site.
3933
/// </summary>
4034
private IntPtr parentWindowHandle;
41-
42-
/// <summary>
43-
/// The band ID provided by explorer to identify the band.
44-
/// </summary>
45-
private uint explorerBandId = 0;
4635

4736
#region Implmentation of the IObjectWithSite interface
4837

@@ -70,7 +59,14 @@ int IObjectWithSite.SetSite(object pUnkSite)
7059
// If we have not been provided a site, the band is being removed.
7160
if (pUnkSite == null)
7261
{
73-
DestroyBand();
62+
OnBandRemoved();
63+
if (lazyDeskBand.IsValueCreated)
64+
{
65+
lazyDeskBand.Value.Hide();
66+
User32.SetParent(lazyDeskBand.Value.Handle, IntPtr.Zero);
67+
lazyDeskBand.Value.Dispose();
68+
lazyDeskBand = new Lazy<UserControl>(CreateDeskBand);
69+
}
7470
return WinError.S_OK;
7571
}
7672

@@ -105,20 +101,6 @@ int IObjectWithSite.SetSite(object pUnkSite)
105101
return WinError.S_OK;
106102
}
107103

108-
private void DestroyBand()
109-
{
110-
// Log key events.
111-
Log("SharpDeskban.DestroyBand called.");
112-
OnBandRemoved();
113-
if (lazyDeskBand.IsValueCreated)
114-
{
115-
lazyDeskBand.Value.Hide();
116-
User32.SetParent(lazyDeskBand.Value.Handle, IntPtr.Zero);
117-
lazyDeskBand.Value.Dispose();
118-
lazyDeskBand = new Lazy<UserControl>(CreateDeskBand);
119-
}
120-
}
121-
122104
#endregion
123105

124106
#region Implementation of IPersistStream
@@ -147,7 +129,7 @@ int IPersistStream.IsDirty()
147129
return WinError.S_FALSE;
148130
}
149131

150-
int IPersistStream.Load(System.Runtime.InteropServices.ComTypes.IStream pStm)
132+
int IPersistStream.Load(object pStm)
151133
{
152134
// Log key events.
153135
Log("IPersistStream.Load called.");
@@ -156,7 +138,7 @@ int IPersistStream.Load(System.Runtime.InteropServices.ComTypes.IStream pStm)
156138
return WinError.S_OK;
157139
}
158140

159-
int IPersistStream.Save(System.Runtime.InteropServices.ComTypes.IStream pStm, bool fClearDirty)
141+
int IPersistStream.Save(IntPtr pStm, bool fClearDirty)
160142
{
161143
// Log key events.
162144
Log("IPersistStream.Save called.");
@@ -219,9 +201,6 @@ int IDeskBand.GetBandInfo(uint dwBandID, DESKBANDINFO.DBIF dwViewMode, ref DESKB
219201
// Log key events.
220202
Log("IDeskBand.GetBandInfo called.");
221203

222-
// Store the band id.
223-
explorerBandId = dwBandID;
224-
225204
// Depending on what we've been asked for, we'll return various band properties.
226205
var bandOptions = GetBandOptions();
227206
var bandUi = lazyDeskBand.Value;

SharpShell/SharpShell/SharpShell.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
<Compile Include="Interop\IDeskBand2.cs" />
101101
<Compile Include="Interop\IExtractIconA.cs" />
102102
<Compile Include="Interop\IExtractIconW.cs" />
103+
<Compile Include="Interop\IInputObject.cs" />
103104
<Compile Include="Interop\IInputObjectSite.cs" />
104105
<Compile Include="Interop\IMAGEINFO.cs" />
105106
<Compile Include="Interop\IMAGELISTDRAWPARAMS.cs" />

0 commit comments

Comments
 (0)