News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

SetConsoleIcon

Started by Neil, July 04, 2009, 01:23:09 PM

Previous topic - Next topic

Neil

Came accross this undocumented API, played around with it for a while without success.
Has any one else tried using it?

qWord

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
FPU in a trice: SmplMath
It's that simple!

Neil

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

qWord

probably the icon-size/format cause your problems: Icons in Win32 (see Table 1. "Where Windows Uses Different Sized Icons" )
FPU in a trice: SmplMath
It's that simple!

Neil

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

jj2007

It's a two-liner :bg

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


Neil


Vortex

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]

Neil

Thanks vortex,
Excellent example :U Works fine on Vista SP2

dedndave

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

Vortex

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.

BlackVortex

Yeah, polink and golink seem to be the only worthwhile linkers. I'm open to other suggestions, though  :green

dedndave

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

jj2007

This example tested on good ol' XP SP2 :bg

[attachment deleted by admin]