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
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
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
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
;...
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.
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 (https://docs.microsoft.com/en-us/windows/win32/controls/image-list-reference).
Does anyone know what the includes are for GetIconInfoEx? Thanks
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
deleted
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
I still don't know which linrary to Load. ty
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
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.
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
deleted
Quote from: Vortex on February 16, 2022, 04:50:18 AM
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
It's also in my User32.dll; GetProcAddress returned error proc_not_found, but then I had the bright idea to ask for GetIconInfoExA :biggrin: