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...

In reply to Disable Control in Win32::GUI by ChrisR

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.