zaafar / ClickableTransparentOverlay

A library for creating transparent overlay using windows API & ImGui.NET
Apache License 2.0
94 stars 32 forks source link

WindowHandle not exposed #68

Closed TwoTenPvP closed 4 months ago

TwoTenPvP commented 7 months ago

This issue is twofold

  1. The window handle is not exposed. I have to steal it with reflection to temporarily accomplish the things I request.

    protected override Task PostInitialized()
    {
    var handleField = typeof(Overlay).GetField("window", BindingFlags.NonPublic | BindingFlags.Instance);
    
    if (handleField == null)
        throw new Exception("Failed to get window field");
    
    object? window = handleField.GetValue(this);
    
    if (window == null)
        throw new Exception("Failed to get window value");
    
    object? handle = window.GetType().GetField("Handle")?.GetValue(window);
    
    if (handle == null)
        throw new Exception("Failed to get handle value"); 
    
    windowHandle = (IntPtr)handle;
    
    return Task.CompletedTask;
    }
  2. A lot of native things are not exposed.

  3. A) I cannot put the overlay ontop of another window. I have to do:

    IntPtr hwndInsertAfter = Win32.GetWindow(windowHandle, Win32.WindowCommand.Previous);
    if (hwndInsertAfter == this.windowHandle)
    return;
    Win32.SetWindowPos(this.windowHandle, hwndInsertAfter, 0, 0, 0, 0, Win32.SwpFlags.NoSize | Win32.SwpFlags.NoMove | Win32.SwpFlags.NoActivate | Win32.SwpFlags.AsyncWindowPos) ? 1 : 0;
  4. B) I cannot change the window decoration, for example removing the window.

  // Hide the window
  var style = Win32.GetWindowLong(windowHandle, Win32.GWL_EXSTYLE);
  Win32.SetWindowLong(windowHandle, Win32.GWL_EXSTYLE, (style & -Win32.WS_EX_APPWINDOW) | Win32.WS_EX_TOOLWINDOW);
zaafar commented 7 months ago

I will expose the window handle.

zaafar commented 4 months ago

done in version 10.1.0. feel free to re-open the issue if there is something else.