Re: Can't change icon with win32 module
by bulk88 (Priest) on Sep 22, 2012 at 04:02 UTC
|
| [reply] |
|
|
Win32::GUI object around a HWND You can fake it with bless, but it isn't required, every Win32::GUI method is also a function, it will take a hwnd as first argument
| [reply] |
Re: Can't change icon with win32 module
by Anonymous Monk on Sep 22, 2012 at 07:11 UTC
|
Its me again, some code for you #!/usr/bin/perl --
#~ wget -c -O perlmonks.favicon.ico http://perlmonks.org/favicon.ico
use strict; use warnings;
use Data::Dump;
use Win32::GUI();
my $icon = 'Win32::GUI::Icon'->new(
'perlmonks.favicon.ico'
) or die $^E;
my $cmd = Win32::GUI::GetPerlWindow() or die $^E;
dd [ $cmd, $^E ];
dd [ Win32::GUI::ChangeIcon($cmd, $icon) , $^E ]; ## "Access is denied
+" as expected
BEGIN {
use Win32::API;
Win32::API::->Import("kernel32","BOOL SetConsoleIcon(HWND icon )")
+;
}
$^E=0; dd [ SetConsoleIcon( $icon->{-handle} ), $^E ]; ## UNDOCUMENTED
+ MAGIC
__END__
[46334276, ""]
[0, "Access is denied"]
[1, ""]
SetConsoleIcon() naturally works where ChangeIcon() fails | [reply] [d/l] |
|
|
Won't seem to go online for me for some reason,
but I just wanted it to use my icons anyway,
so after some tweaking it worked gr8 (thank you very very much).
In my version
use Win32::GUI();
use Win32::API;
Win32::API->Import('kernel32','BOOL SetConsoleIcon(HWND icon)');
SetConsoleIcon( Win32::GUI::Icon->new('box.ico')->{-handle} );
For some reason it only works for some icons.
It seems that Win32::GUI::Icon->new('box.ico') returns undef for some icons, or to be exact, it does the same as in the case I refer to a non-existing icon.
Some icon-format limitation ? | [reply] [d/l] [select] |
|
|
Tried checking Win32::GetLastError() if creating an Win32::GUI::Icon failed?
| [reply] |
|
|
|
|
|
|
|
|
|
|
SetConsoleIcon is implemented as an IPC message/call to CSRSS.
| [reply] |
|
|
SetConsoleIcon is implemented as an IPC message/call to CSRSS. I figured it was something like that :) but how do you know, its undocumented?
| [reply] |
|
|
|
|
| [reply] |
Re: Can't change icon with win32 module
by Anonymous Monk on Sep 21, 2012 at 22:14 UTC
|
What am I doing wrong ? Well, you seem to be assuming that what you're trying to do is allowed/possible -- I don't think it is, but I've long ago given up on win32/msdn
| [reply] |
|
|
This is very encouraging ^^.
What do you use instead of win32 ?
I tired both wx and gtk2 but I got tired of trying to figure out why both won't work.
If I remember correctly, it was some install problem or something.
So if you got alternatives to offer, please exclude these 2.
| [reply] |
|
|
This is very encouraging Well, trying to change the icon on a console is kind of a weird thing to do :)
I tired both wx and gtk2 but I got tired of trying to figure out why both won't work. If I remember correctly, it was some install problem or something. So if you got alternatives to offer, please exclude these 2. Yeah, I'd go with Wx, it comes with dwimperl/citrusperl, and is available via ppm for activeperl or any ppm capable perl
FWIW, Gtk2 is available via some PPM::Repositories, but I prefer Wx
| [reply] |