Here is mine
#!/usr/bin/perl --
use strict; use warnings;
use Win32::GUI();
use Win32::API;
Win32::API->Import('kernel32','BOOL SetConsoleIcon(HWND icon)');
@ARGV or @ARGV = map { glob $_ }
"C:/Progra~1/*.ico",
"C:/Progra~1/*/*.ico",
"C:/Progra~1/*/*/*.ico",
"C:/Progra~1/*/*/*/*.ico",
#~ "C:/Progra~1/*/*/*/*/*.ico",
"C:/WINDOWS/*/*.ico",
"C:/WINDOWS/*/*/*.ico",
"C:/WINDOWS/*/*/*/*.ico",
#~ "C:/WINDOWS/*/*/*/*/*.ico",
#~ "C:/WINDOWS/*/*/*/*/*/*.ico",
#~ "C:/WINDOWS/*/*/*/*/*/*/*.ico",
;;;;
for my $file ( @ARGV ){
print "$file\n";
eval {
my $icon = Win32::GUI::Icon->new( $file )
or die sprintf qq/ErrIcon \$!(%d)(%s)\n\$^E(%d)(%s)\nGLS(%
+d)(%s)/,
$!,$!,$^E,$^E,
Win32::GetLastError(),
Win32::FormatMessage(Win32::GetLastError())
;;;;;
SetConsoleIcon( $icon->{-handle} )
or die sprintf qq/ErrSet \$!(%d)(%s)\n\$^E(%d)(%s)\nGLS(%d
+)(%s)/,
$!,$!,$^E,$^E,
Win32::GetLastError(),
Win32::FormatMessage(Win32::GetLastError())
;;;;;
1;
} or warn "$@\n\n";
sleep 1;
}
SetConsoleIcon( undef );## restore
__END__
$ perl sicon.pl sicon.pl perlmonks.favicon.ico sicon.pl
sicon.pl
ErrIcon $!(2)(No such file or directory)
$^E(0)()
GLS(0)(The operation completed successfully.
) at sicon.pl line 25.
perlmonks.favicon.ico
sicon.pl
ErrIcon $!(2)(No such file or directory)
$^E(0)()
GLS(0)(The operation completed successfully.
) at sicon.pl line 25.
Obviously sicon.pl isn't an .ico file
Looking at these results and Win32::GUI::Icon docs, it is now obvious that it doesn't preserve $^E from the 2-3 ways it tries to load the file, so $^E ends up being uninformative
FormatMessage() OTOH assumes 0 means success where as $^E doesn't
Since this program works for me for about a dozen icon files I find in program files
I must assume there is something wrong with your box2.ico
good luck figuring it out :) You might hack on some GUI.xs to insert informative diagnostics, or hit up MSDN for specs regarding icon files so you can compare them to box2.ico ...
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.