Thanks for the reply, but I'm still getting the usage
errors with this script, no matter how I call Hook.
With the attached file, I tried these 3 ways of
calling it:
#$win->Hook($win, WM_ENTERIDLE, \&Idle($win));
#$win->Hook(WM_ENTERIDLE, \&Idle($win));
Win32::GUI::Hook($win,WM_ENTERIDLE, \&Idle($win));
The strange thing is that the hook works in the
example that Rob sent out (last week, I think). Am I
missing something here?
thanks,
-ariel
--- Jeremy White <[EMAIL PROTECTED]> wrote:
>
> >command that passes the $win object. when i run
> that
> >line, then i get a usage error that says only to
> pass
> >the msg and the coderef. does anyone have any idea
> >what's going on here?
>
> > #$win->Hook($win, WM_ENTERIDLE, \&Idle($win));
>
> Try:
>
> $win->Hook(WM_ENTERIDLE, \&Idle($win));
>
> When called as a method the first paramater is the
> window, ie:
>
> Win32::GUI::Hook($win,WM_ENTERIDLE, \&Idle($win));
>
> As you are passing a win32::GUI object, Hook will
> get the handle from the
> object.
>
> Cheers,
>
> jez.
>
>
>
use Win32::GUI;
use Win32::API;
use Win32::GUI::Loft::Design;
sub WM_WINDOWPOSCHANGING() {70}
sub WM_ENTERIDLE() {289}
sub SWP_NOACTIVATE() {16}
sub MSGF_DIALOGBOX() {0}
my $win = Win32::GUI::Window->new(
-name => 'win',
-text => 'test',
-left => 10,
-top => 10,
-width => 250,
-height => 250,
);
$win->AddButton(
-name => 'button',
-text => 'button',
-left => 10,
-top => 10,
-onClick => \&open_thumbnails,
);
$win->Center;
$win->Show;
Win32::GUI::Dialog();
sub open_thumbnails
{
#$win->Hook($win, WM_ENTERIDLE, \&Idle($win));
#$win->Hook(WM_ENTERIDLE, \&Idle($win));
Win32::GUI::Hook($win,WM_ENTERIDLE, \&Idle($win));
my $files = Win32::GUI::GetOpenFileName(
-owner => $win,
);
return $files;
}
sub Idle
{
$win->UnHook(WM_ENTERIDLE); # ensure this hook doesn't get called again
my ($object, $wParam, $lParam, $type, $msgcode) = @_;
return unless $type == 0;
return unless $msgcode == WM_ENTERIDLE;
# check the message came from a dialog box
return unless $wParam == MSGF_DIALOGBOX;
# check that the dialog window handle in $lParam is for the Open File
dialog:
# here I test the window caption, but you might needsomething more
robust:
return unless Win32::GUI::Text($lParam) eq "Open";
# modify the Dialog (center it on the main window):
my $sx = $win->Left() + ($win->Width() - Win32::GUI::Width($lParam))/2;
my $sy = $win->Top() + ($win->Height() - Win32::GUI::Height($lParam))/2;
Win32::GUI::Move($lParam, $sx, $sy);
# Walk the child windows of the open dialog to find the
SHELLDLL_DefView window:
my $phwnd = $lParam;
my $mode = GW_CHILD; # Initially find the first child of the dialog
window
while(my $chwnd = Win32::GUI::GetWindow($phwnd, $mode)) {
if (Win32::GUI::GetClassName($chwnd) eq "SHELLDLL_DefView") {
# set the view:
# from
http://msdn.microsoft.com/msdnmag/issues/04/03/CQA/
# 0x7029 Icons
# 0x702B List
# 0x702C Details
# 0x702D Thumbnails
# 0x702E Tiles
Win32::GUI::SendMessage($chwnd, WM_COMMAND, 0x702D, 0);
last; # we found it
}
$mode = GW_HWNDNEXT; # and walk the rest of the dialog's
children
$phwnd = $chwnd;
}
return;
}
1;