ExtractIconEx_ / DrawIconEx_ and a little white dot

Windows specific forum
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

ExtractIconEx_ / DrawIconEx_ and a little white dot

Post 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?
Last edited by blueznl on Thu Oct 07, 2021 7:19 pm, edited 1 time in total.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: ExtradIconEx_ / DawIconEx_ and a little white dot

Post by blueznl »

Hmmm... I think I made a mess of the code somewhere. Ignore this for now :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: ExtradIconEx_ / DawIconEx_ and a little white dot

Post by Mijikai »

Here is an example that uses PB commands to draw the icon:
viewtopic.php?p=575394#p575394
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: ExtradIconEx_ / DawIconEx_ and a little white dot

Post 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!
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
fryquez
Enthusiast
Enthusiast
Posts: 367
Joined: Mon Dec 21, 2015 8:12 pm

Re: ExtradIconEx_ / DawIconEx_ and a little white dot

Post 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

User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: ExtradIconEx_ / DawIconEx_ and a little white dot

Post 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.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: ExtractIconEx_ / DrawIconEx_ and a little white dot

Post 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.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: ExtractIconEx_ / DrawIconEx_ and a little white dot

Post 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)
Last edited by blueznl on Thu Oct 07, 2021 8:30 pm, edited 1 time in total.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
fryquez
Enthusiast
Enthusiast
Posts: 367
Joined: Mon Dec 21, 2015 8:12 pm

Re: ExtractIconEx_ / DrawIconEx_ and a little white dot

Post 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

User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: ExtractIconEx_ / DrawIconEx_ and a little white dot

Post 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).
Post Reply