Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Can't change icon with win32 module

by Anonymous Monk
on Sep 22, 2012 at 07:11 UTC ( #995066=note: print w/ replies, xml ) Need Help??


in reply to Can't change icon with win32 module

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


Comment on Re: Can't change icon with win32 module
Download Code
Re^2: Can't change icon with win32 module
by bulk88 (Priest) on Sep 22, 2012 at 08:40 UTC
    SetConsoleIcon is implemented as an IPC message/call to CSRSS.

      SetConsoleIcon is implemented as an IPC message/call to CSRSS.

      I figured it was something like that :) but how do you know, its undocumented?

Re^2: Can't change icon with win32 module
by palkia (Scribe) on Sep 22, 2012 at 16:54 UTC
    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 ?
      Tried checking Win32::GetLastError() if creating an Win32::GUI::Icon failed?
        I used Win32::FormatMessage(Win32::GetLastError()) but it returns The operation completed successfully for both icons (those the do and doe that don't give undef).
        It even says the same thing if I use a pl file instead of ico,
        Seems to me to be pretty equivalent to the -e operator.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2014-10-24 07:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (130 votes), past polls