• A twapi question: How to go from a HWND to a HWIN

    From Helmut Giese@21:1/5 to All on Tue May 31 22:53:10 2022
    Hello out there,
    many functions return a HWND (get_foreground_window, find_windows,
    etc.) but I would often need a HWIN - and I have not found a way to go
    from one to the other.
    Any help or advice will be greatly appreciated.
    Helmut

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From apn@21:1/5 to Helmut Giese on Wed Jun 1 10:38:19 2022
    On 6/1/2022 2:23 AM, Helmut Giese wrote:
    Hello out there,
    many functions return a HWND (get_foreground_window, find_windows,
    etc.) but I would often need a HWIN - and I have not found a way to go
    from one to the other.
    Any help or advice will be greatly appreciated.
    Helmut

    I'm not quite sure what you mean by needing an HWIN. Some commands might
    have "hwin" as an argument name. But that's just an argument name. It
    might as well be "foo".

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Giese@21:1/5 to All on Wed Jun 1 16:29:56 2022
    Hello Ashok,
    I'm not quite sure what you mean by needing an HWIN. Some commands might
    have "hwin" as an argument name. But that's just an argument name. It
    might as well be "foo".
    well, from 'twapi::get_foreground_window' I got '41224048 HWND' and I
    read in twapi's documentation 'set_foreground_window HWIN' - so I
    assumed that those are 2 different types. All the better if they are
    not.

    I am trying to give a certain window the focus but failed miserably.
    I have this little test script t.tcl:
    ---
    package require Tk
    package require twapi

    wm title "." "Test" --------- this is used below
    set t [text .t -width 40 -height 10]
    pack $t
    $t insert end "aaa\nbbb\nccc\n"
    focus $t
    ---
    and in TkCon I do this:
    ---
    loading history file ... 42 events added
    buffer line limit: 512 max line length: unlimited
    Main console display active (Tcl8.6.10 / Tk8.6.10)
    (GUI) 43 % source t.tcl
    (GUI) 44 % set hwnd [twapi::find_windows -match glob -text Test]
    {11535582 HWND} ----- this identifies my test window
    (GUI) 45 % twapi::set_focus $hwnd
    Invalid pointer or opaque value '{11535582 HWND}'.
    (GUI) 46 % twapi::set_focus $hwnd [lindex $hwnd 0]
    wrong # args: should be "twapi::set_focus hwin"
    (GUI) 47 % twapi::set_foreground_window $hwnd
    Invalid pointer or opaque value '{11535582 HWND}'.
    (GUI) 48 % twapi::set_foreground_window $hwnd [lindex $hwnd 0]
    wrong # args: should be "twapi::set_foreground_window hwin"
    (GUI) 49 %
    ---
    So evidently I am doing something wrong or did not yet understand it -
    but how am I supposed to use the result of 'find_windows' and similar functions?

    Any help or advice will be greatly appreciated.
    Helmut

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From greg@21:1/5 to All on Wed Jun 1 08:46:24 2022
    tkwait visibility .t


    set hwnd [twapi::find_windows -match glob -text Test]
    twapi::set_focus [lindex $hwnd 0]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From apn@21:1/5 to greg on Wed Jun 1 21:59:13 2022
    On 6/1/2022 9:16 PM, greg wrote:
    tkwait visibility .t


    set hwnd [twapi::find_windows -match glob -text Test]
    twapi::set_focus [lindex $hwnd 0]




    To further elaborate what Greg wrote, find_windows returns a list of
    window handles. Even if there is only one match, it is still a list so
    you need to extract the first element.

    Also, it might be more robust to call twapi::set_foreground_window as
    well as set_focus. I seem to remember some circumstances where it was
    needed but don't recall the details.


    /Ashok

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Giese@21:1/5 to All on Wed Jun 1 21:25:58 2022
    Hello Ashok and Greg,
    'tkwait' did the trick.
    Many thanks to both of you.
    Helmut

    On 6/1/2022 9:16 PM, greg wrote:
    tkwait visibility .t


    set hwnd [twapi::find_windows -match glob -text Test]
    twapi::set_focus [lindex $hwnd 0]




    To further elaborate what Greg wrote, find_windows returns a list of
    window handles. Even if there is only one match, it is still a list so
    you need to extract the first element.

    Also, it might be more robust to call twapi::set_foreground_window as
    well as set_focus. I seem to remember some circumstances where it was
    needed but don't recall the details.


    /Ashok

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)