Joe, The way to do this is to create the method in the Win32::GUI package. Then switch back to the main package when you've finished to write your own code. See the following example:
#!/perl -w use Win32::GUI; package Win32::GUI; # Create following methods as Win32::GUI methods sub CenterOnScreen{ my $window = shift; # gets the object which called the method?? my $desk = $window->GetDesktopWindow(); my(undef, undef, $d_width, $d_height)= Win32::GUI::GetWindowRect($desk); my ($win_width)= $window->ScaleWidth(); my ($win_height) = $window->ScaleHeight(); my $delta_w = ($d_width /2) - ($win_width/ 2); my $delta_h = ($d_height / 2) - ($win_height / 2); $window->Move($delta_w, $delta_h); } package main; # Return to the main package my $window = new Win32::GUI::Window( -style => WS_MINIMIZEBOX | WS_SYSMENU | WS_MAXIMIZEBOX, -name => "Window", -title => "EDFTree", -left => 0, -top => 0, -width => 600, -height => 504, -sizable => 1, ); $window->Show; $window->CenterOnScreen; Win32::GUI::Dialog(); ----- Original Message ----- From: "Frazier, Joe Jr" <[EMAIL PROTECTED]> To: <perl-win32-gui-users@lists.sourceforge.net> Sent: 07 August 2001 22:56 Subject: [perl-win32-gui-users] Question about adding methods to GUI objects Is there a simple way to add a method to an object? Basically, what I want to do is this: $window->CenterOnScreen(); where $window is my Win32::GUI::Window object, and CenterOnScreen() is a sub I created in another package( or in main for that matter) so that the method call above would invoke sub CenterOnScreen{ my $window = shift; # gets the object which called the method?? my $desk = $window->GetDesktopWindow(); my(undef, undef, $d_width, $d_height)= Win32::GUI::GetWindowRect($desk); my ($win_width)= $window->ScaleWidth(); my ($win_height) = $window->ScaleHeight(); my $delta_w = ($d_width /2) - ($win_width/ 2); my $delta_h = ($d_height / 2) - ($win_height / 2); $window->Move($delta_w, $delta_h); } So, how do I call this method created in my own package with an object created in another package. I know I could easily do CenterOnScreen($window); but I want to stay in OO mode as much as possible AND I will want to create several utility methods such as this for my GUI projects. Any help is appreciated in advance. Joe Frazier, Jr Technical Support Engineer PeopleClick 919-645-2916 [EMAIL PROTECTED] PS: Thanks to all for making such a great visual tool for us Win32 programmers. I use this often to create simple GUI's which our "Tools" team does seem to find time to produce. Also, when is the next version coming out? _______________________________________________ Perl-Win32-GUI-Users mailing list Perl-Win32-GUI-Users@lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users