Hi,
I've little idea of what you were trying to do :-)
Is the following anything like what you were after ? (Beware of line wrapping.)


#---------------------------------
# BOOL EnumWindows(
#  WNDENUMPROC lpEnumFunc,  // callback function
#  LPARAM lParam            // application-defined value
#  );

# BOOL CALLBACK EnumWindowsProc(
#  HWND hwnd,      // handle to parent window
#  LPARAM lParam   // application-defined value
#  );

# int GetWindowText(
#  HWND hWnd,        // handle to window or control
#  LPTSTR lpString,  // text buffer
#  int nMaxCount     // maximum number of characters to copy
#  );

use warnings;

use Inline (C => Config =>
            LIBS => '-luser32 -lkernel32',
            BUILD_NOISY => 1,
            );

use Inline C => <<'EOC';

#include <windows.h>

void Call_my_callback(int handle) {
     dSP ;

     ENTER ;
     SAVETMPS ;

     PUSHMARK(SP) ;
     XPUSHs(sv_2mortal(newSViv(handle)));
     PUTBACK ;

     call_pv("my_callback", G_DISCARD);

     FREETMPS ;
     LEAVE ;

}

BOOL CALLBACK EnumWindowsProc(HWND handle, LPARAM given) {

/*  This function is not accessible from perl.           */
/*  Have it do a callback to the perl subroutine         */
/*  my_callback(). This is just my (convoluted ?) way of */
/*  getting all of the handles stored into a perl array. */

     Call_my_callback((int) handle);
}

void enumwindows() {
     WNDENUMPROC ptr;
     LPARAM lp = 42; /* Universally meaningful number */

     ptr = EnumWindowsProc;
     EnumWindows(ptr, lp);
}

SV * getwindowtext(SV * a, SV * b) {
     char * buffer;
     int len = SvIV(b);
     SV * ret;

if(b <= 0) croak("2nd arg to getwindowtext function must be greater than zero");

     New(1, buffer, sizeof(char) * len, char);

     GetWindowText(SvUV(a), buffer, len);
     ret = newSVpv(buffer, 0);
     Safefree(buffer);
     return ret;
}

EOC

@handles = (); # global

enumwindows();

# @handles now contains handles of all open windows.

print "Looking for IE windows\n";

for(@handles) {
   if(getwindowtext($_, 100) =~ /Internet Explorer/) {
     printf "IE Window handle: %x\n", $_;
     }
   }

print "Search completed\n";

sub my_callback {
    push @handles, $_[0];
}

__END__

The usual approach to this sort of stuff is to use the rough (but brilliant and effective) hack that goes by the name of Win32::API.

Anyway ... I hope there's something there that helps. But if there isn't, then at least I had some fun writing it :-)

Hmmm .... s/writing it/plagiarising/

Cheers,
Rob



Reply via email to