News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

how to transform an Icon into a Bitmap?

Started by xandaz, February 14, 2022, 06:30:27 AM

Previous topic - Next topic

xandaz

  Hi guys. I'm using the following code but doesn't work. Help is appreciated invoke SHGetFileInfo,edi,0,addr shfi,sizeof shfi,SHGFI_SMALLICON or SHGFI_SHELLICONSIZE
invoke GetIconInfo,shfi.hIcon,addr iinfo
invoke CreateBitmap,20,20,1,16,addr iinfo.hbmColor

Vortex

Hi xandaz,

Here is an example based on OleCreatePictureIndirect :

    mov         hLib,eax
    invoke      LoadIcon,eax,100
    mov         hIcon,eax

    mov         pd.cbSizeofstruct,SIZEOF PICTDESC   ; initialize the PICTDESC structure
    mov         pd.picType,PICTYPE_ICON
    push        hIcon
    pop         pd.icon.hicon
    invoke      OleCreatePictureIndirect,ADDR pd,ADDR IID_IPicture,TRUE,ADDR pBitmap
                                                    ; create the OLE image
    invoke      CreateStreamOnHGlobal,NULL,TRUE,ADDR pStream
                                                    ; create the destination stream to save the icon

    coinvoke    pBitmap,IPicture,SaveAsFile,pStream,TRUE,OFFSET pcbSize
    invoke      GetHGlobalFromStream,pStream,ADDR hGlobal
    invoke      GlobalLock,hGlobal                  ; get the address pointing the icon in memory
    invoke      WriteFileToDisc,ADDR IconName,eax,pcbSize
                                                    ; write the icon to disc
    coinvoke    pBitmap,IPicture,Release
    coinvoke    pStream,IStream,Release
    invoke      FreeLibrary,hLib

xandaz

   Thanks Vortex. That's kinda complicated code. I was wondering if the code i wrote could be tweaked around a little bit to perform the same action. Can't it? ty

Greenhorn

Doin' it the GDI way ...


hbm      HBITMAP   NULL
hIcon   HICON   NULL
hdcMem   HDC      NULL
hObjOld   HGDIOBJ   NULL

;...

invoke CreateCompatibleDC, 0
mov  hdcMem, rax
invoke CreateCompatibleBitmap, rax, nWidth, nHeight
mov  hbm, rax
invoke SelectObject, hdcMem, hbm
mov  hObjOld, rax
invoke DrawIcon, hdcMem, 0, 0, hIcon
invoke SelectObject, hdcMem, hObjOld
invoke DeleteDC, hdcMem
invoke DeleteObject, hIcon   ; Delete icon if no longer needed

;...
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

xandaz

   That's a lot simpler Greenhorn. The problem i have is that it's for a menu. I'm not just drawing on a Device Context. So the problem is this.

Greenhorn

Quote from: xandaz on February 14, 2022, 08:06:45 AM
The problem i have is that it's for a menu. I'm not just drawing on a Device Context. So the problem is this.
:biggrin:
You always draw into a Device Context.

However, if you want to display icons in your (ownerdrawn) menus, use image lists.
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

xandaz

   Does anyone know what the includes are for GetIconInfoEx? Thanks

jj2007

Quote from: xandaz on February 15, 2022, 06:51:14 AM
   Does anyone know what the includes are for GetIconInfoEx? Thanks

Not included in user32.inc, so you need LoadLibrary plus GetProcAddress

nidud

#8
deleted

jj2007

Quote from: nidud on February 15, 2022, 09:04:51 AMadding the proto type as well would be simpler.

Nonsense, the PROTO is a simple :DWORD, :DWORD but that won't be helpful if you don't have the static lib.

ICONINFOEXA STRUCT
cbSize    DWORD ?
fIcon      BOOL ?
xHotspot  DWORD ?
yHotspot  DWORD ?
hbmMask    HBITMAP ?
hbmColor  HBITMAP ?
wResID    WORD ?
szModName CHAR MAX_PATH dup(?
szResName CHAR MAX_PATH dup(?
ICONINFOEXA ENDS

xandaz

    I still don't know which linrary to Load. ty

jj2007

Quote from: xandaz on February 16, 2022, 04:16:12 AM
    I still don't know which linrary to Load. ty

Quote from: jj2007 on February 15, 2022, 08:34:52 AMNot included in user32.inc, so you need LoadLibrary plus GetProcAddress

Quoteif you don't have the static lib

No library. Read my posts: you need a DLL. Which one, I don't know. User32.dll on my Windows 7-64 does not have GetIconInfoEx

Vortex

Hi xandaz,

The function GetIconInfoEx is exported by user32.dll :

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-geticoninfoexa

You need to update \masm32\include\user32.inc to add the prototype of the function GetIconInfoEx :

GetIconInfoExA PROTO STDCALL :DWORD,:DWORD

IFNDEF __UNICODE__
  GetIconInfoEx equ <GetIconInfoExA>
ENDIF

GetIconInfoExW PROTO STDCALL :DWORD,:DWORD

IFDEF __UNICODE__
  GetIconInfoEx equ <GetIconInfoExW>
ENDIF


You can install the latest version of PellesC to get the latest versions of the command-line tools. You can copy this import library from the PellesC installation :

copy D:\PellesC\lib\Win\user32.lib G:\masm32\lib

A quick verification :

D:\PellesC\Bin>podump /EXPORTS ..\lib\Win\user32.lib | findstr "GetIconInfoEx"
User32.dll: GetIconInfoExA (_GetIconInfoExA@8)
User32.dll: GetIconInfoExW (_GetIconInfoExW@8)


Don't forget to backup the original user32.def and user32.lib supplied with the Masm32 package.

Vortex

Hi Jochen,

My Windows 7 64-bit installation is providing the function GetIconInfoEx :

D:\PellesC\Bin>podump /EXPORTS C:\Windows\System32\user32.dll | findstr "GetIconInfoEx"
            719   134  7DCACFF8  GetIconInfoExA
            71A   135  7DCACF3F  GetIconInfoExW

nidud

#14
deleted