It is currently Sat Sep 26, 2020 7:51 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Extract Icon from Dll/exe at non standard size(WINDOWS ONLY)
PostPosted: Sat May 09, 2020 9:39 am 
Offline
User
User

Joined: Wed Nov 06, 2019 10:28 am
Posts: 73
Hi,

Here is a way to extract an icon from a resource file (dll/exe) at the size you desire and use it with an image gadget (the function returns an icon handle so an imageID in PB) :

Code:
; Macro LOWORD(dwValue) : dwValue & $FFFF : EndMacro
; Macro HIWORD(dwValue) : dwValue >> 16 : EndMacro

Prototype.i Proto_SHDefExtractIcon(pszIconFile.s, iIndex.i, uFlags.i, phiconLarge.i, phiconSmall.i, nIconSize.i)

Procedure ExtractArbitrarySizeIcon(pszPath.s, index, size)
   Protected hIcon
   OpenLibrary(0, "Shell32.dll")
   Protected SHDefExtractIcon_.Proto_SHDefExtractIcon = GetFunction(0, "SHDefExtractIconW")
   
   If SHDefExtractIcon_(pszPath, index, 0, @hIcon, #Null, size) = #S_OK
      ProcedureReturn hIcon
   EndIf
   
   ProcedureReturn 0
EndProcedure


If OpenWindow(0, 0, 0, 300, 50, "ImageGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   
   
   hicon1 = ExtractArbitrarySizeIcon("c:\windows\system32\shell32.dll", 22, 16)
   ImageGadget(1, 0, 0, 50, 50, hicon1)
   
   hicon2 = ExtractArbitrarySizeIcon("c:\windows\system32\shell32.dll", 22, 24)
   ImageGadget(2, 50, 0, 50, 50, hicon2)
   
   hicon3 = ExtractArbitrarySizeIcon("c:\windows\system32\shell32.dll", 22, 32)
   ImageGadget(3, 100, 0, 50, 50, hicon3)   
   
   hicon4 = ExtractArbitrarySizeIcon("c:\windows\system32\shell32.dll", 22, 40)
   ImageGadget(4, 150, 0, 50, 50, hicon4)
   
   hicon5 = ExtractArbitrarySizeIcon("c:\windows\system32\shell32.dll", 22, 48)
   ImageGadget(5, 200, 0, 50, 50, hicon5)   
   
   Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf


DestroyIcon_(hicon1)
DestroyIcon_(hicon2)
DestroyIcon_(hicon3)
DestroyIcon_(hicon4)
DestroyIcon_(hicon5)


Msdn doc : https://docs.microsoft.com/en-us/window ... tracticonw
The doc doesn't match my experience. It seems you can use only the phiconLarge pointer to get every size you want...


Top
 Profile  
Reply with quote  
 Post subject: Re: Extract Icon from Dll/exe at non standard size
PostPosted: Sat May 09, 2020 1:07 pm 
Offline
User
User
User avatar

Joined: Tue Jan 28, 2020 10:17 am
Posts: 64
Nice, thanks for sharing.

_________________
FlatEarth addresses in PB :
Engine3D --> SkyDome
Mesh --> CreatePlane


Top
 Profile  
Reply with quote  
 Post subject: Re: Extract Icon from Dll/exe at non standard size
PostPosted: Sun May 10, 2020 12:50 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 2:15 pm
Posts: 894
Location: Cuernavaca, Mexico
I've been using some older 2013 code by 'Nalor' which still works well and you might fine useful. :)

see: https://www.purebasic.fr/english/viewtopic.php?p=417143#p417143

_________________
- It was too lonely at the top.

Current Machine: Win 10 Pro 64-bit, Dual Xeon E5-2670, 64 gigs ram, Geforce GTX 1660 Ti w/6 gigs ram


Top
 Profile  
Reply with quote  
 Post subject: Re: Extract Icon from Dll/exe at non standard size(WINDOWS O
PostPosted: Sun May 10, 2020 6:22 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4705
Location: Lyon - France
Works fine here, thanks for sharing 8)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 25 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye