Thanks for the support, Timon.
I've got the answer from Stackoverflow.
It's a WPF application that's the reason.
Set foreground of child window in Visual Studio

I want to set the foreground of a window in Visual Studio.
What i've tried:
When i have 2 windows "docked" side by side i can't set the foreground of a window under the mouse in VS. I'm using GetCursorPos and WindowFromPoint which usually works for standard windows. I also tried to use EnumChildWindows from pinvoke.net (sample code 2 -https://www.pinvoke.net/default.aspx/user32.enumchildwindows) but it returns 0 when i pass the WindowFromPoint or MainWindowHandle of the process.
I tested it with Chrome and Remote Desktop Manager which is the only application that i have with docked windows and it works, it doesn't return 0.
Could it be that Microsoft is blocking it intentionally?
If it would work, i have to recognize the right windows under the cursor and to use SetForeground. Maybe it's not the right approach?
Best regards
To get the window handles:
public static IntPtr GetProcessMainWindowHandle()
{
Process process = null;
if (GetCursorPos(out Point point))
{
IntPtr hWnd = WindowFromPoint(point);
GetWindowThreadProcessId(hWnd, out uint pid);
process = Process.GetProcessById((int)pid);
}
return process.MainWindowHandle;
}
public static IntPtr GetHandle()
{
IntPtr hWnd = IntPtr.Zero;
if (GetCursorPos(out Point point))
{
hWnd = WindowFromPoint(point);
}
return hWnd;
}
1 answer
Sort by: Most helpful
-
youki 891 Reputation points
2020-12-16T18:46:10.977+00:00
Hello Timon,
OK, what i do:
When it's the explorer, i use GetHandle. For anything else i use GetProcessMainWindowHandle (mark the window from user perspective) and then GetHandle (activate child window).
I hope it's right explained. I'm testing a lot to find the right behaviour and that works for me.
These are the mentioned docked child windows in VS in the snapshot where i want to SetForeground of a child window under the cursor. I need to get the window and a reference to know that it's the right window to activate.