SetCursor_() - Pippet in paint??
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
srod,
unfortunately I am no expert in working with resources and therefore can't answer your question about the details in the difference between the use of ExtractIcon_() and LoadImage_(). But if you want to know how to scan for resources in DLL- and Exe-Files, take a look into the nice code from VoSs2o0o in the German forum:
http://www.purebasic.fr/german/archive/ ... 0&start=10
VoSs2o0o demonstrates how to extract and save an icon from the Shell32.DLL without knowing the resource name by using the following WinAPI and PB functions:
- LoadLibraryEx_()
- FindResource_()
- LoadResource_()
- LockResource_()
- CopyMemory()
- Analyze the icon information (number of icons, color, etc.) and save it
The analysis of other resources like cursors, AVI, etc. should be similar...
Some time ago I wrote a scanner to analyze Windows resource files for AVI animations for use in my own programs, but I had to freeze this project because of missing time. The scanning part was ready (using EnumResourceTypes_()) so that I was informed whether a resource file (for example Shell32.dll) contains AVI animations but the read out of the resources is still unfinished. The display of the animations is no problem... As soon as this project is finished I will post it in this forum.
unfortunately I am no expert in working with resources and therefore can't answer your question about the details in the difference between the use of ExtractIcon_() and LoadImage_(). But if you want to know how to scan for resources in DLL- and Exe-Files, take a look into the nice code from VoSs2o0o in the German forum:
http://www.purebasic.fr/german/archive/ ... 0&start=10
VoSs2o0o demonstrates how to extract and save an icon from the Shell32.DLL without knowing the resource name by using the following WinAPI and PB functions:
- LoadLibraryEx_()
- FindResource_()
- LoadResource_()
- LockResource_()
- CopyMemory()
- Analyze the icon information (number of icons, color, etc.) and save it
The analysis of other resources like cursors, AVI, etc. should be similar...
Some time ago I wrote a scanner to analyze Windows resource files for AVI animations for use in my own programs, but I had to freeze this project because of missing time. The scanning part was ready (using EnumResourceTypes_()) so that I was informed whether a resource file (for example Shell32.dll) contains AVI animations but the read out of the resources is still unfinished. The display of the animations is no problem... As soon as this project is finished I will post it in this forum.
If you want to see which cursors are contained as resources in a library (like .Exe, .DLL, .OCX or .Scr), try the following code example which displays all cursors of MSPaint.Exe:
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)
- Kwai chang caine
- Always Here

- Posts: 5502
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Yes the code of SHARDIK is great and so simple 
But KCC have again a fly in his milk
If i have insert the ressource in my exe with
I can't use for obtain the handle
And i want enumerate the ressource inside it
How can i obtain the handle of the exe who extract HIS ressources ????
In the GREAT code of DROOPY lib, he use, for extract HIS ressource:
But if i don't know the name of the ressource who is in my exe ???
I must enumerate all the ressource in my EXE, and choose the ressource i want to extract :roll:
How can i do ???
But KCC have again a fly in his milk
If i have insert the ressource in my exe with
Code: Select all
Import "Ressource.res"
EndImportCode: Select all
LibHandle.L = LoadLibrary_(@LibName) How can i obtain the handle of the exe who extract HIS ressources ????
In the GREAT code of DROOPY lib, he use, for extract HIS ressource:
Code: Select all
HandleResource= FindResource_(0,@Name,#RT_RCDATA)I must enumerate all the ressource in my EXE, and choose the ressource i want to extract :roll:
How can i do ???
The happiness is a road...Not a destination
- Kwai chang caine
- Always Here

- Posts: 5502
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Hello CAS
Thanks to answer at my question
My problem is for understand how an EXE can scan itself for ENUMERATE and extracting ressources inside him ???? :roll:
I found some codes, who use for access at the ressource.
But me...the ressources is in the exe who ENUMERATE and extract it
I have include it with
I don't know how the EXE obtain the handle of himself ??? 
In the great code of DROOPY, the EXE scan itself and save ressource in a picture file, but i don't understand how ENUMERATE the ressources in this code
Thanks to answer at my question
In fact i don't knowEnumResourceNames_() or EnumResourceNamesEx_() ?
My problem is for understand how an EXE can scan itself for ENUMERATE and extracting ressources inside him ???? :roll:
I found some codes, who use for access at the ressource.
Code: Select all
LibHandle.L = LoadLibrary_(@LibName) I have include it with
Code: Select all
Import "Ressources.res"
EndImportIn the great code of DROOPY, the EXE scan itself and save ressource in a picture file, but i don't understand how ENUMERATE the ressources in this code
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")
The happiness is a road...Not a destination
- Kwai chang caine
- Always Here

- Posts: 5502
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
I have destroy the nice code of SHARDIK to made that...
That's works apparently
1/ I use "GetModuleHandle_(0)" but is it the good way ??? :roll:
2/ The line is it usefull ????
This is my cowpat ...
That's works apparently
1/ I use "GetModuleHandle_(0)" but is it the good way ??? :roll:
2/ The line is it usefull ????
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)
The happiness is a road...Not a destination
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.
- Kwai chang caine
- Always Here

- Posts: 5502
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Thanks a lot EESAUI think you can just pass #Null to EnumResourceTypes_ to get the same effect. I.e.:
You're right, i just replace the handle by "0" and that's works better fine
Just a "0" is the fault of all my worries
Ok thanks too...You shouldn't do that, here's an explanation from msdn:
If EESAU and Mister CROSOFT say KCC don't use FREELIBRARY
Then KCC don't use.....
I promise to you
Thanks a lot again for your precious help
I wish you a very good day
The happiness is a road...Not a destination

