From: Robert M. <rob...@us...> - 2007-04-24 19:35:16
|
On 16/04/07, Perl Rob <pe...@co...> wrote: > I'm using the "-topmost" option on my window to make it start out always on > top. However, I'd like to provide a check box (labeled "Always on top" and > checked by default) that allows the user to toggle whether the window stays > on top or doesn't. Unfortunately, I can't get the change to take effect. > Below is the code I'm trying. What am I doing wrong (or is this even > possible)? > > sub AlwaysOnTop_Click > { > $aot_state = $aot_check_box->GetCheck(); > if ($aot_state == 0) > { > Win32::GUI::Change($main, -topmost => 0); > } [snip] Unfortunately -topmost is one of a small number of things that you can't simply Change() after creating a window (all the topmost option does is toggle the WS_EX_TOPMOST flag, which is documented by MS as not the way to do it). The 'correct' way to change the topmost state of a window is using the SetWindowPos() method. Here's some code: #!perl -w use strict; use warnings; use Win32::GUI qw(CW_USEDEFAULT HWND_TOPMOST HWND_NOTOPMOST SWP_NOMOVE SWP_NOSIZE); my $appname = 'Test App'; my $mw = Win32::GUI::Window->new( -title => $appname, -left => CW_USEDEFAULT, -size => [300,200], ); $mw->AddCheckbox( -text => 'Topmost', -pos => [10,10], -onClick => \&set_topmost, ); $mw->Show(); Win32::GUI::Dialog(); $mw->Hide(); exit(0); sub set_topmost { my ($self) = @_; my $title = $appname; my $hwnd_after = HWND_NOTOPMOST; if ($self->Checked()) { $title .= ' - Topmost'; $hwnd_after = HWND_TOPMOST; } $self->GetParent()->Text($title); $self->GetParent()->SetWindowPos($hwnd_after, 0,0,0,0, SWP_NOMOVE|SWP_NOSIZE); return 0; } __END__ Regards, Rob. |