

Code: Select all
#RT_GROUP_CURSOR = 12
NewList ResNameList.S()
Procedure.l EnumResNameProc(ResHandle.L, ResType.L, ResName.L, AppParam.L)
Shared ResNameList.S()
AddElement(ResNameList())
ResNameList() = "#" + Str(ResName)
ProcedureReturn #True
EndProcedure
Procedure.L EnumResTypeProc(ResHandle.L, ResType.L, AppParam.L)
If ResType = #RT_GROUP_CURSOR
EnumResourceNames_(ResHandle, ResType, @EnumResNameProc(), 0)
EndIf
ProcedureReturn #True
EndProcedure
LibName.S = "MSPaint.Exe"
LibHandle.L = LoadLibrary_(@LibName)
If LibHandle = 0
MessageRequester("Error", "Loading of " + LibName + " failed!", #MB_ICONERROR)
End
EndIf
EnumResourceTypes_(LibHandle, @EnumResTypeProc(), 0)
CreateImage(0, 135, 57)
StartDrawing(ImageOutput(0))
Box(0, 0, 135, 57, #White)
StopDrawing()
OpenWindow(0, 0, 0, 160, 100, "Display lib's cursors", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
ImageGadget(0, 10, 10, 135, 57, ImageID(0), #PB_Image_Border)
ButtonGadget(1, 10, 75, 140, 20, "Switch to another cursor")
ForEach ResNameList()
CursorHandle = LoadImage_(LibHandle, ResNameList(), #IMAGE_CURSOR, 0, 0, #LR_DEFAULTCOLOR)
If CursorHandle = 0
MessageRequester("Error", "Loading of cursor " + ResNameList() + " from " + LibName + " failed!", #MB_ICONERROR)
FreeLibrary_(LibHandle)
End
EndIf
SetClassLong_(GadgetID(0), #GCL_HCURSOR, CursorHandle)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
If EventGadget() = 1
Break
EndIf
Case #PB_Event_CloseWindow
DestroyIcon_(CursorHandle)
FreeLibrary_(LibHandle)
End
EndSelect
ForEver
DestroyIcon_(CursorHandle)
Next
FreeLibrary_(LibHandle)
Code: Select all
Import "Ressource.res"
EndImport
Code: Select all
LibHandle.L = LoadLibrary_(@LibName)
Code: Select all
HandleResource= FindResource_(0,@Name,#RT_RCDATA)
In fact i don't knowEnumResourceNames_() or EnumResourceNamesEx_() ?
Code: Select all
LibHandle.L = LoadLibrary_(@LibName)
Code: Select all
Import "Ressources.res"
EndImport
Code: Select all
; PureBasic 3.94 25/11/05
; Create a File with RC Extension And include it as RC_DATA Resource Type
; Path can be absolute Or relative
; Exemple :
; REG RCData "C:\WINDOWS\REGEDIT.EXE"
; SON RCData "son.wav"
; Image RCData "image.bmp"
;/ SaveResourceAs(Name.s,File.s) Save the resource as a file
;/ GetResourcePointer(Name.s) is usefull with PureBasic CatchXXX functions (CatchImage / CatchSound ... )
ProcedureDLL SaveResourceAs(Name.s,File.s)
; (Use GetModuleHandle_ if you want to specify another file)
HandleResource= FindResource_(0,@Name,#RT_RCDATA)
If HandleResource
HandleGlobalMemoryBlock=LoadResource_(0,HandleResource)
PointerFirstByteOfTheResource=LockResource_(HandleGlobalMemoryBlock)
; Get size of the resource
Size= SizeofResource_(Handle,HandleResource)
; Save the file
FileId=OpenFile(#PB_Any,File)
If FileId
WriteData(HandleGlobalMemoryBlock,Size)
CloseFile(FileId)
EndIf
; Test if the file is written
If FileSize(File)=Size
ProcedureReturn 1
EndIf
EndIf
EndProcedure
ProcedureDLL GetResourcePointer(Name.s)
; (Use GetModuleHandle_ if you want to specify another file)
HandleResource= FindResource_(0,@Name,#RT_RCDATA)
If HandleResource
HandleGlobalMemoryBlock=LoadResource_(0,HandleResource)
PointerFirstByteOfTheResource=LockResource_(HandleGlobalMemoryBlock)
ProcedureReturn HandleGlobalMemoryBlock
EndIf
EndProcedure
ProcedureDLL GetResourceSize(Name.s)
; (Use GetModuleHandle_ if you want to specify another file)
HandleResource= FindResource_(0,@Name,#RT_RCDATA)
If HandleResource
HandleGlobalMemoryBlock=LoadResource_(0,HandleResource)
PointerFirstByteOfTheResource=LockResource_(HandleGlobalMemoryBlock)
; Return the size of the resource
Size= SizeofResource_(Handle,HandleResource)
ProcedureReturn Size
EndIf
EndProcedure
;/ Test
CatchImage(0,GetResourcePointer("IMAGE"))
OpenWindow(0,0,0,240,240,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"ImageGadget")
ImageGadget(0,20,20,200,200,UseImage(0),#PB_Image_Border)
SaveResourceAs("REG","c:\Picture.jpg")
Code: Select all
FreeLibrary_(LibHandle)
Code: Select all
Import "c:\Ressources.res"
EndImport
Procedure.l EnumResNameProc(ResHandle.L, ResType.L, ResName.L, AppParam.L)
Debug PeekS(ResName)
ProcedureReturn #True
EndProcedure
Procedure.L EnumResTypeProc(ResHandle.L, ResType.L, AppParam.L)
Debug ResType
If ResType = #RT_RCDATA
EnumResourceNames_(ResHandle, ResType, @EnumResNameProc(), 0)
EndIf
ProcedureReturn #True
EndProcedure
LibHandle.L = GetModuleHandle_(0)
EnumResourceTypes_(LibHandle, @EnumResTypeProc(), 0)
Repeat
Delay(100)
ForEver
FreeLibrary_(LibHandle)
I think you can just pass #Null to EnumResourceTypes_ to get the same effect. I.e.:Kwaï chang caïne wrote:1/ I use "GetModuleHandle_(0)" but is it the good way ??? :roll:
Code: Select all
EnumResourceTypes_(0, @EnumResTypeProc(), 0)
You shouldn't do that, here's an explanation from msdn:Kwaï chang caïne wrote:2/ The line is it usefull ????
Code: Select all
FreeLibrary_(LibHandle)
msdn wrote:Use caution when calling FreeLibrary with a handle returned by GetModuleHandle. The GetModuleHandle function does not increment a module's reference count, so passing this handle to FreeLibrary can cause a module to be unloaded prematurely.
Thanks a lot EESAUI think you can just pass #Null to EnumResourceTypes_ to get the same effect. I.e.:
Ok thanks too...You shouldn't do that, here's an explanation from msdn: