viewtopic.php?f=12&t=17224
Added support for right-clicking to go backwards and changed the index to start from 0 to match the resource number.
Code: Select all
EnableExplicit
Enumeration
#GadgetButtonImage
#GadgetText
EndEnumeration
#FileName="explorer.exe"
Structure G_State
*OldWndProc
IconCount.i
IconIndex.i
EndStructure
Global G_State.G_State
G_State\IconIndex=0
G_State\IconCount=ExtractIcon_(0,#FileName,-1)
Procedure WinCallback(hWnd, uMsg, wParam, lParam)
Protected ButtonEvent
With G_State
Select uMsg
Case #WM_LBUTTONUP
\IconIndex+1
If \IconIndex=\IconCount
\IconIndex=0
EndIf
ButtonEvent=#True
Case #WM_RBUTTONUP
\IconIndex-1
If \IconIndex<0
\IconIndex=\IconCount-1
EndIf
ButtonEvent=#True
EndSelect
If ButtonEvent
SetGadgetAttribute(#GadgetButtonImage,#PB_Button_Image,ExtractIcon_(0,#FileName,\IconIndex))
SetGadgetText(#GadgetText,"Index: "+Str(\IconIndex))
EndIf
ProcedureReturn CallWindowProc_(G_State\OldWndProc,hWnd,uMsg,wParam,lParam)
EndWith
EndProcedure
OpenWindow(#PB_Any,0,0,130,70,Str(G_State\IconCount)+" Icons",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ButtonImageGadget(#GadgetButtonImage,10,10,48,48,ExtractIcon_(0,#FileName,G_State\IconIndex))
TextGadget(#GadgetText,70,30,60,20,"Index: "+Str(G_State\IconIndex))
G_State\OldWndProc=GetWindowLongPtr_(GadgetID(#GadgetButtonImage),#GWL_WNDPROC)
SetWindowLongPtr_(GadgetID(#GadgetButtonImage),#GWL_WNDPROC,@WinCallback())
Repeat
Until WaitWindowEvent(1)=#PB_Event_CloseWindow