Reputation: 1
I'm working on an OpenTK project in C# to create a transparent window that lets mouse events pass through. I want to make this OpenTK window click-through by adjusting its extended window styles. However, I'm running into an issue where the IsWindow function doesn't recognize WindowPtr from OpenTK as a valid window handle.
Here is a relevant part of my code:
[DllImport("user32.dll", SetLastError = true)]
private static extern bool IsWindow(IntPtr hWnd);
public static void MakeWindowClickThrough(IntPtr hWnd)
{
int exStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
SetWindowLong(hWnd, GWL_EXSTYLE, exStyle | WS_EX_LAYERED | WS_EX_TRANSPARENT);
}
protected override void OnRenderFrame(FrameEventArgs e)
{
base.OnRenderFrame(e);
if (!_clickThroughSet)
{
IntPtr hWnd = (nint)WindowPtr;
if (IsWindow(hWnd))
{
MakeWindowClickThrough(hWnd);
_clickThroughSet = true;
Console.WriteLine("Click-through style set.");
}
else
{
Console.WriteLine("Waiting for a valid window handle...");
}
}
// ... rest of the rendering code
}
In OnRenderFrame, I try to check if the WindowPtr is a valid window handle using IsWindow(hWnd). However, IsWindow consistently returns false, and the console prints "Waiting for a valid window handle...". My questions:
Upvotes: -1
Views: 48
Reputation: 239636
If you want to obtain an HWND for making any Win32 API calls related to windows, you should be passing your WindowPtr
to the GetWin32Window
function.
Even if multiple frameworks or libraries have a concept of a "Window Handle" it doesn't mean that those frameworks will recognise each others handles or know what to do with them, in general.
Upvotes: 1