Purebasic Resources.pbi mise a jour v0.3

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Purebasic Resources.pbi mise a jour v0.3

Message par celtic88 »

Bonjour à toutes 8) et à tous :lol: ,,
j ai crée ce "Inclu" pbi afin de simplifier l'accès a les ressources exe qui se trouve soi en courant "exe,dll" ou l ajouter a partir d un external module comme un "exe" ou "dll" ou "cpl" .
ce "inclue" permet de charger les ressource et l utiliser directement a partir de la mémoire pour l afficher dans un gadget comme un image ou faire jouer les sons et les clips avi, ou les sauvegarder en fichier.

-les procédures:
Resource_LoadFromFile()
Resource_FreeLoadFromFile()
Resource_GetAsCursor()
Resource_GetAsIcon()
Resource_GetAsString()
Resource_GetAsImage()
Resource_GetAsBitmap()
Resource_GetAsMemory()
Resource_LoadFont()
Resource_SetImageToGadget()
Resource_PlayAvi()
Resource_PlayWavSond()
Resource_SaveToFile()

la description des paramètres de les procédures se trouvant dans l include.

amusez vous bien :D

exemple

*; vous pouvez télécharger la "dll" utiliser dans l exemple par ici : http://www.mediafire.com/download/69ae4 ... source.rar

Code : Tout sélectionner

XIncludeFile "Pbresources.pbi"

