The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Neil on July 04, 2009, 01:23:09 PM

Title: SetConsoleIcon
Post by: Neil on July 04, 2009, 01:23:09 PM
Came accross this undocumented API, played around with it for a while without success.
Has any one else tried using it?
Title: Re: SetConsoleIcon
Post by: qWord on July 04, 2009, 02:47:06 PM
hi,

on my machine (under Vista32) it works:

mov hIcon,rv(LoadIcon,0,IDI_EXCLAMATION)
fn GetProcAddress,rv(GetModuleHandle,"kernel32.dll"),"SetConsoleIcon"

push hIcon
call eax


regards, qWord
Title: Re: SetConsoleIcon
Post by: Neil on July 04, 2009, 03:06:53 PM
Thanks qWord,
Your code works OK for me (Vista 32), but what I was trying to do was load an owner drawn Icon & not a system Icon, not sure if that's possible.
I'll keep trying
Title: Re: SetConsoleIcon
Post by: qWord on July 04, 2009, 03:17:52 PM
probably the icon-size/format cause your problems: Icons in Win32 (http://msdn.microsoft.com/en-us/library/ms997538.aspx) (see Table 1. "Where Windows Uses Different Sized Icons" )
Title: Re: SetConsoleIcon
Post by: Neil on July 04, 2009, 03:25:48 PM
Thanks qWord
I will give it some more thought tomorrow, the Tour De France is just about to start & I'm a bit of a cycling fan :bg
Title: Re: SetConsoleIcon
Post by: jj2007 on July 04, 2009, 03:34:34 PM
It's a two-liner :bg

push rv(LoadIcon, rv(GetModuleHandle, 0), IDI_APPLICATION)
call rv(GetProcAddress, rv(GetModuleHandle, "kernel32.dll"), "SetConsoleIcon")

Title: Re: SetConsoleIcon
Post by: Neil on July 05, 2009, 08:54:09 AM
Nice one jj :U
Title: Re: SetConsoleIcon
Post by: Vortex on July 05, 2009, 10:09:27 AM
This example tested on Windows XP SP 3 :


.386
.model flat,stdcall
option casemap:none

include    \masm32\include\windows.inc
include    \masm32\include\kernel32.inc
include    \masm32\include\user32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

.data

kernel32    db 'kernel32.dll',0
FuncName    db 'SetConsoleIcon',0
msg         db 'Click the message box to change the console icon',0
msg2        db 'Console icon changed',0
capt        db 'Test',0
func        db 0FFh,025h ; define a jump entry
            dd pFunc


.data?

hIcon       dd ?
pFunc       dd ?

SetConsoleIcon  EQU <pr1 PTR func>

.code

start:

    invoke  GetModuleHandle,0
    invoke  LoadIcon,eax,200
    mov     hIcon,eax
    invoke  GetModuleHandle,ADDR kernel32
    invoke  GetProcAddress,eax,ADDR FuncName
    mov     pFunc,eax
    invoke  MessageBox,0,ADDR msg,ADDR capt,MB_OK
    invoke  SetConsoleIcon,hIcon
    invoke  MessageBox,0,ADDR msg2,ADDR capt,MB_OK
    invoke  ExitProcess,0

END start

[attachment deleted by admin]
Title: Re: SetConsoleIcon
Post by: Neil on July 05, 2009, 12:24:44 PM
Thanks vortex,
Excellent example :U Works fine on Vista SP2
Title: Re: SetConsoleIcon
Post by: dedndave on July 05, 2009, 03:06:39 PM
Vortex - I noticed you used polink to build that - is that a habit or requirement ?

also, could i use a 16x16 icon ? - i think that is the "standard" size for the console window

btw - very cool Neil and Vortex - i want to use this one - lol
Title: Re: SetConsoleIcon
Post by: Vortex on July 05, 2009, 03:58:31 PM
Hi dedndave,

Polink is my favorite linker. It's maintained regularly and creates smaller executables compared to the version of MS link supplied with the Masm32 package.
Title: Re: SetConsoleIcon
Post by: BlackVortex on July 05, 2009, 04:19:08 PM
Yeah, polink and golink seem to be the only worthwhile linkers. I'm open to other suggestions, though  :green
Title: Re: SetConsoleIcon
Post by: dedndave on July 05, 2009, 04:29:45 PM
well, i have been using MS linkers since about 1983 - lol
old habits, i guess
but, polink is cool - and pelle's C also, if i ever have a need to compile some C code
my only concern is what is compatible with what - lol
there are so many assemblers/compilers/linkers/whatevers, nowdays
not having the experience (yet) to know all the little ins and outs makes it hard
you guys know every little quirk in these programs - lol
sometimes, it is easier to just ask someone who is experienced than to try all the combinations to see what works best

i have enough to learn as it is
if i have to cram much more into my brain, i hafta push something else out, first
oh well, i wasn't using that info, anyways - lol
Title: Re: SetConsoleIcon
Post by: jj2007 on July 05, 2009, 05:55:41 PM
This example tested on good ol' XP SP2 :bg

[attachment deleted by admin]