Page 1 of 1
ExtractIconEx_ / DrawIconEx_ and a little white dot
Posted: Thu Oct 07, 2021 5:58 pm
by blueznl
Code: Select all
StartDrawing(IExtractIconEx_(file,0,large(),small(),1)
DrawIconEx_(image_h,x,y,large(0),w,w,0,0,#DI_NORMAL)
DestroyIcon_(small(0))
DestroyIcon_(large(0))
The above works, but it leaves a small white dot on the top right corner of my generated image, very weird. I'll have to build a little snippet to show it. Any idea what causes this?
Re: ExtradIconEx_ / DawIconEx_ and a little white dot
Posted: Thu Oct 07, 2021 6:05 pm
by blueznl
Hmmm... I think I made a mess of the code somewhere. Ignore this for now

Re: ExtradIconEx_ / DawIconEx_ and a little white dot
Posted: Thu Oct 07, 2021 6:08 pm
by Mijikai
Here is an example that uses PB commands to draw the icon:
viewtopic.php?p=575394#p575394
Re: ExtradIconEx_ / DawIconEx_ and a little white dot
Posted: Thu Oct 07, 2021 6:16 pm
by blueznl
Okay, the dot is caused by a certain amount of .ICO files, very weird, but it isn't the code
However, it triggered another question... how do improve the quality?
Code: Select all
OpenWindow(1,100,100,200,200,"Test",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ImageGadget(2,10,10,180,180,0)
CreateImage(3,180,180)
;
Dim large(10)
Dim small(10)
file.s = "notepad.exe"
file.s = "C:\googledrive\icons\flat\command_prompt_1.ico"
file.s = "%USERPROFILE%\AppData\Local\Google\Chrome\User Data\Default\Google Profile.ico"
;
h=StartDrawing(ImageOutput(3))
Box(0,0,180,180,$00FFFF)
n = ExtractIconEx_(file,-1,0,0,0)
Debug n
ExtractIconEx_(file,0,large(),small(),1)
DrawIconEx_(h,x,y,large(0),180,180,0,0,#DI_NORMAL)
DestroyIcon_(small(0))
DestroyIcon_(large(0))
StopDrawing()
SetGadgetState(2,ImageID(3))
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Replace 'file' with something you like, now what I noticed is that it doesn't draw in the best resolution. Is there a trick to that? Or is this some deprecated function and should I look for something different?
Thanks in advance!
Re: ExtradIconEx_ / DawIconEx_ and a little white dot
Posted: Thu Oct 07, 2021 6:30 pm
by fryquez
Code: Select all
OpenWindow(1,100,100,200,200,"Test",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ImageGadget(2,10,10,180,180,0)
CreateImage(3,180,180)
;
Dim large(10)
Dim small(10)
file.s = "notepad.exe"
;file.s = "C:\googledrive\icons\flat\command_prompt_1.ico"
;file.s = "%USERPROFILE%\AppData\Local\Google\Chrome\User Data\Default\Google Profile.ico"
;
h=StartDrawing(ImageOutput(3))
Box(0,0,180,180,$00FFFF)
Define hicon
SHExtractIcons_(file, 0, 128, 128, @hicon, 0, 1, 0)
DrawIconEx_(h,x,y, hicon,180,180,0,0,#DI_NORMAL)
DestroyIcon_(small(0))
DestroyIcon_(large(0))
StopDrawing()
SetGadgetState(2,ImageID(3))
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: ExtradIconEx_ / DawIconEx_ and a little white dot
Posted: Thu Oct 07, 2021 7:23 pm
by blueznl
fryquez wrote: Thu Oct 07, 2021 6:30 pm
SHExtractIcons_(file, 0, 128, 128, @hicon, 0, 1, 0)
Which version of PureBasic are you running? 5.73LTS nor Alpha4 seem to recognize that Windows API function.
Re: ExtractIconEx_ / DrawIconEx_ and a little white dot
Posted: Thu Oct 07, 2021 7:55 pm
by Mijikai
SHExtractIconsW is not exported by name or declared in a public header file.
To use it, you must declare a matching prototype and use GetProcAddress to request
a function pointer from Shell32.dll that can be used to call this function.
Re: ExtractIconEx_ / DrawIconEx_ and a little white dot
Posted: Thu Oct 07, 2021 8:21 pm
by blueznl
Ah, I thought for a moment it was a WinApi_ call already defined.
Thx, code below works.
Code: Select all
OpenWindow(1,100,100,200,200,"Test",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ImageGadget(2,10,10,180,180,0)
CreateImage(3,180,180)
;
OpenLibrary(4,"shell32.dll")
p_shextracticonsw = GetFunction(4,"SHExtractIconsW")
;
hicon.i = 0
;
file.s = "notepad.exe"
;file.s = "C:\googledrive\icons\flat\command_prompt_1.ico"
;file.s = "%USERPROFILE%\AppData\Local\Google\Chrome\User Data\Default\Google Profile.ico"
;
h=StartDrawing(ImageOutput(3))
Box(0,0,180,180,$00FFFF)
CallFunctionFast(p_shextracticonsw,@file,0,128,128,@hicon,0,1,0)
DrawIconEx_(h,x,y,hicon,180,180,0,0,#DI_NORMAL)
DestroyIcon_(hicon)
StopDrawing()
SetGadgetState(2,ImageID(3))
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
;
CloseLibrary(4)
Re: ExtractIconEx_ / DrawIconEx_ and a little white dot
Posted: Thu Oct 07, 2021 8:23 pm
by fryquez
PB's libs and import are utterly outdated, try this:
Code: Select all
Prototype pPrivateExtractIcons(szFileName, nIconIndex, cxIcon, cyIcon, phicon, piconid, nIcons, flags)
OpenLibrary(0, "user32.dll")
PrivateExtractIcons.pPrivateExtractIcons = GetFunction(0, "PrivateExtractIconsW")
CloseLibrary(0)
OpenWindow(1,100,100,200,200,"Test",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ImageGadget(2,10,10,180,180,0)
CreateImage(3,180,180)
;
Dim large(10)
Dim small(10)
file.s = "notepad.exe"
;file.s = "C:\googledrive\icons\flat\command_prompt_1.ico"
;file.s = "%USERPROFILE%\AppData\Local\Google\Chrome\User Data\Default\Google Profile.ico"
;
h=StartDrawing(ImageOutput(3))
Box(0,0,180,180,$00FFFF)
Define hicon
;SHExtractIcons_(file, 0, 128, 128, @hicon, 0, 1, 0)
PrivateExtractIcons(@file, 0, 128, 128, @hicon, 0, 1, 0)
DrawIconEx_(h,x,y, hicon,180,180,0,0,#DI_NORMAL)
DestroyIcon_(small(0))
DestroyIcon_(large(0))
StopDrawing()
SetGadgetState(2,ImageID(3))
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: ExtractIconEx_ / DrawIconEx_ and a little white dot
Posted: Thu Oct 07, 2021 8:54 pm
by Mijikai
fryquez wrote: Thu Oct 07, 2021 8:23 pm
PB's libs and import are utterly outdated, try this:
...
Its because of PBs support for older systems (which doesnt make a difference here).