OpenWindow(0, #PB_Ignore, #PB_Ignore, 460, 298, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ButtonGadget(1, 6, 8, 88, 40, "play wav")
ButtonGadget(4, 100, 8, 88, 40, "Sav data")
EditorGadget(2, 220, 62, 228, 138)
ImageGadget(0, 10, 58, 266, 138, 0)
ImageGadget(3, 10, 159, 148, 64, 0)

Global Resource_LoadDataFromFile=Resource_LoadFromFile("Resource.dll")

Resource_SetImageToGadget("ICO_1",GadgetID(4) ,#RT_ICON, Resource_LoadDataFromFile)
SetGadgetText(2,Resource_GetAsString("TXT_1",#PB_Unicode,#RT_RCDATA,0,Resource_LoadDataFromFile))

hgdplusimage = Resource_GetAsImage("JPG_1",#RT_RCDATA, Resource_LoadDataFromFile)
Debug _Gdiplus_GetImageWidth(hgdplusimage)
Debug _Gdiplus_GetImageHeight(hgdplusimage)
GdipDisposeImage_(hgdplusimage)

Resource_SetImageToGadget("JPG_1",GadgetID(3) ,#RT_RCDATA, Resource_LoadDataFromFile)

hbitmap = Resource_GetAsBitmap("BMP_1",#RT_BITMAP, Resource_LoadDataFromFile)
SetGadgetState(0,hbitmap)
DeleteObject_(hbitmap)

hfont=Resource_LoadFont("TTF_1", 0, Resource_LoadDataFromFile)

If LoadFont(0, "SF Square Head", 16)
  SetGadgetFont(2, FontID(0))   
EndIf
;RemoveFontMemResourceEx _(hfont)

hCursor=Resource_GetAsCursor("ANI_CUR_1", Resource_LoadDataFromFile)
SetClassLongPtr_(WindowID(0),#GCL_HCURSOR,hCursor)
; DestroyCursor_(hCursor)

hicon = Resource_GetAsIcon("201",Resource_LoadDataFromFile)
SendMessage_(WindowID(0),#WM_SETICON,#False,hicon) 
; DestroyIcon_(hicon)

Repeat
  Event = WaitWindowEvent()
  
  Select Event

    Case #PB_Event_Gadget
      Select EventGadget()
        Case 4
          Debug "Point resource : " + Str(Resource_GetAsMemory("Bin_1", @Size,0,Resource_LoadDataFromFile))
          Debug "Size resource : " + Str(Size)
        Case 1 
          Resource_PlayWavSond("WAV_1",#SND_ASYNC,Resource_LoadDataFromFile)
      EndSelect
      
  EndSelect
Until Event = #PB_Event_CloseWindow
Resource_FreeLoadFromFile(Resource_LoadDataFromFile)
PbResource.Pbi

Code : Tout sélectionner

;EnableExplicit

;////////////////////////////////////
;          Author Celtic88
;///////////////////////////////////

;Resource Pb include
;https://msdn.microsoft.com/en-us/library/ms632583.aspx

Prototype GdiplusStartup(a,b,c)
Prototype GdipDisposeImage(a)
Prototype GdiplusShutdown(a)
Prototype GdipCreateBitmapFromHBITMAP(a, b, c)
Prototype GdipCreateBitmapFromStream(a, b)
Prototype GdipGetImageEncodersSize(a,b)
Prototype GdipSaveImageToFile(a,b.s,c,d)
Prototype GdipCreateHBITMAPFromBitmap(a, b, c)
Prototype GdipGetImageEncoders(a, b, c)
Prototype GdipCreateBitmapFromHicon(a, b)
Prototype GdipGetImageWidth(a,b)
Prototype GdipGetImageHeight(a,b)
Prototype GdipCloneBitmapArea(a.f,b.f,c.f,d.f,e,f,g)
Global  lib_gdiplus = OpenLibrary(#PB_Any, "GDIPlus.dll") 
Global  GdiplusStartup_.GdiplusStartup=GetFunction(lib_gdiplus,"GdiplusStartup")
Global  GdipDisposeImage_.GdipDisposeImage=GetFunction(lib_gdiplus,"GdipDisposeImage")
Global  GdiplusShutdown_.GdiplusShutdown=GetFunction(lib_gdiplus,"GdiplusShutdown")
Global  GdipCreateBitmapFromHicon_.GdipCreateBitmapFromHicon=GetFunction(lib_gdiplus,"GdipCreateBitmapFromHICON")
Global  GdipCreateBitmapFromHBITMAP_.GdipCreateBitmapFromHBITMAP=GetFunction(lib_gdiplus,"GdipCreateBitmapFromHBITMAP")
Global  GdipCreateBitmapFromStream_.GdipCreateBitmapFromStream=GetFunction(lib_gdiplus,"GdipCreateBitmapFromStream")
Global  GdipCreateHBITMAPFromBitmap_.GdipCreateHBITMAPFromBitmap=GetFunction(lib_gdiplus,"GdipCreateHBITMAPFromBitmap")
Global  GdipGetImageEncodersSize_.GdipGetImageEncodersSize=GetFunction(lib_gdiplus,"GdipGetImageEncodersSize")
Global  GdipSaveImageToFile_.GdipSaveImageToFile=GetFunction(lib_gdiplus,"GdipSaveImageToFile")
Global  GdipDisposeImage_.GdipDisposeImage=GetFunction(lib_gdiplus,"GdipDisposeImage")
Global  GdipGetImageEncoders_.GdipGetImageEncoders=GetFunction(lib_gdiplus,"GdipGetImageEncoders")
Global  GdipCloneBitmapArea_.GdipCloneBitmapArea=GetFunction(lib_gdiplus,"GdipCloneBitmapArea")
Global  GdipGetImageWidth_.GdipGetImageWidth=GetFunction(lib_gdiplus,"GdipGetImageWidth")
Global  GdipGetImageHeight_.GdipGetImageHeight=GetFunction(lib_gdiplus,"GdipGetImageHeight")

;///////////////////// Gdiplus Structure //////////////
Structure GdiplusStartupInput 
  GdiPlusVersion.l 
  *EventCallback._EVENT
  SuppressBackgroundThread.l 
  SuppressExternalCodecs.l 
EndStructure 
Structure EncoderParameter
  Guid.GUID
  NumberOfValues.l
  Type.l
  *Value
EndStructure
Structure EncoderParameters
  Count.l
  Parameter.EncoderParameter[1]
EndStructure
Structure ImageCodecInfo
  clsid.CLSID
  formatID.GUID
  *codecName
  *dllName
  *formatDescription
  *filenameExtension
  *mimeType
  flags.l
  version.l
  sigCount.l
  sigSize.l
  *sigPattern
  *sigMask
EndStructure

;Initialize Microsoft Windows GDI+
; Return values .: Success      - True
;                  Failure      - False
Procedure.b _Gdiplus_Startup()
  Protected GdiplusStartupInput.GdiplusStartupInput\GdiPlusVersion=1
  Protected *token
  ProcedureReturn Bool(GdiplusStartup_(@*token, @GdiplusStartupInput,0)=0)
EndProcedure
Procedure _Gdiplus_GetImageWidth(hImage)
  Protected xw:GdipGetImageWidth_(hImage,@xw):ProcedureReturn xw
EndProcedure
Procedure _Gdiplus_GetImageHeight(hImage)
  Protected xy:GdipGetImageHeight_(hImage,@xy):ProcedureReturn xy
EndProcedure

;///////////////////// Resource info Structure //////////////
Structure Resource_info
  *pResourceData
  SizeResource.i
EndStructure

_Gdiplus_Startup() ; Start GDI+.

#RT_ENHMETAFILE = 1001

Global hInstanceLocalmodule ; Save local Module Handle

Procedure IsNumeric(t$) ; <==== by PB here : http://www.purebasic.fr/english/viewtopic.php?t=16668
  Protected ok,p,a
  ok=1 : t$=Trim(t$)
  For p=1 To Len(t$)
    a=Asc(Mid(t$,p,1))
    If a<>45 And a<>46 And (a<48 Or a>57) : ok=0 : Break : EndIf
  Next
  ProcedureReturn ok
EndProcedure

Procedure.s MAKEINTRESOURCE(int) 
  ProcedureReturn "#" + Str(int)
EndProcedure

;Loads the specified module As Datafile
;Parameters : FilePath.s = Full path of Library
;Return values .: Success      - return handle to the loaded module.
;                  Failure      - False
Procedure Resource_LoadFromFile(FilePath.s)
  ProcedureReturn LoadLibraryEx_(FilePath, 0,#LOAD_LIBRARY_AS_DATAFILE)
EndProcedure

;Frees the loaded module
;Parameters : hInstance_DATAFILE = A handle to the loaded library given by Resource_LoadFromFile()
Procedure Resource_FreeLoadFromFile(hInstance_DATAFILE)
  ProcedureReturn FreeLibrary_(hInstance_DATAFILE)
EndProcedure

;internal procedure
Procedure Resource_GetCurhInstance(hInstance_DATAFILE)
  Protected hInstance=hInstance_DATAFILE
  If hInstance = 0
    If Not hInstanceLocalmodule
      hInstanceLocalmodule=GetModuleHandle_(0)
    EndIf
    hInstance=hInstanceLocalmodule
  EndIf
  ProcedureReturn hInstance
EndProcedure

;internal procedure
;Get specified resource 
;Parameters : ResnameOrID.s = id or name of resource file 
;             *Resource_info.Resource_info = point to Resource_info to get :\
;             \pResourceData = point to image or file 
;             \SizeResource = size of file
;             ResType = The resource type. default : #RT_RCDATA
;             ResLang = The language of the resource.  default : LANG_NEUTRAL
;             hInstance_DATAFILE = A handle to the loaded library module. default : -Get resource form current processes
;             GetAsRaw = specified the resource type if is not standard types.  default : Nul => the resource is standard types
;Return values .: Success      - True
;                  Failure      - False
Procedure.b Resource_Get(ResnameOrID.s, *Resource_info.Resource_info,ResType = #RT_RCDATA, ResLang = 0, hInstance_DATAFILE=0,GetAsRaw.s="")
  Protected hInstance=Resource_GetCurhInstance(hInstance_DATAFILE)
  Protected IMAGEType=-99
  If IsNumeric(ResnameOrID)
    ResnameOrID=MAKEINTRESOURCE(Val(ResnameOrID))
  EndIf
  If GetAsRaw <> ""
    If IsNumeric(GetAsRaw)
      Protected mkres.s=MAKEINTRESOURCE(Val(GetAsRaw))
      ResType=@mkres
    Else
      ResType=@GetAsRaw
    EndIf
  EndIf
  If hInstance 
    Select ResType
      Case #RT_ANICURSOR, #RT_CURSOR
        IMAGEType=#IMAGE_CURSOR
      Case #RT_BITMAP
        IMAGEType=#IMAGE_BITMAP
      Case #RT_ICON
        IMAGEType=#IMAGE_ICON
      Default
        Protected InfoBlock
        If ResLang 
          InfoBlock = FindResourceEx_(hInstance,ResType,ResnameOrID,ResLang)
        Else
          InfoBlock = FindResource_(hInstance,ResnameOrID,ResType)
        EndIf
        If InfoBlock
          Protected ResSize =SizeofResource_(hInstance,InfoBlock)
          If ResSize
            Protected GlobalMemoryBlock =LoadResource_(hInstance,InfoBlock)
            If GlobalMemoryBlock
              *Resource_info\SizeResource =ResSize
              *Resource_info\pResourceData =LockResource_(GlobalMemoryBlock)
            EndIf
          EndIf
        EndIf
    EndSelect
  EndIf
  If IMAGEType <> -99
    *Resource_info\pResourceData =LoadImage_(hInstance,ResnameOrID,IMAGEType,0,0,0)
  EndIf
  If *Resource_info\pResourceData
    ProcedureReturn  1
  EndIf
EndProcedure

;Get a resource as a cursor handle
;Parameters : ResnameOrID.s = id or name of resource file 
;             hInstance_DATAFILE = A handle to the loaded library module. default : Get resource form current processes
;Return values .: Success      - return handle to hCursor.
;                  Failure      - False
Procedure Resource_GetAsCursor(ResnameOrID.s,hInstance_DATAFILE=0)
  Protected Resource_info.Resource_info
  If Resource_Get(ResnameOrID, @Resource_info,#RT_CURSOR , 0, hInstance_DATAFILE)
    ProcedureReturn Resource_info\pResourceData
  EndIf
EndProcedure

;Get a resource as an icon handle
;Parameters : ResnameOrID.s = id or name of resource file 
;             hInstance_DATAFILE = A handle to the loaded library. default : Get resource form current processes
;Return values .: Success      - return handle to hIcon.
;                  Failure      - False
Procedure Resource_GetAsIcon(ResnameOrID.s,hInstance_DATAFILE=0)
  Protected Resource_info.Resource_info
  If Resource_Get(ResnameOrID, @Resource_info,#RT_ICON, 0, hInstance_DATAFILE)
    ProcedureReturn Resource_info\pResourceData
  EndIf
EndProcedure

;Load a font resource into the memory of the specified module
;Parameters : ResnameOrID.s = id or name of resource file 
;             ResLang = The language of the resource.  default : LANG_NEUTRAL
;             hInstance_DATAFILE = A handle to the loaded library module. default : Get resource form current processes
;Return values .: Success      - return handle to hFont.
;                  Failure      - False
Procedure Resource_LoadFont(ResnameOrID.s, ResLang = 0,hInstance_DATAFILE=0)
  Protected Resource_info.Resource_info
  If Resource_Get(ResnameOrID, @Resource_info,#RT_FONT , 0, hInstance_DATAFILE)
    Protected hFont=1
    ProcedureReturn AddFontMemResourceEx_(Resource_info\pResourceData,Resource_info\SizeResource,0,@hFont)
  EndIf
EndProcedure

;Get a resources Memory point
;Parameters : ResnameOrID.s = id or name of resource file 
;             *ByvalResSize = point to integer variable to get size of resource file. default : Nul
;             ResLang = The language of the resource.  default : LANG_NEUTRAL
;             hInstance_DATAFILE = A handle to the loaded library module. default : Get resource form current processes
;             GetAsRaw = specified the resource type if is not standard types.  default : Nul => the resource is standard types
;Return values .: Success      - return point of memory.
;                  Failure      - False
Procedure Resource_GetAsMemory(ResnameOrID.s, *ByvalResSize=0,ResLang = 0,hInstance_DATAFILE=0,GetAsRaw.s="")
  Protected Resource_info.Resource_info
  If Resource_Get(ResnameOrID, @Resource_info,#RT_RCDATA , 0, hInstance_DATAFILE,GetAsRaw)
  If *ByvalResSize
    PokeI(*ByvalResSize,Resource_info\SizeResource)
	EndIf
    ProcedureReturn Resource_info\pResourceData
  EndIf
EndProcedure

;Get a resource as a string
;Parameters : ResnameOrID.s = id or name of resource file 
;             Stringformat = String format
;             ResType = The resource type. default : #RT_RCDATA
;             ResLang = The language of the resource.  default : LANG_NEUTRAL
;             hInstance_DATAFILE = A handle to the loaded library module. default : Get resource form current processes
;             GetAsRaw = specified the resource type if is not standard types.  default : Nul => the resource is standard types
;Return values .: Success      - return String.
;                  Failure      - False
Procedure.s Resource_GetAsString(ResnameOrID.s,Stringformat=#PB_Ascii ,ResType = #RT_RCDATA, ResLang = 0, hInstance_DATAFILE=0,GetAsRaw.s="")
  If  ResType = #RT_STRING
    Protected hInstance=Resource_GetCurhInstance(hInstance_DATAFILE)
    Protected LoadString.s=Space(4096)
    If LoadString_(hInstance,Val(ResnameOrID),@LoadString,4096)
      ProcedureReturn LoadString
    EndIf
  Else
    Protected Resource_info.Resource_info
    If Resource_Get(ResnameOrID, @Resource_info,ResType , ResLang, hInstance_DATAFILE,GetAsRaw)
      ProcedureReturn PeekS(Resource_info\pResourceData,-1,Stringformat)
    EndIf
  EndIf
EndProcedure

;Get a resource as a GdipBitmap handle
;Parameters : ResnameOrID.s = id or name of resource file 
;             ResType = The resource type. default : #RT_RCDATA
;             hInstance_DATAFILE = A handle to the loaded library module. default : Get resource form current processes
;             GetAsRaw = specified the resource type if is not standard types.  default : Nul => the resource is standard types
;Return values .: Success      - return handle to Gdipbitmap.
;                  Failure      - False
Procedure Resource_GetAsImage(ResnameOrID.s,ResType = #RT_RCDATA, hInstance_DATAFILE=0,GetAsRaw.s="")
  Protected Resource_info.Resource_info,hImage
  If Resource_Get(ResnameOrID, @Resource_info,ResType , 0, hInstance_DATAFILE,GetAsRaw)
    Select ResType 
      Case #RT_BITMAP 
        GdipCreateBitmapFromHBITMAP_(Resource_info\pResourceData,0,@hImage)
        DeleteObject_(Resource_info\pResourceData)
      Case #RT_ICON
        ;GdipCreateBitmapFromHicon_(Resource_info\pResourceData,@hImage)
        ;DeleteObject_(Resource_info\pResourceData)
      Case #RT_RCDATA
        Protected hData=GlobalAlloc_(#GMEM_MOVEABLE,Resource_info\SizeResource)
        If hData
          Protected pData=GlobalLock_(hData)
          CopyMemory(Resource_info\pResourceData,pData,Resource_info\SizeResource)
          GlobalUnlock_(hData)
          Protected pStream
          CreateStreamOnHGlobal_(hData,1,@pStream)
          If pStream
            GdipCreateBitmapFromStream_(pStream,@hImage)
             DispCallFunc_(pStream,8 + 8 * Bool(#PB_Processor_x64=#PB_Compiler_Processor),4,23,0,0,0,@"") ;< ===== crach!!
          EndIf
          GlobalFree_(hData)
        EndIf
    EndSelect
    ProcedureReturn hImage
  EndIf
EndProcedure

;Get an image resource as a HBITMAP handle
;Parameters : ResnameOrID.s = id or name of resource file 
;             ResType = The resource type. default : #RT_RCDATA
;             hInstance_DATAFILE = A handle to the loaded library module. default : Get resource form current processes
;             GetAsRaw = specified the resource type if is not standard types.  default : Nul => the resource is standard types
;Return values .: Success      - return handle to Bitmap.
;                  Failure      - False
Procedure Resource_GetAsBitmap(ResnameOrID.s,ResType = #RT_RCDATA, hInstance_DATAFILE=0,GetAsRaw.s="")
  Protected hImage = Resource_GetAsImage(ResnameOrID,ResType , hInstance_DATAFILE,GetAsRaw)
  Protected hBitmap
  If hImage
    GdipCreateHBITMAPFromBitmap_(hImage,@hBitmap,$FF000000)
    GdipDisposeImage_(hImage)
  EndIf
  ProcedureReturn hBitmap
EndProcedure

;internal procedure
Procedure _GDIPlus_ImageSaveToFile(hImage, sFileName.s,imageQuality.l=100) ; <== current support only JPG;JPEG and bmp image format
  Protected encoderparams.EncoderParameters ,EncPar
  Protected.s Extension = GetExtensionPart(sFileName),EncExtension
  
  If   FindString("JPG;JPEG",Extension,1,#PB_String_NoCase)  > 0
    With encoderparams.EncoderParameters
      \Count = 1
      \Parameter[0]\Type = 4
      \Parameter[0]\NumberOfValues = 1
      \parameter[0]\Value = @imageQuality
    EndWith
    CopyMemory(?clsid_EncoderQuality, encoderparams\parameter[0]\Guid, SizeOf(GUID))
    EncPar=@encoderparams
  Else
    Protected NewGdipBitmap
    #GDIP_PXF24RGB = $00021808
    GdipCloneBitmapArea_(0,0,_Gdiplus_GetImageWidth(hImage),_Gdiplus_GetImageHeight(hImage),#GDIP_PXF24RGB,hImage,@NewGdipBitmap)
    GdipDisposeImage_(hImage)
    hImage = NewGdipBitmap
  EndIf
  
  Protected Encount,Encsize,ic
  GdipGetImageEncodersSize_(@Encount,@Encsize)
  Protected CodecCount = Encsize / SizeOf(ImageCodecInfo)
  Protected Dim tinfo.ImageCodecInfo(CodecCount-1 )
  GdipGetImageEncoders_(Encount,Encsize,@tinfo())
  For ic=0 To Encount-1  
    EncExtension = PeekS(tinfo(ic)\filenameExtension, -1, #PB_Unicode)  
    If FindString( EncExtension,Extension,1,#PB_String_NoCase)  > 0 :Break:EndIf
  Next
  
  ProcedureReturn Bool(GdipSaveImageToFile_(hImage,sFileName,tinfo(ic)\clsid,EncPar) = 0)
EndProcedure

;Save a resource to a file
;Parameters : ResnameOrID.s = id or name of resource file 
;             SavePath.s = Path to save resource file 
;             ResType = The resource type. default : #RT_RCDATA
;             ResLang = The language of the resource.  default : LANG_NEUTRAL
;             hInstance_DATAFILE = A handle to the loaded library module. default : Get resource form current processes
;             GetAsRaw = specified the resource type if is not standard types.  default : Nul => the resource is standard types
;Return values .: Success      - True
;                  Failure      - False
Procedure Resource_SaveToFile(ResnameOrID.s,SavePath.s ,ResType = #RT_RCDATA, ResLang = 0, hInstance_DATAFILE=0,GetAsRaw.s="")
  Protected Resource_info.Resource_info,WriteSize
  Select  ResType
    Case #RT_BITMAP
      Protected hImage = Resource_GetAsImage(ResnameOrID,ResType , hInstance_DATAFILE)
      If hImage
        If _GDIPlus_ImageSaveToFile(hImage, SavePath)
          WriteSize=1
        EndIf
        GdipDisposeImage_(hImage)
      EndIf
    Default
      If ResType = #RT_RCDATA Or GetAsRaw <> ""
        If Resource_Get(ResnameOrID, @Resource_info,ResType , ResLang, hInstance_DATAFILE,GetAsRaw)
          Protected ROpenFile=CreateFile(#PB_Any,SavePath)
          If  ROpenFile
            WriteSize=WriteData(ROpenFile,Resource_info\pResourceData,Resource_info\SizeResource)
            CloseFile(ROpenFile)
          EndIf
        EndIf
      EndIf
  EndSelect
  ProcedureReturn WriteSize
EndProcedure

;internal procedure
Procedure Window_Add_Style(Hwnd,Isteyle)
  Protected Getstyle = GetWindowLong_(Hwnd, #GWL_STYLE)
  If (Getstyle& Isteyle) <> Isteyle
    SetWindowLong_(Hwnd, #GWL_STYLE, Getstyle | Isteyle)
  EndIf
EndProcedure

;internal procedure
Procedure Control_SetBitmap(ControlId ,hBitmap,ResType)
  Protected iMsg_Set, iStyle, wParam
  Protected Clsname.s=Space(256)
  GetClassName_(ControlId,@Clsname,255)
  Select Clsname
    Case "Button"
      iMsg_Set=#BM_SETIMAGE
      If ResType = #RT_BITMAP Or ResType = #RT_RCDATA
        iStyle = #BS_BITMAP
        wParam = #IMAGE_BITMAP
      ElseIf  ResType = #RT_ICON
        iStyle = #BS_ICON
        wParam = #IMAGE_ICON
      Else
        ProcedureReturn
      EndIf
    Case "Static"
      iMsg_Set = #STM_SETIMAGE
      Select ResType
        Case #RT_BITMAP,#RT_RCDATA
          iStyle = #SS_BITMAP
          wParam = #IMAGE_BITMAP
        Case #RT_CURSOR
          iStyle = #SS_ICON
          wParam = #IMAGE_CURSOR
        Case #RT_ENHMETAFILE
          iStyle = #SS_ENHMETAFILE
          wParam = #IMAGE_ENHMETAFILE
        Case #RT_ICON
          iStyle = #SS_ICON
          wParam = #IMAGE_ICON
        Default
          ProcedureReturn
      EndSelect
    Default
      ProcedureReturn
  EndSelect
  
  Window_Add_Style(ControlId,iStyle)
  
  Protected hPrev=SendMessage_(ControlId, iMsg_Set, wParam, hBitmap)
  If hPrev
    DeleteObject_(hPrev)
  EndIf
  ProcedureReturn 1
EndProcedure

;Set a Image handle to gadgetid
;Parameters : ResnameOrID.s = id or name of resource file 
;             ControlId = hwnd to gadget !gadgetid()
;             ResType = The resource type. default : #RT_RCDATA
;             hInstance_DATAFILE = A handle to the loaded library module. default : Get resource form current processes
;             GetAsRaw = specified the resource type if is not standard types.  default : Nul => the resource is standard types
;Return values .: Success      - True
;                  Failure      - False
Procedure Resource_SetImageToGadget(ResnameOrID.s,ControlId ,ResType = #RT_RCDATA, hInstance_DATAFILE=0,GetAsRaw.s="")
  Protected iReturn
  If ResType=#RT_BITMAP Or ResType=#RT_RCDATA Or GetAsRaw <> ""
    Protected hBitmap = Resource_GetAsBitmap(ResnameOrID,ResType, hInstance_DATAFILE,GetAsRaw)
    If hBitmap
      If Control_SetBitmap(ControlId ,hBitmap,ResType)
        iReturn=1
      Else
        DeleteObject_(hBitmap)
      EndIf
    EndIf
  Else
    Select ResType
      Case #RT_ICON,#RT_CURSOR,#RT_ENHMETAFILE
        Protected Resource_info.Resource_info,hImage
        If Resource_Get(ResnameOrID, @Resource_info,ResType , 0, hInstance_DATAFILE)
          If Control_SetBitmap(ControlId ,Resource_info\pResourceData,ResType)
            iReturn=1
          Else
            DeleteObject_(Resource_info\pResourceData)
          EndIf
        EndIf
    EndSelect
  EndIf
  ProcedureReturn iReturn
EndProcedure

;Load (play) a Avi resource
;Parameters : ResnameOrID.s = id or name of resource file 
;             HwndAvi = Flags for playing the sound
;             hInstance_DATAFILE = A handle to the loaded library module. default : Get resource form current processes
;Return values .: Success      - True
;                  Failure      - False
Procedure Resource_PlayAvi(ResnameOrID.s,HwndAvi, hInstance_DATAFILE=0)
  Protected iRet
  Protected hInstance=Resource_GetCurhInstance(hInstance_DATAFILE)
  If hInstance 
    ;https://msdn.microsoft.com/en-us/library/windows/desktop/ff485879(v=vs.85).aspx
    iRet=SendMessage_(HwndAvi, #ACM_OPEN, hInstance, Val(ResnameOrID))
    If iRet
      SendMessage_(HwndAvi, #ACM_PLAY, 1, 0)
    EndIf
  EndIf
  ProcedureReturn iRet
EndProcedure

;Load (play) a sound resource
;Parameters : ResnameOrID.s = id or name of resource file 
;             Flag = Flags for playing the sound
;             hInstance_DATAFILE = A handle to the loaded library module. default : Get resource form current processes
;Return values .: Success      - True
;                  Failure      - False
Procedure Resource_PlayWavSond(ResnameOrID.s,Flag = 0, hInstance_DATAFILE=0)
  Protected iPlaySound
  Protected hInstance=Resource_GetCurhInstance(hInstance_DATAFILE)
  If hInstance 
    ;https://msdn.microsoft.com/en-us/library/windows/desktop/dd743680(v=vs.85).aspx
    iPlaySound=PlaySound_(ResnameOrID,hInstance,#SND_RESOURCE|Flag)
  EndIf
  ProcedureReturn iPlaySound
EndProcedure

DataSection
  clsid_EncoderQuality:
  Data.l $1D5BE4B5
  Data.w $FA4A
  Data.w $452D
  Data.b $9C,$DD,$5D,$B3,$51,$05,$E7,$EB
EndDataSection
.....i Love Pb :)
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: Purebasic Resources.pbi mise a jour v0.3

Message par celtic88 »

mise a jour v0.3

-error corriger : "DispCallFunc_(pStream,8 + 8 * Bool(#PB_Processor_x64=#PB_Compiler_Processor),4,23,0,0,0,@"")"

-ajoute des ressources de type non standard.
.....i Love Pb :)
Avatar de l’utilisateur
Kwai chang caine
Messages : 6989
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: Purebasic Resources.pbi mise a jour v0.3

Message par Kwai chang caine »

Cool le petit cheval rouge !!!! :mrgreen:
Et ben, encore un code de fou 8O
Merci de ce partage 8)
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Répondre