Page 2 of 2

Re: how to show several sizes of the icons help

Posted: Tue Jan 12, 2010 8:06 pm
by Shardik
Denis,

thank you very much for pinpointing the error in my code that does
not take into account alphanumeric identifiers. And thanks for even
providing two files as examples and for your in depth explanation. I
have to appologize for my sloppiness because I didn't go into depth
and only modified an example from Mistrel for reading an icon from
an IconGroup:
http://www.purebasic.fr/english/viewtopic.php?t=35534

My own work with resources is already several years ago. Examining
my own old routines I discovered that I also took care of possible
alphanumeric identifiers... :wink:

In my previous example I only had to declare the linked list IconGroupID()
as String instead of Integer and change the EnumResNameProc() from

Code: Select all

Procedure.I EnumResNameProc(ResHandle.I, ResType.I, ResName.I, AppParam.I)
  Shared IconGroupID()

  AddElement(IconGroupID())
  IconGroupID() = ResName

  ProcedureReturn #True
EndProcedure 
into

Code: Select all

Procedure.I EnumResNameProc(ResHandle.I, ResType.I, ResName.I, AppParam.I)
  Shared IconGroupID()

  AddElement(IconGroupID())

  If ResName & $FFFF0000
    IconGroupID() = PeekS(ResName)
  Else
    IconGroupID() = "#" + Str(ResName)
  EndIf

  ProcedureReturn #True
EndProcedure
This is the complete corrected code that runs with numeric
IconGroup names and with the alphanumeric IconGroup names
of your two example files (again tested with PB 4.40 running on
Windows XP Prof SP2 and Windows 7 RC1):

Code: Select all

EnableExplicit

#WindowHeight = 180
#WindowWidth = 240

Define *GrpIconDir.GRPICONDIR
Define i.I
Define IconHandle.I
Define *IconImage.ICONIMAGE
Define LibHandle.I
Define LibName.S = #PB_Compiler_Home + "PureBASIC.Exe"
; Define LibName.S = "CPViewer.Exe"
; Define LibName.S = "ISignup.Exe"
Define MaxHeight.I
Define WindowDC.I
Define xLeft.I
Define yTop.I

NewList IconGroupID.S()

Procedure.I EnumResNameProc(ResHandle.I, ResType.I, ResName.I, AppParam.I)
  Shared IconGroupID()

  AddElement(IconGroupID())

  If ResName & $FFFF0000
    IconGroupID() = PeekS(ResName)
  Else
    IconGroupID() = "#" + Str(ResName)
  EndIf

  ProcedureReturn #True
EndProcedure

Procedure.I EnumResTypeProc(ResHandle.I, ResType.I, AppParam.I)
  If ResType = #RT_GROUP_ICON
    EnumResourceNames_(ResHandle, ResType, @EnumResNameProc(), 0)
  EndIf

  ProcedureReturn #True
EndProcedure

