Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TWAPI tkpath_to_hwnd bug?

53 views
Skip to first unread message

Eugene

unread,
Mar 15, 2018, 10:32:23 PM3/15/18
to
Hi,

Here's what I'm doing (in wish interactive console, I'm using Tcl 8.6.7):

% package require twapi
4.2.12

% wm title . foo ; # the title changes to "foo"
% set hwnd [::twapi::tkpath_to_hwnd .]
% ::twapi::set_window_text $hwnd bar ; # nothing happens, the title's
still "foo"

What gives? Ok, having done some research I've found that tkpath_to_hwnd
actually returns a handle for TkChild window, which is a child of
TkTopLevel, so if I get the handle like this, everything starts working:

% set hwnd [::twapi::get_parent_window [::twapi::tkpath_to_hwnd .]]

Not sure if it's a quirk of the latest Tk or actually a bug in the
latest TWAPI.

--
Best regards,
Eugene

Ashok

unread,
Mar 16, 2018, 3:51:05 AM3/16/18
to
No, not a bug, nor a quirk:-). Tk "." is not actually a Windows
toplevel window as you have discovered but is wrapped by one. Afaik,
this has always been the case. If you look at the "wm title"
implementation you will probably find it doing the equivalent of the
get_parent_window sequence and setting its title.

/Ashok

Eugene

unread,
Mar 16, 2018, 8:22:31 AM3/16/18
to
On 16-Mar-18 3:51 AM, Ashok wrote:
> No, not a bug, nor a quirk:-). Tk  "." is not actually a Windows
> toplevel window as you have discovered but is wrapped by one. Afaik,
> this has always been the case. If you look at the "wm title"
> implementation you will probably find it doing the equivalent of the
> get_parent_window sequence and setting its title.
>
> /Ashok
>
>

Thank you Ashok, that makes sense. Here's one thing though - it's
confusing as hell :) I was pulling my hair out trying to figure out
what's going on and why nothing works. May I suggest adding a small
clarification to the docs, something like "if you want to work with
toplevel windows, make sure to get the **parent** window handle when
using tkpath_to_hwnd" with an example of how to do it?

--
Best regards,
Eugene

Rich

unread,
Mar 16, 2018, 9:23:50 AM3/16/18
to
While a reasonable request, I suspect the info was omitted because most
of us would think: "if you are using Tk, you'd change the windows title
text via Tk's "wm title" command, not via trying to 'end-run' with
twapi".

At least for myself, I'd never think to use twapi to change a window
title of a Tk window belonging to the Tk script running on MSWin that
created the window. I'd only consider twapi when changing titles of
"other" MSWin windows, that were not created by my current script via
Tk 'toplevel' commands.

Mike Griffiths

unread,
Mar 16, 2018, 4:38:04 PM3/16/18
to
I suspect that this is just an easy example/demonstration of the problem - TWAPI exposes a great many other features for toplevels that aren't available through Tk's [wm] command, but many of which have less easily-demonstrated behaviours and successes/failures.

Eugene

unread,
Mar 16, 2018, 6:40:01 PM3/16/18
to
On 16-Mar-18 4:38 PM, Mike Griffiths wrote:
> On Friday, 16 March 2018 13:23:50 UTC, Rich wrote:
>
> I suspect that this is just an easy example/demonstration of the problem - TWAPI exposes a great many other features for toplevels that aren't available through Tk's [wm] command, but many of which have less easily-demonstrated behaviours and successes/failures.
>

Yes, Mike, you are correct - I've just created a minimal working script
that accurately illustrates the problem with as few commands as
possible. The actual problem I was trying to solve is to get rid of
minimize/maximize boxes in a Tk window while retaining the title, which
is not possible with pure Tk, unless I'm missing something.

--
Best regards,
Eugene

Ashok

unread,
Mar 18, 2018, 2:27:51 AM3/18/18
to
On 3/16/2018 5:52 PM, Eugene wrote:
>
> Thank you Ashok, that makes sense. Here's one thing though - it's
> confusing as hell :) I was pulling my hair out trying to figure out
> what's going on and why nothing works. May I suggest adding a small
> clarification to the docs, something like "if you want to work with
> toplevel windows, make sure to get the **parent** window handle when
> using tkpath_to_hwnd" with an example of how to do it?
>

I've added a blurb to the docs. A new twapi release is a far way off
though, so it probably won't help for a while.

/Ashok
0 new messages