Skip to content

Commit

Permalink
Issues #5, Issues #8 Fixed detection "Normal" windows and Modal dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderPro committed Feb 10, 2024
1 parent b1668bc commit ebc7267
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
17 changes: 10 additions & 7 deletions SmartContextMenu/Native/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@ static class Constants
public const int DWL_USER = 8;

// WindowStyle
public const int WS_MAXIMIZEBOX = 0x00010000;
public const int WS_MINIMIZEBOX = 0x00020000;
public const int WS_EX_LAYERED = 0x00080000;
public const int WS_EX_TOPMOST = 0x00000008;
public const int WS_EX_TOOLWINDOW = 0x00000080;
public const int WS_EX_TRANSPARENT = 0x20;
public const int WS_EX_NOACTIVATE = 0x08000000;
public const long WS_CAPTION = 0x00C00000L;
public const long WS_SYSMENU = 0x00080000L;
public const long WS_POPUP = 0x80000000L;
public const long WS_MAXIMIZEBOX = 0x00010000L;
public const long WS_MINIMIZEBOX = 0x00020000L;
public const long WS_EX_LAYERED = 0x00080000L;
public const long WS_EX_TOPMOST = 0x00000008L;
public const long WS_EX_TOOLWINDOW = 0x00000080L;
public const long WS_EX_TRANSPARENT = 0x00000020L;
public const long WS_EX_NOACTIVATE = 0x08000000L;

// Window Messages
public const int WM_GETICON = 0x7F;
Expand Down
4 changes: 2 additions & 2 deletions SmartContextMenu/Native/User32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ static class User32
public static extern bool GetWindowPlacement(IntPtr hWnd, ref WindowPlacement lpwndpl);

[DllImport("user32.dll")]
public static extern int SetWindowLong(IntPtr handle, int nIndex, int dwNewLong);
public static extern int SetWindowLong(IntPtr handle, int nIndex, long dwNewLong);

[DllImport("user32.dll")]
public static extern int GetWindowLong(IntPtr handle, int nIndex);
public static extern long GetWindowLong(IntPtr handle, int nIndex);

[DllImport("user32.dll")]
public static extern int GetClassLong(IntPtr handle, int nIndex);
Expand Down
13 changes: 9 additions & 4 deletions SmartContextMenu/Utils/WindowUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@ public static Bitmap PrintWindow(IntPtr hWnd)

public static IntPtr GetParentWindow(IntPtr hWnd)
{
IntPtr parentHwnd;
var resultHwnd = hWnd;
while ((parentHwnd = GetParent(resultHwnd)) != IntPtr.Zero)
IntPtr resultHwnd;
var parentHwnd = hWnd;
do
{
resultHwnd = parentHwnd;
}
var windowStyle = GetWindowLong(resultHwnd, GWL_STYLE);
if ((windowStyle & WS_CAPTION) != 0 || (windowStyle & WS_SYSMENU) != 0 || (windowStyle & WS_POPUP) != 0)
{
return resultHwnd;
}
} while ((parentHwnd = GetParent(resultHwnd)) != IntPtr.Zero);
return resultHwnd;
}

Expand Down
6 changes: 3 additions & 3 deletions SmartContextMenu/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ public int Transparency
{
get
{
int style = GetWindowLong(Handle, GWL_EXSTYLE);
bool isLayeredWindow = (style & WS_EX_LAYERED) == WS_EX_LAYERED;
var style = GetWindowLong(Handle, GWL_EXSTYLE);
var isLayeredWindow = (style & WS_EX_LAYERED) == WS_EX_LAYERED;
if (!isLayeredWindow) return 0;
GetLayeredWindowAttributes(Handle, out _, out var alpha, out _);
int transparency = 100 - (int)Math.Round(100 * alpha / 255f, MidpointRounding.AwayFromZero);
var transparency = 100 - (int)Math.Round(100 * alpha / 255f, MidpointRounding.AwayFromZero);
return transparency;
}
}
Expand Down
8 changes: 4 additions & 4 deletions SmartContextMenu/WindowDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ class WindowDetails

public int DWL_DLGPROC { get; set; }

public int GWL_STYLE { get; set; }
public long GWL_STYLE { get; set; }

public int GCL_STYLE { get; set; }

public int GWL_EXSTYLE { get; set; }
public long GWL_EXSTYLE { get; set; }

public uint WindowInfoExStyle { get; set; }

public bool LWA_ALPHA { get; set; }

public bool LWA_COLORKEY { get; set; }

public int GWL_ID { get; set; }
public long GWL_ID { get; set; }

public int GWL_USERDATA { get; set; }
public long GWL_USERDATA { get; set; }

public int DWL_USER { get; set; }

Expand Down

0 comments on commit ebc7267

Please sign in to comment.