Skip to content

Commit 9bb5ce6

Browse files
committed
Some windows do not have menu items (2).
1 parent 0960edf commit 9bb5ce6

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

SmartSystemMenu/EnumWindows.cs

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Diagnostics;
55
using SmartSystemMenu.Settings;
66
using SmartSystemMenu.Native;
7+
using SmartSystemMenu.Utils;
78

89
namespace SmartSystemMenu
910
{
@@ -46,6 +47,11 @@ public static IList<Window> EnumProcessWindows(int processId, IntPtr[] filterHan
4647

4748
private static bool EnumWindowCallback(IntPtr hwnd, int lParam)
4849
{
50+
if (!WindowUtils.IsWindowVisibleOrConsole(hwnd))
51+
{
52+
return true;
53+
}
54+
4955
if (_filterHandles.Any(h => h == hwnd))
5056
{
5157
return true;

SmartSystemMenu/Forms/MainForm.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ private void MenuItemExitClick(object sender, EventArgs e)
299299

300300
private void WindowCreated(object sender, WindowEventArgs e)
301301
{
302-
if (e.Handle != IntPtr.Zero && new SystemMenu(e.Handle, _settings.MenuItems, _settings.LanguageSettings).Exists && !_windows.Any(w => w.Handle == e.Handle))
302+
if (e.Handle != IntPtr.Zero && WindowUtils.IsWindowVisibleOrConsole(e.Handle) && !_windows.Any(w => w.Handle == e.Handle))
303303
{
304304
NativeMethods.GetWindowThreadProcessId(e.Handle, out int processId);
305305
IList<Window> windows = new List<Window>();

SmartSystemMenu/SmartSystemMenu64.exe

0 Bytes
Binary file not shown.

SmartSystemMenu/Utils/WindowUtils.cs

+13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@ namespace SmartSystemMenu.Utils
1313
{
1414
static class WindowUtils
1515
{
16+
public static string GetClassName(IntPtr hWnd)
17+
{
18+
var builder = new StringBuilder(1024);
19+
NativeMethods.GetClassName(hWnd, builder, builder.Capacity);
20+
var className = builder.ToString();
21+
return className;
22+
}
23+
24+
public static bool IsWindowVisibleOrConsole(IntPtr hWnd)
25+
{
26+
return IsWindowVisible(hWnd) || GetClassName(hWnd) == "ConsoleWindowClass";
27+
}
28+
1629
public static Bitmap PrintWindow(IntPtr hWnd)
1730
{
1831
Rect rect;

0 commit comments

Comments
 (0)