It is currently Wed Nov 20, 2019 11:47 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Can't obtain icons beyond index 0 with LoadResource_()
PostPosted: Fri Sep 27, 2019 6:27 pm 
Offline
Addict
Addict

Joined: Sat Jun 30, 2007 8:04 pm
Posts: 3362
I know that this used to work but it doesn't anymore. For some reason I can only obtain an icon for the first index (0).

Here is a demo. When you click on the image gadget it increments the index and displays it as a titlebar icon and on the image gadget. The demo might work depending on your version of Windows but it doesn't work anymore on my Windows 10 x64.

To clarify, I'm pretty sure this has something with Windows and is not a bug in PureBasic. This is a Windows-specific code question.

Code:
Enumeration
  #GadgetButtonImage
EndEnumeration

Lib=LoadLibraryEx_("ddores.dll",0,#LOAD_LIBRARY_AS_DATAFILE)
*lpIconImage.ICONIMAGE=LoadResource_(Lib,FindResource_(Lib,1,#RT_ICON))

hIcon=CreateIconFromResource_(*lpIconImage,*lpIconImage\icHeader\biBitCount,1,$00030000)

Debug "hIcon: "+Str(hIcon)

Window=OpenWindow(#PB_Any,0,0,130,70,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ButtonImageGadget(#GadgetButtonImage,38,10,48,48,0)

PostMessage_(WindowID(Window),#WM_SETICON,1,hIcon)
SetGadgetAttribute(#GadgetButtonImage,#PB_Button_Image,hIcon)

Repeat
  Event=WaitWindowEvent()
 
  Select Event
  Case #PB_Event_Gadget
    If EventGadget()=#GadgetButtonImage And EventType()=#PB_EventType_LeftClick
      Index+1
     
      If Index=IconCount
        Index=0
      EndIf
     
      DestroyIcon_(hIcon)
     
      *lpIconImage=LoadResource_(Lib,FindResource_(Lib,1,#RT_ICON))
      hIcon=CreateIconFromResource_(*lpIconImage,*lpIconImage\icHeader\biBitCount,1,$00030000)
     
      Debug "hIcon: "+Str(hIcon)
     
      PostMessage_(WindowID(Window),#WM_SETICON,1,hIcon)
      SetGadgetAttribute(#GadgetButtonImage,#PB_Button_Image,hIcon)
    EndIf
  EndSelect
Until Event=#PB_Event_CloseWindow


Top
 Profile  
Reply with quote  
 Post subject: Re: Can't obtain icons beyond index 0 with LoadResource_()
PostPosted: Sun Sep 29, 2019 11:30 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Apr 25, 2003 5:10 pm
Posts: 504
Location: Doubs - France
Hi Mistrel,
the right way is to enumerate resource.

Here a quick try, but be carrefull using API CreateIconFromResource_() wich use API CreateIconFromResourceEx()
Quote:
The CreateIconFromResource function calls CreateIconFromResourceEx passing LR_DEFAULTSIZE|LR_SHARED as flags.

May be it could erase system icon.

following use 2 callback, the first one to count Icon and the second to load the correct icon using its position (not Icon ID)

ddores.dll has 147 Icon groups and 1066 icons.

Code:
EnableExplicit
;- Enumeration
Enumeration
      #GadgetButtonImage
EndEnumeration

#StartOfErrors = 1
Enumeration  #StartOfErrors
      #ErrorCode_No_Error
      ; Callback error
      #error_BadCallbackParameter
      #error_FindResource_Fails
      #error_LoadResource_Fails
      #error_BadIconIndex
      #error_sizeOfResource_Fails
      #error_CreateIconFromResource_Fails
      ;
      #error_100
      #error_101
EndEnumeration


#Stop_Enumeration     = #False
#Continue_Enumeration = #True
#Return_Error    = 0
#Return_No_Error = 1

#IntegerIdentifier = 0


Declare SetlastError(Error_Code)


;-'           Macros
Macro _StopEnumeration_With_Error(Error_Code)
      SetlastError(Error_Code)
      ProcedureReturn #Stop_Enumeration
EndMacro
Macro _StopEnumeration_With_No_Error()
      SetlastError(#ErrorCode_No_Error)
      ProcedureReturn #Stop_Enumeration
EndMacro
Macro _ContinueEnumeration__With__No_Error()
      ProcedureReturn #Continue_Enumeration
EndMacro
Macro _ExitProcedure_With_Error(Error_Code)
      SetlastError(Error_Code)
      ProcedureReturn #Return_Error
EndMacro
Macro _Reset_ErrorCode()
      SetlastError(#ErrorCode_No_Error)
EndMacro

;- Structures
Structure iconGroupsNumber
      ;// nombre d'icônes pour le comptage courant/Icon number for the current count
      iconNumber.i
EndStructure
Structure GetIcon
      ;// Numéro de l'icône à trouver/Icon number to find
      iconPositionToFind.i
      ;// Numéro de l'icône courrante/current Icon number
      currentIconPosition.i
      ;// Id de l'icône/Icon id
      *icon
EndStructure

;- Global var
;// erreur courante/current error
Global g_LastErrorCode
;-
Procedure.i Callback_CountIcon(*hModule, resType, ResName, *resourceInfos.iconGroupsNumber)
      ; https://docs.microsoft.com/fr-fr/previous-versions/windows/desktop/legacy/ms648034(v=vs.85)
      ; EnumResNameProc callback function
      ; BOOL CALLBACK EnumResNameProc(
      ;   _In_opt_ HMODULE  hModule,
      ;   _In_     LPCTSTR  lpszType,
      ;   _In_     LPTSTR   lpszName,
      ;   _In_     LONG_PTR lParam
      ; )
     
      ;// l'adresse de la ressource d'icônes identifiée par ResName
      ;// ResName est donné par le système et est l'identifiant numérique ou alpahanumérique de l'icône
      ;// icon resource address identified by ResName,
      ;// ResName is put by the system and is an Icon ID, numerical or alphanumerical
      Protected *FindResource_RT_ICON
     
      If Not(*hModule And *resourceInfos And (resType = #RT_ICON))
            _StopEnumeration_With_Error(#error_BadCallbackParameter)
      EndIf
     
      *FindResource_RT_ICON = FindResource_(*hModule, ResName, resType)
      If *FindResource_RT_ICON
            If LoadResource_(*hModule, *FindResource_RT_ICON)
                  *resourceInfos\IconNumber + 1
                  _ContinueEnumeration__With__No_Error()
            Else
                  _StopEnumeration_With_Error(#error_LoadResource_Fails)
            EndIf
      Else
            _StopEnumeration_With_Error(#error_FindResource_Fails)
      EndIf
EndProcedure
Procedure.i Callback_GetIcon(*hModule, resType, ResName, *resourceInfos.GetIcon)
      ; https://docs.microsoft.com/fr-fr/previous-versions/windows/desktop/legacy/ms648034(v=vs.85)
      ; EnumResNameProc callback function
      ; BOOL CALLBACK EnumResNameProc(
      ;   _In_opt_ HMODULE  hModule,
      ;   _In_     LPCTSTR  lpszType,
      ;   _In_     LPTSTR   lpszName,
      ;   _In_     LONG_PTR lParam
      ; )
     
      ;// l'adresse de la ressource groupe d'icônes identifiée par ResName
      ;// ResName est donné par le stème et est l'identifiant numérique ou alpahanumérique du groupe
      ;// address of resource icon group identified by ResName,
      ;// ResName is put by the system And is Group ID, numerical Or alphanumerical
      Protected *FindResource_RT_ICON
      ;// le handle du bloc d'information des données de la ressource chargée
      Protected *LoadResource_RT_ICON
      ;// Taille de la ressource/resource size
      Protected sizeOfResource_RT_ICON
     
      If Not(*hModule And *resourceInfos And (resType = #RT_ICON))
            _StopEnumeration_With_Error(#error_BadCallbackParameter)
      EndIf
     
      ;// Numéro du group courrant/current group number
      *resourceInfos\currentIconPosition + 1
      If *resourceInfos\currentIconPosition =  *resourceInfos\iconPositionToFind
            ;// Group position Ok
            *FindResource_RT_ICON = FindResource_(*hModule, ResName, resType)
            If *FindResource_RT_ICON
                  *LoadResource_RT_ICON = LoadResource_(*hModule, *FindResource_RT_ICON)
                  If *LoadResource_RT_ICON
                        sizeOfResource_RT_ICON = SizeofResource_(*hModule, *FindResource_RT_ICON)
                        If sizeOfResource_RT_ICON
                              *resourceInfos\icon = CreateIconFromResource_(*LoadResource_RT_ICON, sizeOfResource_RT_ICON, 1, $00030000)
                              If *resourceInfos\icon = #Null
                                    _StopEnumeration_With_Error(#error_CreateIconFromResource_Fails)
                              Else
                                    ;// It's OK, Icon loaded
                                    _StopEnumeration_With_No_Error()
                              EndIf
                        Else
                              _StopEnumeration_With_Error(#error_sizeOfResource_Fails)
                        EndIf
                  Else
                        _StopEnumeration_With_Error(#error_LoadResource_Fails)
                  EndIf
            Else
                  _StopEnumeration_With_Error(#error_FindResource_Fails)
            EndIf
      ElseIf  *resourceInfos\currentIconPosition > *resourceInfos\iconPositionToFind
            _StopEnumeration_With_Error(#error_BadIconIndex)
      Else
            _ContinueEnumeration__With__No_Error()
      EndIf
EndProcedure

Procedure.i GetLastError()
      ProcedureReturn g_LastErrorCode
EndProcedure
Procedure SetlastError(Error_Code)
      g_LastErrorCode = Error_Code
EndProcedure

;-
Procedure Programme()
      Protected Window, Event, Index, IconCount
      Protected resourceInfos.iconGroupsNumber
      Protected resourceIcon.GetIcon
      Protected *hModule
     
      *hModule = LoadLibraryEx_("ddores.dll", 0,#LOAD_LIBRARY_AS_DATAFILE)
      If Not(*hModule)
            MessageRequester("Erreur/Error", "Impossible de charger la dll"+#LF$+"Unable to load dll")
            End
      EndIf
     
      Window=OpenWindow(#PB_Any,0,0,130,70,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
     
      ;// on énumère les icônes pour en retrouver le nombre
      ;// enumerates icons to find the number
      Select EnumResourceNames_(*hModule, #RT_ICON, @Callback_CountIcon(), @resourceInfos)
            Case #Stop_Enumeration
                  If GetLastError() <> #ErrorCode_No_Error
                        MessageRequester("Erreur/Error", "Impossible d'énumérer les icônes"+#LF$+"Unable to enumerate icons")
                        FreeLibrary_(*hModule)
                        End
                  EndIf
      EndSelect
     
      IconCount = resourceInfos\iconNumber
     
      ButtonImageGadget(#GadgetButtonImage,38,10,48,48,0)
     
      ;// display the first Icon
      PostEvent(#PB_Event_Gadget, Window, #GadgetButtonImage, #PB_EventType_LeftClick)
     
      Repeat
            Event=WaitWindowEvent()
           
            Select Event
                  Case #PB_Event_Gadget
                        If EventGadget()=#GadgetButtonImage And EventType()=#PB_EventType_LeftClick
                              Index+1
                             
                              If Index = IconCount+1
                                    Index = 1
                              EndIf
                             
                              resourceIcon\iconPositionToFind  = Index
                              resourceIcon\currentIconPosition = 0
                             
                              If resourceIcon\icon
                                    DestroyIcon_(resourceIcon\icon)
                                    resourceIcon\icon = 0
                              EndIf
                             
                              _Reset_ErrorCode()
                              Select EnumResourceNames_(*hModule, #RT_ICON, @Callback_GetIcon(), @resourceIcon)
                                    Case #Stop_Enumeration
                                          If GetLastError() = #ErrorCode_No_Error
                                                PostMessage_(WindowID(Window),#WM_SETICON,1, resourceIcon\icon)
                                                SetGadgetAttribute(#GadgetButtonImage,#PB_Button_Image, resourceIcon\icon)
                                                SetWindowTitle(Window, Str(Index)+"/"+Str(IconCount))
                                          Else
                                                MessageRequester("","")
                                          EndIf
                              EndSelect
                             
                             
                        EndIf
            EndSelect
      Until Event=#PB_Event_CloseWindow
      If resourceIcon\icon
            DestroyIcon_(resourceIcon\icon)
            resourceIcon\icon = 0
      EndIf
      FreeLibrary_(*hModule)
EndProcedure

Programme()

_________________
A+
Denis


Top
 Profile  
Reply with quote  
 Post subject: Re: Can't obtain icons beyond index 0 with LoadResource_()
PostPosted: Wed Oct 30, 2019 10:57 am 
Offline
New User
New User

Joined: Wed Oct 30, 2019 10:54 am
Posts: 1
Denis wrote:
Hi Mistrel,
the right way is to enumerate resource.

Here a quick try, but be carrefull using API CreateIconFromResource_() wich use API CreateIconFromResourceEx()
Quote:
The CreateIconFromResource function calls CreateIconFromResourceEx passing LR_DEFAULTSIZE|LR_SHARED as flags.

May be it could erase system icon.

following use 2 callback, the first one to count Icon and the second to load the correct icon using its position (not Icon ID)

ddores.dll has 147 Icon groups and 1066 icons.

Code:
EnableExplicit
;- Enumeration
Enumeration
      #GadgetButtonImage
EndEnumeration

#StartOfErrors = 1
Enumeration  #StartOfErrors
      #ErrorCode_No_Error
      ; Callback error
      #error_BadCallbackParameter
      #error_FindResource_Fails
      #error_LoadResource_Fails
      #error_BadIconIndex
      #error_sizeOfResource_Fails
      #error_CreateIconFromResource_Fails
      ;
      #error_100
      #error_101
EndEnumeration


#Stop_Enumeration     = #False
#Continue_Enumeration = #True
#Return_Error    = 0
#Return_No_Error = 1

#IntegerIdentifier = 0


Declare SetlastError(Error_Code)


;-'           Macros
Macro _StopEnumeration_With_Error(Error_Code)
      SetlastError(Error_Code)
      ProcedureReturn #Stop_Enumeration
EndMacro
Macro _StopEnumeration_With_No_Error()
      SetlastError(#ErrorCode_No_Error)
      ProcedureReturn #Stop_Enumeration
EndMacro
Macro _ContinueEnumeration__With__No_Error()
      ProcedureReturn #Continue_Enumeration
EndMacro
Macro _ExitProcedure_With_Error(Error_Code)
      SetlastError(Error_Code)
      ProcedureReturn #Return_Error
EndMacro
Macro _Reset_ErrorCode()
      SetlastError(#ErrorCode_No_Error)
EndMacro

;- Structures
Structure iconGroupsNumber
      ;// nombre d'icônes pour le comptage courant/Icon number for the current count
      iconNumber.i
EndStructure
Structure GetIcon
      ;// Numéro de l'icône à trouver/Icon number to find
      iconPositionToFind.i
      ;// Numéro de l'icône courrante/current Icon number
      currentIconPosition.i
      ;// Id de l'icône/Icon id
      *icon
EndStructure

;- Global var
;// erreur courante/current error
Global g_LastErrorCode
;-
Procedure.i Callback_CountIcon(*hModule, resType, ResName, *resourceInfos.iconGroupsNumber)
      ; https://docs.microsoft.com/fr-fr/previous-versions/windows/desktop/legacy/ms648034(v=vs.85)
      ; EnumResNameProc callback function
      ; BOOL CALLBACK EnumResNameProc(
      ;   _In_opt_ HMODULE  hModule,
      ;   _In_     LPCTSTR  lpszType,
      ;   _In_     LPTSTR   lpszName,
      ;   _In_     LONG_PTR lParam
      ; )
     
      ;// l'adresse de la ressource d'icônes identifiée par ResName
      ;// ResName est donné par le système et est l'identifiant numérique ou alpahanumérique de l'icône
      ;// icon resource address identified by ResName,
      ;// ResName is put by the system and is an Icon ID, numerical or alphanumerical
      Protected *FindResource_RT_ICON
     
      If Not(*hModule And *resourceInfos And (resType = #RT_ICON))
            _StopEnumeration_With_Error(#error_BadCallbackParameter)
      EndIf
     
      *FindResource_RT_ICON = FindResource_(*hModule, ResName, resType)
      If *FindResource_RT_ICON
            If LoadResource_(*hModule, *FindResource_RT_ICON)
                  *resourceInfos\IconNumber + 1
                  _ContinueEnumeration__With__No_Error()
            Else
                  _StopEnumeration_With_Error(#error_LoadResource_Fails)
            EndIf
      Else
            _StopEnumeration_With_Error(#error_FindResource_Fails)
      EndIf
EndProcedure
Procedure.i Callback_GetIcon(*hModule, resType, ResName, *resourceInfos.GetIcon)
      ; https://docs.microsoft.com/fr-fr/previous-versions/windows/desktop/legacy/ms648034(v=vs.85)
      ; EnumResNameProc callback function
      ; BOOL CALLBACK EnumResNameProc(
      ;   _In_opt_ HMODULE  hModule,
      ;   _In_     LPCTSTR  lpszType,
      ;   _In_     LPTSTR   lpszName,
      ;   _In_     LONG_PTR lParam
      ; )
     
      ;// l'adresse de la ressource groupe d'icônes identifiée par ResName
      ;// ResName est donné par le stème et est l'identifiant numérique ou alpahanumérique du groupe
      ;// address of resource icon group identified by ResName,
      ;// ResName is put by the system And is Group ID, numerical Or alphanumerical
      Protected *FindResource_RT_ICON
      ;// le handle du bloc d'information des données de la ressource chargée
      Protected *LoadResource_RT_ICON
      ;// Taille de la ressource/resource size
      Protected sizeOfResource_RT_ICON
     
      If Not(*hModule And *resourceInfos And (resType = #RT_ICON))
            _StopEnumeration_With_Error(#error_BadCallbackParameter)
      EndIf
     
      ;// Numéro du group courrant/current group number
      *resourceInfos\currentIconPosition + 1
      If *resourceInfos\currentIconPosition =  *resourceInfos\iconPositionToFind
            ;// Group position Ok
            *FindResource_RT_ICON = FindResource_(*hModule, ResName, resType)
            If *FindResource_RT_ICON
                  *LoadResource_RT_ICON = LoadResource_(*hModule, *FindResource_RT_ICON)
                  If *LoadResource_RT_ICON
                        sizeOfResource_RT_ICON = SizeofResource_(*hModule, *FindResource_RT_ICON)
                        If sizeOfResource_RT_ICON
                              *resourceInfos\icon = CreateIconFromResource_(*LoadResource_RT_ICON, sizeOfResource_RT_ICON, 1, $00030000)
                              If *resourceInfos\icon = #Null
                                    _StopEnumeration_With_Error(#error_CreateIconFromResource_Fails)
                              Else
                                    ;// It's OK, Icon loaded
                                    _StopEnumeration_With_No_Error()
                              EndIf
                        Else
                              _StopEnumeration_With_Error(#error_sizeOfResource_Fails)
                        EndIf
                  Else
                        _StopEnumeration_With_Error(#error_LoadResource_Fails)
                  EndIf
            Else
                  _StopEnumeration_With_Error(#error_FindResource_Fails)
            EndIf
      ElseIf  *resourceInfos\currentIconPosition > *resourceInfos\iconPositionToFind
            _StopEnumeration_With_Error(#error_BadIconIndex)
      Else
            _ContinueEnumeration__With__No_Error()
      EndIf
EndProcedure

Procedure.i GetLastError()
      ProcedureReturn g_LastErrorCode
EndProcedure
Procedure SetlastError(Error_Code)
      g_LastErrorCode = Error_Code
EndProcedure

;-
Procedure Programme()
      Protected Window, Event, Index, IconCount
      Protected resourceInfos.iconGroupsNumber
      Protected resourceIcon.GetIcon
      Protected *hModule
     
      *hModule = LoadLibraryEx_("ddores.dll", 0,#LOAD_LIBRARY_AS_DATAFILE)
      If Not(*hModule)
            MessageRequester("Erreur/Error", "Impossible de charger la dll"+#LF$+"Unable to load dll")
            End
      EndIf
     
      Window=OpenWindow(#PB_Any,0,0,130,70,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
     
      ;// on énumère les icônes pour en retrouver le nombre
      ;// enumerates icons to find the number
      Select EnumResourceNames_(*hModule, #RT_ICON, @Callback_CountIcon(), @resourceInfos)
            Case #Stop_Enumeration
                  If GetLastError() <> #ErrorCode_No_Error
                        MessageRequester("Erreur/Error", "Impossible d'énumérer les icônes"+#LF$+"Unable to enumerate icons")
                        FreeLibrary_(*hModule)
                        End
                  EndIf
      EndSelect
     
      IconCount = resourceInfos\iconNumber
     
      ButtonImageGadget(#GadgetButtonImage,38,10,48,48,0)
     
      ;// display the first Icon
      PostEvent(#PB_Event_Gadget, Window, #GadgetButtonImage, #PB_EventType_LeftClick)
     
      Repeat
            Event=WaitWindowEvent()
           
            Select Event
                  Case #PB_Event_Gadget
                        If EventGadget()=#GadgetButtonImage And EventType()=#PB_EventType_LeftClick
                              Index+1
                             
                              If Index = IconCount+1
                                    Index = 1
                              EndIf
                             
                              resourceIcon\iconPositionToFind  = Index
                              resourceIcon\currentIconPosition = 0
                             
                              If resourceIcon\icon
                                    DestroyIcon_(resourceIcon\icon)
                                    resourceIcon\icon = 0
                              EndIf
                             
                              _Reset_ErrorCode()
                              Select EnumResourceNames_(*hModule, #RT_ICON, @Callback_GetIcon(), @resourceIcon)
                                    Case #Stop_Enumeration
                                          If GetLastError() = #ErrorCode_No_Error
                                                PostMessage_(WindowID(Window),#WM_SETICON,1, resourceIcon\icon)
                                                SetGadgetAttribute(#GadgetButtonImage,#PB_Button_Image, resourceIcon\icon)
                                                SetWindowTitle(Window, Str(Index)+"/"+Str(IconCount))
                                          Else
                                                MessageRequester("","")
                                          EndIf
                              EndSelect
                             
                             
                        EndIf
            EndSelect
      Until Event=#PB_Event_CloseWindow
      If resourceIcon\icon
            DestroyIcon_(resourceIcon\icon)
            resourceIcon\icon = 0
      EndIf
      FreeLibrary_(*hModule)
EndProcedure

Programme()


Upon enumerating the source it erased the system icon. How can it be restored?
Any suggestions?


Top
 Profile  
Reply with quote  
 Post subject: Re: Can't obtain icons beyond index 0 with LoadResource_()
PostPosted: Wed Oct 30, 2019 1:00 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 394
Where can I get "ddores.dll" to test?


Top
 Profile  
Reply with quote  
 Post subject: Re: Can't obtain icons beyond index 0 with LoadResource_()
PostPosted: Wed Oct 30, 2019 1:43 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3457
Hi Barry
- ..\Windows\system32 :)

Windows 10 changed the system to obtain the resources from it's DLL
Now you can not obtain the icons from Imagers.dll for example
If you checked the size of the dll you will find it much smaller,it is just a pointer to another file
If it is necessary so copy the same dll from windows 8 :wink:
And then use Denis snippet

For Windows 10 you can use
Code:
File$ = "ddores.dll"

num = ExtractIconEx_(File$, -1, 0, 0, 0)

If num > 0
  Dim SIcon(num)
  Dim LIcon(num)
 
  ExtractIconEx_(File$, 0, LIcon(), SIcon(), num)
 
  OpenWindow(0,0,0,640,480,"",#PB_Window_ScreenCentered| #PB_Window_SystemMenu)
  ImageGadget(0,10,10,32,32,0)
 
  For ic = 0 To num   
    SetGadgetState(0,LIcon(ic))
    Delay(200)
  Next
   
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
           Quit = 1
           
    EndSelect
  Until Quit = 1
EndIf

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Can't obtain icons beyond index 0 with LoadResource_()
PostPosted: Wed Oct 30, 2019 2:59 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4528
Location: Lyon - France
Thanks RASHAD, works also with W7 8)

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


Top
 Profile  
Reply with quote  
 Post subject: Re: Can't obtain icons beyond index 0 with LoadResource_()
PostPosted: Wed Oct 30, 2019 7:49 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Apr 25, 2003 5:10 pm
Posts: 504
Location: Doubs - France
MaxP00 wrote:
Upon enumerating the source it erased the system icon. How can it be restored?
Any suggestions?


Hi MaxP00,
the piece of code i put here is extracted from PureIconManager i've written some years ago. Not easy to adapt simply.

if the icon is a system one, you have to not delete it, else you have to restart your computer i suppose...

so replaces
Code:
*resourceInfos\icon = CreateIconFromResource_(*LoadResource_RT_ICON, sizeOfResource_RT_ICON, 1, $00030000)

with
Code:
*resourceInfos\icon = CreateIconFromResourceEx_(*LoadResource_RT_ICON, sizeOfResource_RT_ICON, #True, $00030000, 48, 48, #LR_DEFAULTCOLOR|#LR_SHARED)


replaces all occurence of
Code:
DestroyIcon_(resourceIcon\icon)

with
Code:
; DestroyIcon_(resourceIcon\icon)


even if CreateIconFromResource call CreateIconFromResourceEx, i do prefer to use directly CreateIconFromResourceEx

and tell me if it's Ok

for info
CreateIconFromResourceEx here
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createiconfromresourceex

_________________
A+
Denis


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 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