Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Disable Control in Win32::GUI

by ChrisR (Hermit)
on Dec 19, 2005 at 21:19 UTC ( [id://517900]=perlquestion: print w/replies, xml ) Need Help??

ChrisR has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: Disable Control in Win32::GUI
by BrowserUk (Patriarch) on Dec 19, 2005 at 21:41 UTC
    I also tried to set the onClick event to an empty sub which didn't work either

    Define "didn't work"? What did you expect that to do that didn't happen?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I guess this may be a little confusing but by "didn't work", I meant that the control was still "working." I am trying to disable the control without it turning gray so that it looks normal but does not respond to events.

        The confusing thing is your terminology. Your control is an textfield, and textfields don't do anything in response to single clicks, so setting an empty onClick handler isn't going to change it's behaviour.

        If you said "I want to stop the user from being able to edit the text displayed in the Textfield", then it would be fairly obvious that you don't want to 'disable the control', you want to 'set the TextField readonly', which is a fairly common thing to want to do to edit fields and there is therefore an option for doing exactly that (called -readonly :). Try this

        use strict; use Win32::GUI; use Win32::API; our $mainform = Win32::GUI::Window->new( -name=>'main', -text=>'main', ) or die "window creation failed: $!\n"; our $test = $mainform->AddTextfield( -name=>'test', -text=>'test', -left=>200,-top=>200, -width=>100,-height=>20, -readonly => 1, ) or die "control creation failed: $!\n"; $mainform->Show(); Win32::GUI::Dialog;

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://517900]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-26 07:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found