Skip to content

Commit ed27dce

Browse files
authored
Merge pull request #2703 from ThunderFrame/next
Better status bar handling if active component has open designer, UI tweaks for Extract Interface
2 parents 12a6e8b + c57c9b8 commit ed27dce

File tree

5 files changed

+81
-43
lines changed

5 files changed

+81
-43
lines changed

RetailCoder.VBE/UI/Refactorings/ExtractInterfaceDialog.Designer.cs

Lines changed: 36 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.VBEEditor/SafeComWrappers/Abstract/IVBE.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public interface IVBE : ISafeComWrapper, IEquatable<IVBE>
2121
IWindows Windows { get; }
2222

2323
IHostApplication HostApplication();
24+
IWindow ActiveMDIChild();
2425

2526
bool IsInDesignMode { get; }
2627
}

Rubberduck.VBEEditor/SafeComWrappers/VB6/VBE.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ public IHostApplication HostApplication()
109109
return null;
110110
}
111111

112+
public IWindow ActiveMDIChild()
113+
{
114+
throw new NotImplementedException();
115+
}
116+
112117
public bool IsInDesignMode
113118
{
114119
get { return VBProjects.All(project => project.Mode == EnvironmentMode.Design); }

Rubberduck.VBEEditor/SafeComWrappers/VBA/VBE.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
using System.IO;
44
using System.Linq;
55
using System.Runtime.InteropServices;
6+
using System.Text;
67
using Rubberduck.VBEditor.Application;
78
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
89
using Rubberduck.VBEditor.SafeComWrappers.MSForms;
910
using Rubberduck.VBEditor.SafeComWrappers.Office.Core;
1011
using Rubberduck.VBEditor.SafeComWrappers.Office.Core.Abstract;
12+
using Rubberduck.VBEditor.WindowsApi;
1113
using VB = Microsoft.Vbe.Interop;
1214

1315
namespace Rubberduck.VBEditor.SafeComWrappers.VBA
@@ -279,6 +281,33 @@ public IHostApplication HostApplication()
279281
return null;
280282
}
281283

284+
/// <summary> Returns the topmost MDI child window. </summary>
285+
public IWindow ActiveMDIChild()
286+
{
287+
const string mdiClientClass = "MDIClient";
288+
const int maxCaptionLength = 512;
289+
290+
IntPtr mainWindow = (IntPtr)MainWindow.HWnd;
291+
292+
IntPtr mdiClient = NativeMethods.FindWindowEx(mainWindow, IntPtr.Zero, mdiClientClass, string.Empty);
293+
294+
IntPtr mdiChild = NativeMethods.GetTopWindow(mdiClient);
295+
StringBuilder mdiChildCaption = new StringBuilder();
296+
int captionLength = NativeMethods.GetWindowText(mdiChild, mdiChildCaption, maxCaptionLength);
297+
298+
if (captionLength > 0)
299+
{
300+
try
301+
{
302+
return Windows.FirstOrDefault(win => win.Caption == mdiChildCaption.ToString());
303+
}
304+
catch
305+
{
306+
}
307+
}
308+
return null;
309+
}
310+
282311
/// <summary> Returns whether the host supports unit tests.</summary>
283312
public bool HostSupportsUnitTests()
284313
{

Rubberduck.VBEEditor/WindowsApi/NativeMethods.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ public static class NativeMethods
4949
internal static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
5050

5151

52+
/// <summary> Gets the child window at the top of the Z order. </summary>
53+
///
54+
/// <param name="hWnd"> The window handle. </param>
55+
/// <returns> The child window IntPtr handle. </returns>
56+
[DllImport("user32.dll")]
57+
internal static extern IntPtr GetTopWindow(IntPtr hWnd);
58+
59+
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
60+
internal static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle);
61+
5262
/// <summary> Gets window caption text by handle. </summary>
5363
///
5464
/// <param name="windowHandle"> Handle of the window to be activated. </param>

0 commit comments

Comments
 (0)