Hi Jeremy,
Thanks for the help. I had some trouble getting 0.558 out and installing
1.02. After that everything worked well :)
I've run into a new problem now. I want to get at the window that owns the
start button and modify certain other controls in it.
I try to get the handle of the window by $self->GetWindow(GW_OWNER); but it
returns 0 :(
sub StartClick {
#first parm in NEM is always the control
my $self=shift;
my $windowhandle = $self->GetWindow(GW_OWNER);
print "$self has been clicked!\n";
}
How do I get at the window handle?
Further is it possible to access the other controls that are part of the
window by using the window handle?
Specifically if there is a Textfield called username how do I access that
Textfield?
Its obvious that $windowhandle->{'Username'}->Change(-readonly=>1); dosent
work.
How do I access the controls in the Window using the window handle?
Or is it possible to get the window object passed to the event handler when
an event occurs?
Thanks a lot,
Emmanuel
----- Original Message -----
From: "Jeremy White" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <perl-win32-gui-users@lists.sourceforge.net>
Sent: Monday, September 12, 2005 1:21 PM
Subject: RE: [perl-win32-gui-users] Using Win32::GUI events within a class
or a package?
Is it possible to define this sub Start_Click in package Test and get it
working so that the entire GUI code is hidden from package main?
Yes, by using NEM.
I did a search of the archives and i found something called NEM at
http://sourceforge.net/mailarchive/message.php?msg_id=11271102 and at
http://sourceforge.net/mailarchive/message.php?msg_id=12559985.
Is there some documentation or a working example of using the NEM?
If you are using the latest version of Win32-GUI you should find some
examples in the samples folder (if not, you could browse the CVS samples
folder on sourceforge).
NEM (New Event Model) should really be used over the OEM (Old Event
Model). The OEM initially looks simpler, because of it's VB style
semantics, but it is slower and less flexible than NEM. Both models can be
used together.
The difference between the two event modules is quite subtle. The NEM
needs a sub reference of a function that will be run when the event is
fired, while OEM will look for the function in the main name space.
There are two main ways to associate a sub ref to an event, when
window/control is created, or dynamically as the programme is running.
When the control is created, you add an event handler prefixed with 'on':
-onClick => sub {print 'clicked';},
a complete example for a treeview control would look like:
$win->AddTreeView(
-width => 217,
-name => 'TV',
-tabstop => 1,
-left => 0,
-visible => 1,
-checkboxes => 0,
-buttons => 1,
-top => 0,
-lines => 1,
-showselalways => 1,
-height => 457,
-hottrack => 0,
-rootlines => 1,
-editlabels => 1,
-onBeginLabelEdit => \&TV_BeginLabelEdit,
-onEndLabelEdit => \&TV_EndLabelEdit,
-onExpand => \&TV_Expand,
-onCollapse => \&TV_Collapse,
-onNodeClick => \&TV_NodeClick,
-onRightClick => \&TV_RightClick,
-onKeyDown => \&TV_KeyDown,
);
To add (or change) an event handler at runtime you can use the SetEvent
method of the control:
$win->myButton->SetEvent('Click',sub {print 'Clicked';});
Back to your example:
$self->{'CNF'}->{'Window'}->AddButton( -name => "Start",
-align => "center",
-height => 30,
-width => 60,
-text => "Start",
-top => 510,
-left => 360,
-tabstop => 1,
-onClick => \&StartClick,
);
and add this sub to your Test package:
sub StartClick {
#first parm in NEM is always the control
my $self=shift;
print "$self has been clicked!\n";
}
Hope that is of some help.
Cheers,
jez.
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle
Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users