I'm looking for a way to disable a control (widget) without changing it's appearance. I would like to be able to do this for any type of control. I'm using Activestate perl 5.8.7 and Win32::GUI 1.03 on win xp.
I tried $control->Enable(0) but the control still gets greyed out. I'm using activestate perl 5.8.7 and Win32::GUI 1.03 on win xp. Here's a brief example:
#!c:\perl58\bin\wperl.exe -W
use strict;
use Win32::GUI;
use Win32::API;
our $mainform = Win32::GUI::Window->new(
-name=>'main',
-text=>'main',
-width=>800,-height=>600,
) or die "window creation failed: $!\n";
our $test = $mainform->AddTextfield(
-name=>'test',
-text=>'test',
-left=>200,-top=>200,
-width=>100,-height=>20,
) or die "control creation failed: $!\n";
$test->Enable(0);
$mainform->Show();
Win32::GUI::Dialog;
I also tried to set the
onClick event to an empty sub which didn't work either
our $test = $mainform->AddTextfield(
-name=>'test',
-text=>'test',
-left=>200,-top=>200,
-width=>100,-height=>20,
-onClick=>sub{},
) or die "control creation failed: $!\n";
I'd really like to find a way to disable the functional aspects of the control without changing the way it looks.
Thanks,
Chris
Update
I found at least one fairly easy way that works:
#!c:\perl58\bin\wperl.exe -w
use strict;
use warnings;
use Win32::GUI();
# Constants
use constant WM_NCHITTEST => 0x0084;
use constant HTCAPTION => 2;
our $mainform = Win32::GUI::Window->new(
-name=>'main',
-text=>'main',
-width=>800,-height=>600,
) or die "window creation failed: $!\n";
our $test = $mainform->AddTextfield(
-name=>'test',
-text=>'test',
-left=>200,-top=>200,
-width=>100,-height=>20,
) or die "control creation failed: $!\n";
$test->Hook(WM_NCHITTEST,sub { $_[0]->Result(HTCAPTION); 0;});
$mainform->Show();
Win32::GUI::Dialog();
exit(0);
Now if I can only figure out how to have multiple
Hook()s per control to handle different messages...