Skip to content

Commit a4fac30

Browse files
committed
Base code for inserting a menu command
1 parent 8b4fe5a commit a4fac30

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

Rubberduck.Main/ComClientLibrary/UI/DockableWindowHost.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ public void AddUserControl(UserControl control, IntPtr vbeHwnd)
386386

387387
control.Dock = DockStyle.Fill;
388388
_userControl.Controls.Add(control);
389-
389+
390390
AdjustSize();
391391
}
392392

@@ -429,6 +429,39 @@ private void AdjustSize()
429429
}
430430
}
431431

432+
private const int WM_SYSCOMMAND = 0x112;
433+
private const int MF_BYPOSITION = 0x400;
434+
private const int ToggleDockableMenuId = 1000;
435+
436+
[DllImport("user32.dll")]
437+
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
438+
[DllImport("user32.dll")]
439+
private static extern bool InsertMenu(IntPtr hMenu, int wPosition, int wFlags, int wIDNewItem, string lpNewItem);
440+
441+
[DllImport("user32.dll", CharSet = CharSet.Auto)]
442+
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, IntPtr lParam);
443+
444+
private static void InsertDockableToggle(IntPtr handle)
445+
{
446+
var menuHandle = GetSystemMenu(handle, false);
447+
448+
if (menuHandle == IntPtr.Zero)
449+
{
450+
Debug.Print("No menu handle");
451+
return;
452+
}
453+
454+
if (!InsertMenu(menuHandle, 5, MF_BYPOSITION, ToggleDockableMenuId, "Dockable"))
455+
{
456+
Debug.Print("Failed to insert a menu item for dockable command");
457+
}
458+
}
459+
460+
private static void ToggleDockable(IntPtr hWndVBE)
461+
{
462+
SendMessage(hWndVBE, 0x1044, 0xB5, IntPtr.Zero);
463+
}
464+
432465
[ComVisible(false)]
433466
public class ParentWindow : SubclassingWindow
434467
{
@@ -452,6 +485,14 @@ public override int SubClassProc(IntPtr hWnd, IntPtr msg, IntPtr wParam, IntPtr
452485
{
453486
switch ((uint)msg)
454487
{
488+
case (uint)WM.SYSCOMMAND:
489+
switch (wParam.ToInt32())
490+
{
491+
case ToggleDockableMenuId:
492+
ToggleDockable(_vbeHwnd);
493+
break;
494+
}
495+
break;
455496
case (uint)WM.SIZE:
456497
var args = new SubClassingWindowEventArgs(lParam);
457498
if (!_closing) OnCallBackEvent(args);

0 commit comments

Comments
 (0)