LibHandle = LoadLibraryEx_(@LibName, 0, #LOAD_LIBRARY_AS_DATAFILE)

If LibHandle = 0
  MessageRequester("Error", "Unable to load library " + LibName, #MB_ICONERROR)
  End
EndIf

EnumResourceTypes_(LibHandle, @EnumResTypeProc(), 0)

OpenWindow(0, 0, 0, #WindowWidth, #WindowHeight, "Icon-Library: " + GetFilePart(LibName), #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
yTop = 5
WindowDC = StartDrawing(WindowOutput(0))

ForEach IconGroupID()
  *GrpIconDir = LoadResource_(LibHandle, FindResource_(LibHandle, IconGroupID(), #RT_GROUP_ICON))

  If *GrpIconDir
    xLeft = 5

    DrawText(xLeft, yTop, "IconGroup " + IconGroupID() + ":", #Black, #White)
    yTop + 25

    For i = 0 To *GrpIconDir\idCount - 1
      *IconImage = LoadResource_(LibHandle, FindResource_(LibHandle, *GrpIconDir\idEntries[i]\nID, #RT_ICON))
      IconHandle = CreateIconFromResourceEx_(*IconImage, *IconImage\icHeader\biBitCount, #True, $00030000, *GrpIconDir\idEntries[i]\bWidth, *GrpIconDir\idEntries[i]\bHeight, 0)

      DrawIconEx_(WindowDC, xLeft + 15, yTop, IconHandle, *GrpIconDir\idEntries[i]\bWidth, *GrpIconDir\idEntries[i]\bHeight, 0, 0, #DI_NORMAL)
      DestroyIcon_(IconHandle)
      DrawText(xLeft, yTop, "#" + Str(*GrpIconDir\idEntries[i]\nID), #Black, #White)

      xLeft + *GrpIconDir\idEntries[i]\bWidth + 30

      If MaxHeight < *GrpIconDir\idEntries[i]\bHeight
        MaxHeight = *GrpIconDir\idEntries[i]\bHeight
      EndIf
    Next i
  EndIf

  yTop + MaxHeight + 10
Next

StopDrawing()

FreeLibrary_(LibHandle)

While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend

Re: how to show several sizes of the icons help

Posted: Tue Jan 12, 2010 9:06 pm
by Shardik
mx101 wrote:if i want show only one size of group ex: 64x64 how do this?
In principal you only have to check the width or height of each
icon in all icon groups and display only those icons with a width
of 64 pixels:

Code: Select all

If *GrpIconDir\idEntries[i]\bWidth = 64
  ; Display icon
endif
This code example displays all icons with a width of 64 pixels from
Shell32.DLL (tested with PB 4.40 in Windows 7 RC1; the Shell32.DLL
of Windows XP Prof SP2 doesn't contain icons with a width of 64
pixels, so the window remains empty... :wink:)

Code: Select all

EnableExplicit

#WindowHeight = 600
#WindowWidth = 320 

Define *GrpIconDir.GRPICONDIR
Define i.I
Define IconGroupHeaderDisplayed.I
Define IconHandle.I
Define *IconImage.ICONIMAGE
Define LibHandle.I
Define LibName.S = "Shell32.DLL"
Define WindowDC.I
Define xLeft.I
Define yTop.I

NewList IconGroupID.S()

Procedure.I EnumResNameProc(ResHandle.I, ResType.I, ResName.I, AppParam.I)
  Shared IconGroupID()

  AddElement(IconGroupID())

  If ResName & $FFFF0000
    IconGroupID() = PeekS(ResName)
  Else
    IconGroupID() = "#" + Str(ResName)
  EndIf

  ProcedureReturn #True
EndProcedure

Procedure.L EnumResTypeProc(ResHandle.I, ResType.I, AppParam.I)
  If ResType = #RT_GROUP_ICON 
    EnumResourceNames_(ResHandle, ResType, @EnumResNameProc(), 0) 
  EndIf 

  ProcedureReturn #True 
EndProcedure 

LibHandle = LoadLibraryEx_(@LibName, 0, #LOAD_LIBRARY_AS_DATAFILE) 

If LibHandle = 0 
  MessageRequester("Error", "Unable to load library " + LibName, #MB_ICONERROR) 
  End 
EndIf 

EnumResourceTypes_(LibHandle, @EnumResTypeProc(), 0) 

OpenWindow(0, 0, 0, #WindowWidth, #WindowHeight, "64x64 Icons in " + GetFilePart(LibName), #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 

yTop = 5

WindowDC = StartDrawing(WindowOutput(0))

ForEach IconGroupID()
  *GrpIconDir = LoadResource_(LibHandle, FindResource_(LibHandle, IconGroupID(), #RT_GROUP_ICON))
  IconGroupHeaderDisplayed = #False

  If *GrpIconDir
    xLeft = 5

    For i = 0 To *GrpIconDir\idCount - 1
      If *GrpIconDir\idEntries[i]\bWidth = 64
        If IconGroupHeaderDisplayed = #False
          DrawText(xLeft, yTop, "IconGroup " + IconGroupID() + ":", #Black, #White)
          yTop + 25
          IconGroupHeaderDisplayed = #True
        EndIf

        *IconImage = LoadResource_(LibHandle, FindResource_(LibHandle, *GrpIconDir\idEntries[i]\nID, #RT_ICON))
        IconHandle = CreateIconFromResourceEx_(*IconImage, *IconImage\icHeader\biBitCount, #True, $00030000, *GrpIconDir\idEntries[i]\bWidth, *GrpIconDir\idEntries[i]\bHeight, 0)

        DrawIconEx_(WindowDC, xLeft + 27, yTop, IconHandle, *GrpIconDir\idEntries[i]\bWidth, *GrpIconDir\idEntries[i]\bHeight, 0, 0, #DI_NORMAL)
        DestroyIcon_(IconHandle)
        DrawText(xLeft, yTop, "#" + Str(*GrpIconDir\idEntries[i]\nID), #Black, #White)

        xLeft + *GrpIconDir\idEntries[i]\bWidth + 45
      EndIf
    Next i

    If IconGroupHeaderDisplayed
      yTop + 74
    EndIf
  EndIf
Next 

StopDrawing()

FreeLibrary_(LibHandle)

While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend

Re: how to show several sizes of the icons help

Posted: Tue Jan 12, 2010 10:44 pm
by mx101
Shardik wrote:
mx101 wrote:if i want show only one size of group ex: 64x64 how do this?
In principal you only have to check the width or height of each
icon in all icon groups and display only those icons with a width
of 64 pixels:

Code: Select all

If *GrpIconDir\idEntries[i]\bWidth = 64
  ; Display icon
endif
This code example displays all icons with a width of 64 pixels from
Shell32.DLL (tested with PB 4.40 in Windows 7 RC1; the Shell32.DLL
of Windows XP Prof SP2 doesn't contain icons with a width of 64
pixels, so the window remains empty... :wink:)

Code: Select all

EnableExplicit

#WindowHeight = 600
#WindowWidth = 320 

Define *GrpIconDir.GRPICONDIR
Define i.I
Define IconGroupHeaderDisplayed.I
Define IconHandle.I
Define *IconImage.ICONIMAGE
Define LibHandle.I
Define LibName.S = "Shell32.DLL"
Define WindowDC.I
Define xLeft.I
Define yTop.I

NewList IconGroupID.S()

Procedure.I EnumResNameProc(ResHandle.I, ResType.I, ResName.I, AppParam.I)
  Shared IconGroupID()

  AddElement(IconGroupID())

  If ResName & $FFFF0000
    IconGroupID() = PeekS(ResName)
  Else
    IconGroupID() = "#" + Str(ResName)
  EndIf

  ProcedureReturn #True
EndProcedure

Procedure.L EnumResTypeProc(ResHandle.I, ResType.I, AppParam.I)
  If ResType = #RT_GROUP_ICON 
    EnumResourceNames_(ResHandle, ResType, @EnumResNameProc(), 0) 
  EndIf 

  ProcedureReturn #True 
EndProcedure 

LibHandle = LoadLibraryEx_(@LibName, 0, #LOAD_LIBRARY_AS_DATAFILE) 

If LibHandle = 0 
  MessageRequester("Error", "Unable to load library " + LibName, #MB_ICONERROR) 
  End 
EndIf 

EnumResourceTypes_(LibHandle, @EnumResTypeProc(), 0) 

OpenWindow(0, 0, 0, #WindowWidth, #WindowHeight, "64x64 Icons in " + GetFilePart(LibName), #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 

yTop = 5

WindowDC = StartDrawing(WindowOutput(0))

ForEach IconGroupID()
  *GrpIconDir = LoadResource_(LibHandle, FindResource_(LibHandle, IconGroupID(), #RT_GROUP_ICON))
  IconGroupHeaderDisplayed = #False

  If *GrpIconDir
    xLeft = 5

    For i = 0 To *GrpIconDir\idCount - 1
      If *GrpIconDir\idEntries[i]\bWidth = 64
        If IconGroupHeaderDisplayed = #False
          DrawText(xLeft, yTop, "IconGroup " + IconGroupID() + ":", #Black, #White)
          yTop + 25
          IconGroupHeaderDisplayed = #True
        EndIf

        *IconImage = LoadResource_(LibHandle, FindResource_(LibHandle, *GrpIconDir\idEntries[i]\nID, #RT_ICON))
        IconHandle = CreateIconFromResourceEx_(*IconImage, *IconImage\icHeader\biBitCount, #True, $00030000, *GrpIconDir\idEntries[i]\bWidth, *GrpIconDir\idEntries[i]\bHeight, 0)

        DrawIconEx_(WindowDC, xLeft + 27, yTop, IconHandle, *GrpIconDir\idEntries[i]\bWidth, *GrpIconDir\idEntries[i]\bHeight, 0, 0, #DI_NORMAL)
        DestroyIcon_(IconHandle)
        DrawText(xLeft, yTop, "#" + Str(*GrpIconDir\idEntries[i]\nID), #Black, #White)

        xLeft + *GrpIconDir\idEntries[i]\bWidth + 45
      EndIf
    Next i

    If IconGroupHeaderDisplayed
      yTop + 74
    EndIf
  EndIf
Next 

StopDrawing()

FreeLibrary_(LibHandle)

While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend

thanks for your help and thanks to all help me :D

Re: how to show several sizes of the icons help

Posted: Tue Jan 12, 2010 11:16 pm
by Shardik
mx101 wrote:thanks for your help and thanks to all help me :D
You are welcome. :D

Re: how to show several sizes of the icons help

Posted: Thu Jan 14, 2010 3:11 pm
by mx101
hi again....


i need some help with this again.

I only want to show one icon of every time and only one depth.

each icon have several depths like 16 color, 256 so on.

in my application i want show on mouseover only one icon in RGB/A 32 bit color how can i do this with your example?

Re: how to show several sizes of the icons help

Posted: Thu Jan 14, 2010 4:22 pm
by Shardik
mx101,

to display only icons with a width of 64 pixels and 32 bit color change this line of my last example

Code: Select all

If *GrpIconDir\idEntries[i]\bWidth = 64
into

Code: Select all

If *GrpIconDir\idEntries[i]\bWidth = 64 And *GrpIconDir\idEntries[i]\wBitCount = 32

Re: how to show several sizes of the icons help

Posted: Thu Jan 14, 2010 6:51 pm
by mx101
Shardik wrote:mx101,

to display only icons with a width of 64 pixels and 32 bit color change this line of my last example

Code: Select all

If *GrpIconDir\idEntries[i]\bWidth = 64
into

Code: Select all

If *GrpIconDir\idEntries[i]\bWidth = 64 And *GrpIconDir\idEntries[i]\wBitCount = 32

thank you very much Shardik

just one more question. :oops:

how can i show only one group at the time not all groups?

for example on mouseover only show the icon on group 6 with 64 pixels and 32 bit color.

sorry Shardik i'm newbie and i don't understand your code if you put comments to explain the code i will apreciate :oops:


i'm a lame with API code :oops:

Re: how to show several sizes of the icons help

Posted: Sat Jan 16, 2010 9:11 am
by Shardik
mx101,

for displaying only a specified single icon from an icon group you have to
know the icon id which you can find out with one of my previous examples.
Take a look into this new example which just displays icon #490 from the
library Shell32.DLL (tested with Windows 7 RC1):

Code: Select all

EnableExplicit

; ----- Specify the library name and the icon ID you want to display:
;       Icon 490 in Shell32.DLL (64x64 pixels, color depth: 32 Bits)

#LibraryName = "Shell32.DLL"
Define IconID.S = "#490"

; -----

#WindowHeight = 75
#WindowWidth = 200

Define IconHandle.I
Define *IconImage.ICONIMAGE
Define LibraryID.I
Define LibraryHandle.I
Define WindowDC.I

; Open the library which contains the wanted icon

LibraryID = OpenLibrary(#PB_Any, #LibraryName)

If LibraryID = 0
  MessageRequester("Error", "Unable to open library " + #LibraryName, #MB_ICONERROR)
  End
EndIf

LibraryHandle = LibraryID(LibraryID)

If FindResource_(LibraryHandle, @IconID, #RT_ICON) <> 0
  OpenWindow(0, 0, 0, #WindowWidth, #WindowHeight, "Icon " + IconID + " in " + GetFilePart(#LibraryName), #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

  WindowDC = StartDrawing(WindowOutput(0))

  *IconImage = LoadResource_(LibraryHandle, FindResource_(LibraryHandle, @IconID, #RT_ICON))
  IconHandle = CreateIconFromResourceEx_(*IconImage, *IconImage\icHeader\biBitCount, #True, $00030000, 0, 0, 0)

  DrawIconEx_(WindowDC, 75, 5, IconHandle, 0, 0, 0, 0, #DI_NORMAL)

  While WaitWindowEvent() <> #PB_Event_CloseWindow
  Wend
EndIf

CloseLibrary(LibraryID)

Re: how to show several sizes of the icons help

Posted: Sat Jan 16, 2010 10:16 am
by mx101
Shardik wrote:mx101,

for displaying only a specified single icon from an icon group you have to
know the icon id which you can find out with one of my previous examples.
Take a look into this new example which just displays icon #490 from the
library Shell32.DLL (tested with Windows 7 RC1):

Code: Select all

EnableExplicit

; ----- Specify the library name and the icon ID you want to display:
;       Icon 490 in Shell32.DLL (64x64 pixels, color depth: 32 Bits)

#LibraryName = "Shell32.DLL"
Define IconID.S = "#490"

; -----

#WindowHeight = 75
#WindowWidth = 200

Define IconHandle.I
Define *IconImage.ICONIMAGE
Define LibraryID.I
Define LibraryHandle.I
Define WindowDC.I

; Open the library which contains the wanted icon

LibraryID = OpenLibrary(#PB_Any, #LibraryName)

If LibraryID = 0
  MessageRequester("Error", "Unable to open library " + #LibraryName, #MB_ICONERROR)
  End
EndIf

LibraryHandle = LibraryID(LibraryID)

If FindResource_(LibraryHandle, @IconID, #RT_ICON) <> 0
  OpenWindow(0, 0, 0, #WindowWidth, #WindowHeight, "Icon " + IconID + " in " + GetFilePart(#LibraryName), #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

  WindowDC = StartDrawing(WindowOutput(0))

  *IconImage = LoadResource_(LibraryHandle, FindResource_(LibraryHandle, @IconID, #RT_ICON))
  IconHandle = CreateIconFromResourceEx_(*IconImage, *IconImage\icHeader\biBitCount, #True, $00030000, 0, 0, 0)

  DrawIconEx_(WindowDC, 75, 5, IconHandle, 0, 0, 0, 0, #DI_NORMAL)

  While WaitWindowEvent() <> #PB_Event_CloseWindow
  Wend
EndIf

CloseLibrary(LibraryID)
thanks Shardik again now i can complete my application thanks :D