GUI users, i'd appreciate it if someone more knowlegable could please have a look at the following code. i adapted it from the example that rob sent, but i keep getting a usage error on the hook line (in open_thumbnails), which says that it needs to be passed (handle, msg, codref). you'll see that i have a commented hook 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?
thanks, -ariel. 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)); 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 need something 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;