WinMove() places window at the wrong position

Issue #4 closed
Matt Feemster repo owner created an issue
MyGui := Gui("ToolWindow -Sysmenu Disabled", "The clipboard contains:")
MyGui.Add("Text",, A_Clipboard)
MyGui.Show("w400 h300")
WinMove(900, 500,,, MyGui.Title) ; Move the splash window to the top left corner.
MsgBox "Press OK to dismiss the MyGui window"
MyGui.Destroy()

Comments (6)

  1. Matt Feemster reporter

    This is likely due to the recent addition of adding the scaling multiplier to the specified coordinates.

  2. Matt Feemster reporter

    Turns out WinMove() was totally broken with bad code. I am unsure where that came from, but I changed it to match what AHK does. Please retest.

  3. Winter Laite

    The window now moves to the specified coordinates, so that’s fixed. During the course of testing, though, it became apparent that almost all GUI windows are flickering a great deal, (perhaps due to a preload? I don’t want to open an issue on that yet as it’ll likely affect all or most of the GUIs). Here’s the code I used to test.

    MyGui := Gui("", "The clipboard contains:")
    MyGui.Add("Text",, A_Clipboard)
    MsgBox(MyGui.Title)
    MyGui.Show("w400 h300")
    WinMove(10, 10,,, MyGui.Title) ; Move the splash window to the top left corner.
    MsgBox "Press OK to dismiss the MyGui window"
    MyGui.Destroy()
    

    However, if I change to code to that below, a black bar appears to the right of the GUI.

    MyGui := Gui("", "The clipboard contains:")
    MyGui.Add("Text",, A_Clipboard)
    MsgBox(MyGui.Title)
    MyGui.Show("w400 h300")
    Sleep(2000)
    WinMove(10, 10,,, MyGui.Title) ; Move the splash window to the top left corner.
    MsgBox "Press OK to dismiss the MyGui window"
    MyGui.Destroy()
    

  4. Matt Feemster reporter

    Yes, that is an unfortunate artifact due to a collision between how ahk and winforms each work differently.

    When specifying coordinates of controls and such, the form must have called Load() (an internal C# function) at least once for all of the coordinate calculations to be correct, and Load() doesn’t get called in the constructor. Instead, it only gets called after the form is shown.

    That presents a problem: all of our coordinate calculation for placing and sizing of controls is done before we call Show().

    So the only workaround I could devise was to quickly show then hide the window when it’s created with Gui(), then do all of the sizing in a hidden state, then show it when the user requests it with Show().

    I know it’s visually irritating, but ahk and C# have totally different designs.

    I’m closing this ticket.

  5. Log in to comment