WinSetAlwaysOnTop not working

Issue #23 closed
Winter Laite created an issue

Working AHK code:

MyGui := Gui(, "KEYSHARP TESTS")
WinSetAlwaysOnTop(1, MyGui)
MyEdit := MyGui.Add("Edit", "w400 h400")

MyGui.Show()

Truncated error message from Keysharp:

Uncaught exception:

Message: Unable to cast object of type 'Keysharp.Core.Gui' to type 'System.IConvertible'.

Stack:    at System.Convert.ToInt32(Object value)

Comments (6)

  1. Winter Laite reporter

    Workaround using DllCall:

    SetTitleMatchMode(2)
    MyGui := Gui(, "KEYSHARP TESTS")
    MyEdit := MyGui.Add("Edit", "w400 h400")
    SetWindowAlwaysOnTop()
    MyGui.Show()
    
    
    SetWindowAlwaysOnTop() {
        HWND_TOPMOST := -1
        SWP_NOSIZE := 0x0001
        SWP_NOMOVE := 0x0002
        SWP_SHOWWINDOW := 0x0040
        DllCall("SetWindowPos", "Ptr", MyGui.Hwnd, "Ptr", HWND_TOPMOST, "Int", 0, "Int", 0, "Int", 0, "Int", 0, "Uint", SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW)
    }
    

    This sets the GUI always on top.

  2. Winter Laite reporter

    Working code, thanks for the tip. This is another difference between AHK and Keysharp, please mark resolved and close.

    A_DetectHiddenWindows := True ; Necessary in Keysharp
    MyGui := Gui(, "KEYSHARP TESTS")
    WinSetAlwaysOnTop(1, MyGui)
    MyEdit := MyGui.Add("Edit", "w400 h400")
    
    MyGui.Show()
    

  3. Winter Laite reporter

    To avoid having to use A_DetectHiddenWindows := True, code like that shown below works.

    MyGui := Gui(, "KEYSHARP TESTS")
    MyGui.Opt("+AlwaysOnTop")
    MyEdit := MyGui.Add("Edit", "w400 h400")
    
    MyGui.Show()
    

  4. Winter Laite reporter

    Please mark as resolved and closed, unless you feel the remaining minor issue needs addressing. Thanks!

  5. Log in to comment