Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^10: Can't change icon with win32 module

by Anonymous Monk
on Sep 24, 2012 at 04:48 UTC ( #995292=note: print w/ replies, xml ) Need Help??


in reply to Re^9: Can't change icon with win32 module
in thread Can't change icon with win32 module

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 ...


Comment on Re^10: Can't change icon with win32 module
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995292]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2015-07-08 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls