Sign in to follow this  
Followers 0
wolf9228

Resource project Second Version

11 posts in this topic

#1 ·  Posted (edited)

The project contains advanced functionality to use a resource for executable files and DLL files
It also supports multiple formats for image files using the
OleAut32.dll library

Cp_Wz_006.png

project Files

Resource.zip

New Project Files

New_Resource.zip

Error in this section

Switch $ResType

Case $RT_BITMAP
$hImage = LoadBitmap($ResName,$ModuleName)
if @error Then Return SetError(1,0,0)
Return SetError(0,1,$hImage)

Case $RT_ICON
$hImage = LoadIcon($ResName,$ModuleName)
if @error Then Return SetError(2,0,0)
Return SetError(0,3,$hImage)

Case $RT_CURSOR
$hImage = LoadCursor($ResName,$ModuleName)
if @error Then Return SetError(3,0,0)
Return SetError(0,5,$hImage)
 

 

The correct code

Switch $ResType

Case $RT_BITMAP
$hImage = LoadBitmap($ResName,$ModuleName)
if @error Then Return SetError(1,0,0)
Return SetError(0,1,$hImage)

Case $RT_GROUP_ICON
$hImage = LoadIcon($ResName,$ModuleName)
if @error Then Return SetError(2,0,0)
Return SetError(0,3,$hImage)

Case $RT_GROUP_CURSOR
$hImage = LoadCursor($ResName,$ModuleName)
if @error Then Return SetError(3,0,0)
Return SetError(0,5,$hImage)
 

 

Resource.au3

#include <Constants.au3>
#include <WinAPI.au3>
#include <Memory.au3>

Global Const $RT_ACCELERATOR = 9
Global Const $RT_ANICURSOR = 21
Global Const $RT_ANIICON = 22
Global Const $RT_BITMAP = 2
Global Const $RT_CURSOR = 1
Global Const $RT_DIALOG = 5
Global Const $RT_DLGINCLUDE = 17
Global Const $RT_FONT = 8
Global Const $RT_FONTDIR = 7
Global Const $RT_GROUP_CURSOR = ($RT_CURSOR + 11)
Global Const $RT_ICON = 3
Global Const $RT_GROUP_ICON = ($RT_ICON + 11)
Global Const $RT_HTML = 23
Global Const $RT_MANIFEST = 24
Global Const $RT_MENU = 4
Global Const $RT_MESSAGETABLE = 11
Global Const $RT_PLUGPLAY = 19
Global Const $RT_RCDATA = 10
Global Const $RT_STRING = 6
Global Const $RT_VERSION = 16
Global Const $RT_VXD = 20

Func ResGet($ResType,$ResName,$ResLanguage = -1,$ModuleName = "")

Local $DataType1 = "LONG",$DataType2 = "LONG"
Local $LPVOID,$HRSRC,$ResSize,$HGLOBAL


if IsString($ResName) Then
$ResName = StringUpper($ResName)
$DataType1 = "WSTR"
EndIf
If IsString($ResType) Then
$ResType = StringUpper($ResType)
$DataType2 = "WSTR"
EndIf

if StringLen($ModuleName) Then
$HModule = _WinAPI_LoadLibraryEx($ModuleName,$LOAD_LIBRARY_AS_DATAFILE)
if $HModule = 0 Then Return SetError(1,0,0)
Else
$HModule = 0
EndIf

if ($ResLanguage <> -1) Then
$HRSRC = DllCall("Kernel32.dll","ptr","FindResourceExW","ptr",$HModule, _
$DataType2,$ResType,$DataType1,$ResName,"WORD",$ResLanguage)
if @error Or $HRSRC[0] = 0 Then Return SetError(2,0,0)
Else
$HRSRC = DllCall("Kernel32.dll","ptr","FindResourceW","ptr",$HModule, _
$DataType1,$ResName,$DataType2,$ResType)
if @error Or $HRSRC[0] = 0 Then Return SetError(2,0,0)
EndIf

$HRSRC = $HRSRC[0]
$ResSize = DllCall("Kernel32.dll","DWORD","SizeofResource","ptr",$HModule,"ptr",$HRSRC)
if (@error Or $ResSize[0] = 0) Then Return SetError(3,0,0)
$ResSize = $ResSize[0]

$HGLOBAL = DllCall("Kernel32.dll","ptr","LoadResource","ptr",$HModule,"ptr",$HRSRC)
if @error Or $HGLOBAL[0] = 0 Then Return SetError(4,0,0)
$HGLOBAL = $HGLOBAL[0]

$LPVOID = DllCall("Kernel32.dll","ptr","LockResource","ptr",$HGLOBAL)
if @error Or $LPVOID[0] = 0 Then
$BOOL = DllCall("Kernel32.dll","BOOL","FreeResource","ptr",$HGLOBAL)
Return SetError(5,0,0)
EndIf
$LPVOID = $LPVOID[0]

$ByteStruct = DllStructCreate("BYTE[" & $ResSize & "]")
_MemMoveMemory($LPVOID,DllStructGetPtr($ByteStruct),$ResSize)

$BOOL = DllCall("Kernel32.dll","BOOL","FreeResource","ptr",$HGLOBAL)
if ($HModule) Then _WinAPI_FreeLibrary($HModule)

Return SetError(0,$ResSize,$ByteStruct)

EndFunc

Func ResToFile($FileName,$ResType,$ResName,$ResLanguage = -1,$ModuleName = "",$Mode = 10)

$ByteStruct = ResGet($ResType,$ResName,$ResLanguage,$ModuleName)
if @error Then Return SetError(1,0,False)

$OpeFile = FileOpen($FileName,$Mode)
if @error Then Return SetError(2,0,False)

FileWrite($OpeFile,Binary(DllStructGetData($ByteStruct,1)))
if @error Then Return SetError(3,0,False)

FileClose($OpeFile)
Return SetError(0,0,True)

EndFunc

Func StringResGet($ResType,$ResName,$ResLanguage = -1,$Unicode = False,$ModuleName = "")

Local $DtatType = "CHAR"

$ByteStruct = ResGet($ResType,$ResName,$ResLanguage,$ModuleName)
if @error Then Return SetError(1,0,0)
$ResSize = @extended
$LPVOID = DllStructGetPtr($ByteStruct)

if ($Unicode) Then
$DtatType = "WCHAR"
$ResSize = Int($ResSize/2)
EndIf

$StrStruct = DllStructCreate($DtatType & "[" & $ResSize & "]",$LPVOID)
if @error Then Return SetError(2,0,0)

$nString = DllStructGetData($StrStruct,1)
Return SetError(0,StringLen($nString),$nString)

EndFunc


Func ResGetImage($ResType,$ResName,$ResLanguage = -1,$ModuleName = "")

Switch $ResType

Case $RT_BITMAP
$hImage = LoadBitmap($ResName,$ModuleName)
if @error Then Return SetError(1,0,0)
Return SetError(0,1,$hImage)

Case $RT_GROUP_ICON
$hImage = LoadIcon($ResName,$ModuleName)
if @error Then Return SetError(2,0,0)
Return SetError(0,3,$hImage)

Case $RT_GROUP_CURSOR
$hImage = LoadCursor($ResName,$ModuleName)
if @error Then Return SetError(3,0,0)
Return SetError(0,5,$hImage)

Case Else

$ByteStruct = ResGet($ResType,$ResName,$ResLanguage,$ModuleName)
if @error Then Return SetError(4,0,0)
$ResSize = @extended

$hMemory = _MemGlobalAlloc($ResSize,$GHND)
if Not($hMemory) Then Return SetError(5,0,0)

$hLock = _MemGlobalLock($hMemory)
if Not($hLock) Then
_MemGlobalFree($hMemory)
Return SetError(6,0,0)
EndIf

_MemMoveMemory(DllStructGetPtr($ByteStruct),$hLock,$ResSize)

$lpstream = CreateStreamOnHGlobal($hLock,True)
if @error Then
_MemGlobalFree($hMemory)
Return SetError(7,0,0)
EndIf

$riid = _WinAPI_GUIDFromString("{7BF80981-BF32-101A-8BBB-00AA00300CAB}")
if @error Then
_MemGlobalFree($hMemory)
Return SetError(8,0,0)
EndIf


$HRESULT = DllCall("OleAut32.dll","LONG","OleLoadPicture","PTR",$lpstream,"LONG", _
$ResSize,"BOOL",True,"ptr",DllStructGetPtr($riid),"idispatch*",0)
if @error Or $HRESULT[0] <> 0 Then
_MemGlobalFree($hMemory)
Return SetError(9,0,0)
EndIf
$iPicture = $HRESULT[5]

_MemGlobalFree($hMemory)
Return SetError(0,Int($iPicture.Type()),Ptr($iPicture.Handle()))

EndSwitch

;PICTYPE_UNINITIALIZED (-1)
;The picture object is currently uninitialized. This value is only valid as a return value
;from IPicture::get_Type and is not valid with the PICTDESC structure.
;PICTYPE_NONE = 0
;A new picture object is to be created without an initialized state. This
;value is valid only in the PICTDESC structure.
;PICTYPE_BITMAP = 1
;The picture type is a bitmap. When this value occurs in the PICTDESC structure,
;it means that the bmp field of that structure contains the relevant initialization parameters.
;PICTYPE_METAFILE = 2
;The picture type is a metafile. When this value occurs in the PICTDESC structure,
;it means that the wmf field of that structure contains the relevant initialization parameters.
;PICTYPE_ICON = 3
;The picture type is an icon. When this value occurs in the PICTDESC structure,
;it means that the icon field of that structure contains the relevant initialization parameters.
;PICTYPE_ENHMETAFILE = 4
;The picture type is an enhanced metafile. When this value occurs in the PICTDESC structure,
;it means that the emf field of that structure contains the relevant initialization parameters.

EndFunc


Func LoadBitmap($lpBitmapName,$ModuleName = "")

Local $DataType = "LONG" , $TestModule = StringLen($ModuleName) <> 0

if ($TestModule) Then
$HModule = _WinAPI_LoadLibraryEx($ModuleName,$LOAD_LIBRARY_AS_DATAFILE)
if $HModule = 0 Then Return SetError(1,0,0)
Else
$HModule = _WinAPI_GetModuleHandle(0)
EndIf

if IsString($lpBitmapName) Then
$lpBitmapName = StringUpper($lpBitmapName)
$DataType = "WSTR"
EndIf

$HBITMAP = DllCall("User32.dll","PTR","LoadBitmapW","PTR",$HModule,$DataType,$lpBitmapName)
if @error Or $HBITMAP[0] = 0 Then
if ($TestModule) Then _WinAPI_FreeLibrary($HModule)
Return SetError(2,0,0)
EndIf

if ($TestModule) Then _WinAPI_FreeLibrary($HModule)
Return SetError(0,0,$HBITMAP[0])

EndFunc

Func LoadIcon($lpIconName,$ModuleName = "")

Local $DataType = "LONG" , $TestModule = StringLen($ModuleName) <> 0

if ($TestModule) Then
$HModule = _WinAPI_LoadLibraryEx($ModuleName,$LOAD_LIBRARY_AS_DATAFILE)
if $HModule = 0 Then Return SetError(1,0,0)
Else
$HModule = _WinAPI_GetModuleHandle(0)
EndIf

if IsString($lpIconName) Then
$lpIconName = StringUpper($lpIconName)
$DataType = "WSTR"
EndIf

$HICON = DllCall("User32.dll","PTR","LoadIconW","PTR",$HModule,$DataType,$lpIconName)
if @error Or $HICON[0] = 0 Then
if ($TestModule) Then _WinAPI_FreeLibrary($HModule)
Return SetError(2,0,0)
EndIf

if ($TestModule) Then _WinAPI_FreeLibrary($HModule)
Return SetError(0,0,$HICON[0])

EndFunc

Func LoadCursor($lpCursorName,$ModuleName = "")

Local $DataType = "LONG" , $TestModule = StringLen($ModuleName) <> 0

if ($TestModule) Then
$HModule = _WinAPI_LoadLibraryEx($ModuleName,$LOAD_LIBRARY_AS_DATAFILE)
if $HModule = 0 Then Return SetError(1,0,0)
Else
$HModule = _WinAPI_GetModuleHandle(0)
EndIf

if IsString($lpCursorName) Then
$lpCursorName = StringUpper($lpCursorName)
$DataType = "WSTR"
EndIf

$HCURSOR= DllCall("User32.dll","PTR","LoadCursorW","PTR",$HModule,$DataType,$lpCursorName)
if @error Or $HCURSOR[0] = 0 Then
if ($TestModule) Then _WinAPI_FreeLibrary($HModule)
Return SetError(2,0,0)
EndIf

if ($TestModule) Then _WinAPI_FreeLibrary($HModule)
Return SetError(0,0,$HCURSOR[0])

EndFunc

Func CreateStreamOnHGlobal($hGlobal,$fDeleteOnRelease)

$WINOLE = DllCall("Ole32.dll","PTR","CreateStreamOnHGlobal","ptr", _
$hGlobal,"BOOL",$fDeleteOnRelease,"PTR*",0)
if @error Or $WINOLE[0] <> 0 Then Return SetError(1,0,0)
Return SetError(0,0,$WINOLE[3])

EndFunc
 

Res_Ctrl.au3

#include <Constants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Memory.au3>
#include "Resource.au3"

Global $Global_BackGroundArray[4][1]

Func ResCtrlCreatePic($L,$T,$W,$H,$ResType,$ResName, _
$ResLanguage = -1,$ModuleName = "",$Style = 0,$ExStyle = 0)

$ImageHandle = ResGetImage($ResType,$ResName,$ResLanguage,$ModuleName)
if @error Then Return SetError(1,0,0)
$ImageType = @extended

$ControlID = CtrlCreatePic($ImageHandle,$ImageType,$L,$T,$W,$H,$Style,$ExStyle)
if @error Then Return SetError(2,0,0)

Return SetError(0,$ImageType,$ControlID)

EndFunc

Func ResCtrlCreatePicEx($L,$T,$W,$H,$Text,$ResType,$ResName,$ResLanguage = -1, _
$ModuleName = "",$Style = 0,$ExStyle = 0,$FontColor=0,$FontSize=8.5,$FomtWeight=400 _
,$FontAttribute=2,$Fontname="",$FontQuality=2)

$ImageHandle = ResGetImage($ResType,$ResName,$ResLanguage,$ModuleName)
if @error Then Return SetError(1,0,0)
$ImageType = @extended

$ControlID = CtrlCreatePicEx($ImageHandle,$ImageType,$L,$T,$W,$H,$Text,$Style, _
$ExStyle,$FontColor,$FontSize,$FomtWeight,$FontAttribute,$Fontname,$FontQuality)
if @error Then Return SetError(2,0,0)

Return SetError(0,$ImageType,$ControlID)

EndFunc

Func ResCtrlCreate_Button($L,$T,$W,$H,$ResType,$ResName, _
$ResLanguage = -1,$ModuleName = "",$Style = 0,$ExStyle = 0,$ReSize = False)

$ImageHandle = ResGetImage($ResType,$ResName,$ResLanguage,$ModuleName)
if @error Then Return SetError(1,0,0)
$ImageType = @extended

if ($ReSize) Then
$SizeArray = GetImageSize($ImageHandle)
if @error Then
DeleteObj($ImageHandle,$ImageType)
Return SetError(2,0,0)
EndIf
$W = $SizeArray[0]
$H = $SizeArray[1]
EndIf

$ControlID = CtrlCreate_Button($ImageHandle,$ImageType,$L,$T,$W,$H,$Style,$ExStyle)
if @error Then Return SetError(3,0,0)

Return SetError(0,$ImageType,$ControlID)

EndFunc

Func ResSetBackGroundBmp($hWnd,$ResType,$ResName,$ResLanguage = -1 _
,$ModuleName = "",$DeletOldImage = True)

$hImage = ResGetImage($ResType,$ResName,$ResLanguage,$ModuleName)
if @error Then Return SetError(1,0,False)
Local $ImageType = @extended
if ($ImageType <> 1) Then DeleteObj($hImage,$ImageType)

$SizeArray = GetImageSize($hImage)
if @error Then
DeleteObj($hImage,$ImageType)
Return SetError(2,0,False)
EndIf
$BmpWidth = $SizeArray[0]
$BmpHeight = $SizeArray[1]

SetBackGroundBmp($hWnd,$hImage,$BmpWidth,$BmpHeight,$DeletOldImage)
if @error Then
DeleteObj($hImage,$ImageType)
Return SetError(3,0,False)
EndIf

Return SetError(0,0,True)

EndFunc

Func ResSndPlaySound($ResType,$ResName,$ResLanguage = -1,$ModuleName = "",$LOOP = False)
$ByteStruct = ResGet($ResType,$ResName,$ResLanguage,$ModuleName)
if @error Then Return SetError(1,0,False)
$LPVOID = DllStructGetPtr($ByteStruct)
SndPlaySound($LPVOID,$LOOP)
if @error Then Return SetError(2,0,False)
Return SetError(0,0,True)
EndFunc

Func CtrlCreatePic($ImageHandle,$ImageType,$L,$T,$W,$H,$Style = 0,$ExStyle = 0)

Local $SS_ICON_RES = 0x00000003,$SS_ENHMETAFILE_RES = 0x0000000F
Local $SS_BITMAP_RES = 0x0000000E,$SS_REALSIZECONTROL_RES = 0x00000040

Switch $ImageType
Case 1 ;BITMAP
$ImageStyle = BitOR($Style,$SS_BITMAP_RES,$SS_REALSIZECONTROL_RES)
Case 4 ;ENHMETAFILE
$ImageStyle = BitOR($Style,$SS_ENHMETAFILE_RES,$SS_REALSIZECONTROL_RES)
Case 3,5 ;INCON OR CURSOR
$ImageStyle = BitOR($Style,$SS_ICON_RES,$SS_REALSIZECONTROL_RES)
Case Else
Return SetError(1,0,0)
EndSwitch

$ControlID = GUICtrlCreateLabel("",$L,$T,$W,$H,$ImageStyle,$ExStyle)
CtrlSetImage($ControlID,$ImageHandle,$ImageType)
if @error Then Return SetError(2,0,0)
Return SetError(0,$ImageType,$ControlID)

EndFunc

Func CtrlCreatePicEx($ImageHandle,$ImageType,$L,$T,$W,$H,$Text,$Style = 0,$ExStyle = 0, _
$FontColor=0,$FontSize=8.5,$FomtWeight=400,$FontAttribute=0,$Fontname="",$FontQuality=2)

Local $SS_BITMAP_RES = 0x0000000E,$SS_REALSIZECONTROL_RES = 0x00000040
Local $SS_ICON_RES = 0x00000003,$SS_CENTER_RES = 0x01,$SS_CENTERIMAGE_RES = 0x0200
Local $SS_ENHMETAFILE_RES = 0x0000000F

Switch $ImageType
Case 1 ;BITMAP
$ImageStyle = BitOR($Style,$SS_BITMAP_RES,$SS_REALSIZECONTROL_RES)
Case 4 ;ENHMETAFILE
$ImageStyle = BitOR($Style,$SS_ENHMETAFILE_RES,$SS_REALSIZECONTROL_RES)
Case 3,5 ;INCON OR CURSOR
$ImageStyle = BitOR($Style,$SS_ICON_RES,$SS_REALSIZECONTROL_RES)
Case Else
Return SetError(1,0,0)
EndSwitch

$ControlID1 = GUICtrlCreateLabel("",$L,$T,$W,$H,$ImageStyle,$ExStyle)
CtrlSetImage($ControlID1,$ImageHandle,$ImageType)
if @error Then
GUICtrlDelete($ControlID1)
Return SetError(2,0,0)
EndIf

$ControlID2 = GUICtrlCreateLabel($Text,$L,$T,$W,$H,BitOR($SS_CENTER_RES,$SS_CENTERIMAGE_RES))
GUICtrlSetColor(-1,$FontColor)
GUICtrlSetBkColor(-1,-2);-2 $GUI_BKCOLOR_TRANSPARENT
GUICtrlSetFont(-1,$FontSize,$FomtWeight,$FontAttribute,$Fontname,$FontQuality)
Return SetError(0,$ImageType,$ControlID1)

EndFunc

Func DeletePicEx($ControlID)
GUICtrlDelete($ControlID)
GUICtrlDelete($ControlID + 1)
EndFunc

Func SetPosPicEx($ControlID,$L,$T,$W,$H)
GUICtrlSetPos($ControlID,$L,$T,$W,$H)
GUICtrlSetPos($ControlID + 1,$L,$T,$W,$H)
EndFunc

Func SetStatePicEx($ControlID,$State)
GUICtrlSetState($ControlID,$State)
GUICtrlSetState($ControlID + 1,$State)
EndFunc

Func SetStylePicEx($ControlID,$Style,$ExStyle)
GUICtrlSetStyle($ControlID,$Style,$ExStyle)
EndFunc

Func CtrlCreate_Button($ImageHandle,$ImageType,$L,$T,$W,$H,$Style = 0,$ExStyle = 0)

Local $BS_ICON_RES = 0x0040,$BS_BITMAP_RES = 0x0080

Switch $ImageType
Case 1 ;BITMAP
$ImageStyle = BitOR($Style,$BS_BITMAP_RES)
Case 3 ;ICON
$ImageStyle = BitOR($Style,$BS_ICON_RES)
Case Else
Return SetError(1,0,0)
EndSwitch

$ControlID = GUICtrlCreateButton("",$L,$T,$W,$H,$ImageStyle,$ExStyle)
CtrlSetImage($ControlID,$ImageHandle,$ImageType)
if @error Then Return SetError(2,0,0)
Return SetError(0,$ImageType,$ControlID)

EndFunc

Func CtrlSetImage($ControlID,$ImageHandle,$ImageType,$DeletOldImage = False)

;$ImageType
;$ImageType = 1 ==> BITMAP
;$ImageType = 3 ==> ICON
;$ImageType = 4 ==> ENHMETAFILE
;$ImageType = 5 ==> CURSOR
;$ControlID Of STATIC Control Or Button Control

Local $ControHandle = $ControlID,$STM_SETIMAGE_RES = 0x0172,$IMAGE_ENHMETAFILE_RES = 3
Local $IMAGE_BITMAP_RES = 0,$IMAGE_ICON_RES = 1,$IMAGE_CURSOR_RES = 2 , $RthImage = 0
Local $BM_SETIMAGE_RES = 0xF7

if Not IsHWnd($ControlID) Then $ControHandle = GUICtrlGetHandle($ControlID)
Local $Class = _WinAPI_GetClassName($ControHandle)

Select
Case $Class == "Button"
Switch $ImageType
Case 1 ;BITMAP
if ($DeletOldImage) Then $OldImage = CtrlGetOldImage($ControlID)
Local $OldImageType = @extended
$RthImage = _SendMessage($ControHandle,$BM_SETIMAGE_RES,$IMAGE_BITMAP_RES,$ImageHandle)
if ($DeletOldImage And $OldImage <> $ImageHandle _
And $OldImage) Then DeleteObj($OldImage,$OldImageType)
Case 3 ;ICON
if ($DeletOldImage) Then $OldImage = CtrlGetOldImage($ControlID)
Local $OldImageType = @extended
$RthImage = _SendMessage($ControHandle,$BM_SETIMAGE_RES,$IMAGE_ICON_RES,$ImageHandle)
if ($DeletOldImage And $OldImage <> $ImageHandle _
And $OldImage) Then DeleteObj($OldImage,$OldImageType)
Case Else
Return SetError(3,0,False)
EndSwitch
Case $Class == "Static"
Switch $ImageType
Case 1 ;BITMAP
if ($DeletOldImage) Then $OldImage = CtrlGetOldImage($ControlID)
Local $OldImageType = @extended
$RthImage = _SendMessage($ControHandle,$STM_SETIMAGE_RES,$IMAGE_BITMAP_RES,$ImageHandle)
if ($DeletOldImage And $OldImage <> $ImageHandle _
And $OldImage) Then DeleteObj($OldImage,$OldImageType)
Case 4 ;ENHMETAFILE
if ($DeletOldImage) Then $OldImage = CtrlGetOldImage($ControlID)
Local $OldImageType = @extended
$RthImage = _SendMessage($ControHandle,$STM_SETIMAGE_RES,$IMAGE_ENHMETAFILE_RES,$ImageHandle)
if ($DeletOldImage And $OldImage <> $ImageHandle _
And $OldImage) Then DeleteObj($OldImage,$OldImageType)
Case 3 ;ICON
if ($DeletOldImage) Then $OldImage = CtrlGetOldImage($ControlID)
Local $OldImageType = @extended
$RthImage = _SendMessage($ControHandle,$STM_SETIMAGE_RES,$IMAGE_ICON_RES,$ImageHandle)
if ($DeletOldImage And $OldImage <> $ImageHandle _
And $OldImage) Then DeleteObj($OldImage,$OldImageType)
Case 5 ;CURSOR
if ($DeletOldImage) Then $OldImage = CtrlGetOldImage($ControlID)
Local $OldImageType = @extended
$RthImage = _SendMessage($ControHandle,$STM_SETIMAGE_RES,$IMAGE_CURSOR_RES,$ImageHandle)
if ($DeletOldImage And $OldImage <> $ImageHandle _
And $OldImage) Then DeleteObj($OldImage,$OldImageType)
Case Else
Return SetError(3,0,False)
EndSwitch
if IsHWnd($ControlID) Then $ControlID = _WinAPI_GetDlgCtrlID($ControlID)
$ControHandle = GUICtrlGetHandle($ControlID + 1)
if ($ControHandle) Then _WinAPI_RedrawWindow($ControHandle,0,0,$RDW_INVALIDATE)
Case Else
Return SetError(2,0,False)
EndSelect

if ($RthImage) Then DeleteObj($RthImage,$ImageType)
Return SetError(0,0,True)

EndFunc

Func CtrlGetOldImage($ControlID)

; Return $OldImage Or Zero
;$ImageType = @extended
;$ImageType = 1 ==> BITMAP
;$ImageType = 3 ==> ICON
;$ImageType = 4 ==> ENHMETAFILE
;$ImageType = 5 ==> CURSOR

Local $ControHandle = $ControlID,$STM_GETIMAGE_RES = 0x0173,$IMAGE_ENHMETAFILE_RES = 3
Local $IMAGE_BITMAP_RES = 0,$IMAGE_ICON_RES = 1,$IMAGE_CURSOR_RES = 2 , $OldImage = 0
Local $BM_GETIMAGE_RES  = 0x00F6
if Not IsHWnd($ControlID) Then $ControHandle = GUICtrlGetHandle($ControlID)
Local $Class = _WinAPI_GetClassName($ControHandle)
Select
Case $Class == "Button"
$OldImage = _SendMessage($ControHandle,$BM_GETIMAGE_RES,$IMAGE_BITMAP_RES,0)
if ($OldImage) Then Return SetError(0,1,$OldImage)
$OldImage = _SendMessage($ControHandle,$BM_GETIMAGE_RES,$IMAGE_ICON_RES,0)
if ($OldImage) Then Return SetError(0,3,$OldImage)
Return SetError(1,0,0)
Case $Class == "Static"
$OldImage = _SendMessage($ControHandle,$STM_GETIMAGE_RES,$IMAGE_BITMAP_RES,0)
if ($OldImage) Then Return SetError(0,1,$OldImage)
$OldImage = _SendMessage($ControHandle,$STM_GETIMAGE_RES,$IMAGE_ICON_RES,0)
if ($OldImage) Then Return SetError(0,3,$OldImage)
$OldImage = _SendMessage($ControHandle,$STM_GETIMAGE_RES,$IMAGE_CURSOR_RES,0)
if ($OldImage) Then Return SetError(0,5,$OldImage)
$OldImage = _SendMessage($ControHandle,$STM_GETIMAGE_RES,$IMAGE_ENHMETAFILE_RES,0)
if ($OldImage) Then Return SetError(0,4,$OldImage)
Return SetError(1,0,0)
Case Else
Return SetError(2,0,0)
EndSelect
EndFunc

Func SetBackGroundBmp($hWnd,$hBmpImage,$BmpWidth,$BmpHeight,$DeletOldImage = True)
Local $GuiTest = False , $UBound = UBound($Global_BackGroundArray)
For $i = 0 To $UBound - 1
if ($Global_BackGroundArray[$i][0] = $hWnd) Then
$GuiTest = True
ExitLoop
EndIf
Next
if ($GuiTest = False) Then ReDim $Global_BackGroundArray[$UBound + 1][4]
if ($DeletOldImage) And ($Global_BackGroundArray[$i][1]) _
Then _WinAPI_DeleteObject($Global_BackGroundArray[$i][1])
$Global_BackGroundArray[$i][0] = $hWnd
$Global_BackGroundArray[$i][1] = $hBmpImage
$Global_BackGroundArray[$i][2] = $BmpWidth
$Global_BackGroundArray[$i][3] = $BmpHeight
GUIRegisterMsg($WM_ERASEBKGND,"WM_ERASEBKGND")
_WinAPI_RedrawWindow($hWnd)
EndFunc

Func RemoveBackGroundBmp($hWnd,$DeletImage = True)
Local $GuiTest = False , $UBound = UBound($Global_BackGroundArray)
Local $NewBackGroundArray[$UBound - 1][4]
For $i = 0 To $UBound - 1
if ($Global_BackGroundArray[$i][0] = $hWnd) Then
$GuiTest = True
ExitLoop
EndIf
Next
if ($GuiTest = True) Then
For $i = 0 To $UBound - 1
if ($Global_BackGroundArray[$i][0] = $hWnd) Then ContinueLoop
$NewBackGroundArray[$i][0] = $Global_BackGroundArray[$i][0]
$NewBackGroundArray[$i][1] = $Global_BackGroundArray[$i][1]
$NewBackGroundArray[$i][2] = $Global_BackGroundArray[$i][2]
$NewBackGroundArray[$i][3] = $Global_BackGroundArray[$i][3]
Next
$Global_BackGroundArray = $NewBackGroundArray
Else
Return SetError(1,0,False)
EndIf
_WinAPI_RedrawWindow($hWnd)
Return SetError(0,0,True)
EndFunc

Func WM_ERASEBKGND($hWnd, $Msg, $wParam, $lParam)
Local $GuiTest = False , $UBound = UBound($Global_BackGroundArray)
Local $BGhWnd = WindowFromDC($wParam)
if Not @error Then
For $i = 0 To $UBound - 1
if ($Global_BackGroundArray[$i][0] = $BGhWnd) Then
$GuiTest = True
ExitLoop
EndIf
Next
if ($GuiTest) Then
$Pos = WinGetClientSize($BGhWnd)
$hdc = _WinAPI_CreateCompatibleDC($wParam)
$HGDIOBJ = _WinAPI_SelectObject($hdc,$Global_BackGroundArray[$i][1])
StretchBlt($wParam,0,0,$Pos[0],$Pos[1],$hdc,0,0,$Global_BackGroundArray[$i][2], _
$Global_BackGroundArray[$i][3],$SRCCOPY)
$HGDIOBJ = _WinAPI_SelectObject($hdc,$HGDIOBJ)
_WinAPI_DeleteDC($hdc)
Return True
EndIf
EndIf
EndFunc

Func SndPlaySound($Ptr,$LOOP = False)
;File Type Or Format File.wav
Local $SND_MEMORY  = 4, $SND_ASYNC = 1 ,$SND_SYNC = 0,$SND_NODEFAULT = 2 , _
$SND_LOOP  = 0x0008 , $SND_NOSTOP = 0x0010 ,$SND_FILENAME = 0x00020000
Local $fuSound = BitOR($SND_MEMORY,$SND_ASYNC,$SND_NODEFAULT)
if ($LOOP) Then $fuSound = BitOR($fuSound,$SND_LOOP)
$BOOL = DllCall("winmm.dll", "int", "sndPlaySound","ptr",$Ptr,"UINT",$fuSound)
If @error Or $BOOL[0] = 0 Then Return SetError(1,0,False)
Return SetError(0,0,True)
EndFunc

Func DeleteObj($Object,$ObjectType)
Switch $ObjectType
Case 1
if (_WinAPI_DeleteObject($Object)) Then Return True
Case 2
if (DeleteMetaFile($Object)) Then Return True
Case 3
if (_WinAPI_DestroyIcon($Object)) Then Return True
Case 4
if (DeleteEnhMetaFile($Object)) Then Return True
Case 5
if (DestroyCursor($Object)) Then Return True
EndSwitch
Return SetError(1,0,False)
EndFunc

Func StretchBlt($hdcDest,$nXOriginDest,$nYOriginDest,$nWidthDest,$nHeightDest,$hdcSrc,$nXOriginSrc, _
$nYOriginSrc,$nWidthSrc,$nHeightSrc,$dwRop)
$Rt = DllCall("Gdi32.dll" ,"BOOL","StretchBlt","ptr",$hdcDest,"int",$nXOriginDest,"int",$nYOriginDest,"int",$nWidthDest , _
"int",$nHeightDest,"ptr",$hdcSrc,"int",$nXOriginSrc,"int",$nYOriginSrc,"int",$nWidthSrc,"int",$nHeightSrc,"DWORD",$dwRop)
if @error Or $Rt[0] = 0 Then Return SetError(1,0,0)
Return SetError(0,0,$Rt[0])
EndFunc

Func WindowFromDC($hDC)
$HWND = DllCall("User32.dll","ptr","WindowFromDC","ptr",$hdc)
if @error Or $HWND[0] = 0 Then Return SetError(1,0,0)
Return SetError(0,0,$HWND[0])
EndFunc

Func GetImageSize($hBmp)
Local $ntagBITMAPINFO = "DWORD biSize;LONG biWidth;LONG biHeight;USHORT biPlanes;" & _
"USHORT biBitCount;DWORD biCompression;DWORD biSizeImage;LONG biXPelsPerMeter;" & _
"LONG biYPelsPerMeter;DWORD biClrUsed;DWORD biClrImportant;BYTE RGBQUAD[4]"
Local $vBITMAPINFO = DllStructCreate($ntagBITMAPINFO)
DllStructSetData($vBITMAPINFO,"biSize",(DllStructGetSize($vBITMAPINFO) - 4))
Local $hDC = _WinAPI_CreateCompatibleDC(0)
if @error Then
_WinAPI_DeleteDC($hDC)
Return SetError(1,0,0)
EndIf
_WinAPI_GetDIBits($hDC,$hBmp,0,0,0,DllStructGetPtr($vBITMAPINFO),0)
if @error Then
_WinAPI_DeleteDC($hDC)
Return SetError(2,0,0)
EndIf
_WinAPI_DeleteDC($hDC)
Local $biWidth = DllStructGetData($vBITMAPINFO,"biWidth")
Local $biHeight = DllStructGetData($vBITMAPINFO,"biHeight")
Local $SizeArray[2]
$SizeArray[0] = $biWidth
$SizeArray[1] = $biHeight
Return $SizeArray
EndFunc

Func DeleteMetaFile($hmf)
$BOOL = DllCall("Gdi32.dll","BOOL","DeleteMetaFile","ptr",$hmf)
if @error Or $BOOL[0] = 0 Then Return SetError(1,0,False)
Return SetError(0,0,True)
EndFunc

Func DeleteEnhMetaFile($hemf)
$BOOL = DllCall("Gdi32.dll","BOOL","DeleteEnhMetaFile","ptr",$hemf)
if @error Or $BOOL[0] = 0 Then Return SetError(1,0,False)
Return SetError(0,0,True)
EndFunc

Func DestroyCursor($hCursor)
$BOOL = DllCall("User32.dll","BOOL","DestroyCursor","ptr",$hCursor)
if @error Or $BOOL[0] = 0 Then Return SetError(1,0,False)
Return SetError(0,0,True)
EndFunc
 
 

Module_Res_Example.au3

#include "Res_Ctrl.au3"
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

MsgBox(0,AddRes(),"Success AddRes")

$Gui = GUICreate("Gui Example",500,500,0,0)
$ClID1 = ResCtrlCreatePicEx(10,10,200,100,"GIF","IMGES","GIF",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
$ClID2 = ResCtrlCreatePicEx(295,10,200,100,"BMP","IMGES","BMP",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
$ClID3 = ResCtrlCreatePicEx(10,120,200,100,"JPG","IMGES","JPG",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
$ClID4 = ResCtrlCreatePicEx(295,120,200,100,"ICO","IMGES","ICO",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
$ClID5 = ResCtrlCreatePicEx(10,230,480,160,"EMF","IMGES","EMF",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
$ClID6 = ResCtrlCreate_Button(214,100,-1,-1,"IMGES","BUTTON",-1,"Res.Dll",0,0,True)
;$W = -1 $H = -1 // $ReSize = True
$BOOL = ResSetBackGroundBmp($Gui,"IMGES","BKGND",-1,"Res.Dll")
$BOOL = ResSndPlaySound("IMGES","WAV",-1,"Res.Dll",True); LOOP = True
GUICtrlCreateLabel(StringResGet("STR","ANSI",-1,False,"Res.Dll"),10,400,480,40,BitOR($WS_BORDER,$SS_CENTER,$SS_CENTERIMAGE))
GUICtrlCreateLabel(StringResGet("STR","UNICODE",-1,True,"Res.Dll"),10,450,480,40,BitOR($WS_BORDER,$SS_CENTER,$SS_CENTERIMAGE))
GUISetState()

Do
$msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE

Func FileToByteStruct($FileName)
Local $nBytes
$FileSize = FileGetSize($FileName)
$FileStruct = DllStructCreate("byte[" & $FileSize & "]")
if @error Then Return SetError(1,0,0)
$hFile = _WinAPI_CreateFile($FileName,2,2)
if @error Then Return SetError(2,0,0)
_WinAPI_ReadFile($hFile,DllStructGetPtr($FileStruct),$FileSize,$nBytes)
if @error Then Return SetError(3,0,0)
_WinAPI_CloseHandle($hFile)
Return SetError(0,0,$FileStruct)
EndFunc

Func AddRes()
if Not FileExists(@ScriptDir & "\Res.Dll") Then FileCopy(@SystemDir & "\ole32.dll",@ScriptDir & "\Res.Dll")
$DataStruct = FileToByteStruct("Gif.gif")
if @error Then Exit(MsgBox(0,"MsgError1","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"GIF","IMGES")
if @error Then Exit(MsgBox(0,"MsgError2","Error ==> " & @error))
$DataStruct = FileToByteStruct("Bmp.bmp")
if @error Then Exit(MsgBox(0,"MsgError3","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"BMP","IMGES")
if @error Then Exit(MsgBox(0,"MsgError4","Error ==> " & @error))
$DataStruct = FileToByteStruct("jpg.jpg")
if @error Then Exit(MsgBox(0,"MsgError5","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"JPG","IMGES")
if @error Then Exit(MsgBox(0,"MsgError6","Error ==> " & @error))
$DataStruct = FileToByteStruct("Ico.ico")
if @error Then Exit(MsgBox(0,"MsgError7","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"ICO","IMGES")
if @error Then Exit(MsgBox(0,"MsgError8","Error ==> " & @error))
$DataStruct = FileToByteStruct("EMF.EMF")
if @error Then Exit(MsgBox(0,"MsgError9","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"EMF","IMGES")
if @error Then Exit(MsgBox(0,"MsgError10","Error ==> " & @error))
$DataStruct = FileToByteStruct("BKGND.bmp")
if @error Then Exit(MsgBox(0,"MsgError11","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"BKGND","IMGES")
if @error Then Exit(MsgBox(0,"MsgError12","Error ==> " & @error))
$DataStruct = FileToByteStruct("Wav.wav")
if @error Then Exit(MsgBox(0,"MsgError13","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"WAV","IMGES")
if @error Then Exit(MsgBox(0,"MsgError14","Error ==> " & @error))
$DataStruct = DllStructCreate("CHAR[" & StringLen("ANSI String") & "]")
if @error Then Exit(MsgBox(0,"MsgError15","Error ==> " & @error))
DllStructSetData($DataStruct,1,"ANSI String")
UpdateResource("Res.Dll",$DataStruct,"ANSI","STR")
if @error Then Exit(MsgBox(0,"MsgError16","Error ==> " & @error))
$DataStruct = DllStructCreate("WCHAR[" & StringLen("UNICODE Wide Character String") & "]")
if @error Then Exit(MsgBox(0,"MsgError17","Error ==> " & @error))
DllStructSetData($DataStruct,1,"UNICODE Wide Character String")
UpdateResource("Res.Dll",$DataStruct,"UNICODE","STR")
if @error Then Exit(MsgBox(0,"MsgError18","Error ==> " & @error))
$DataStruct = FileToByteStruct("Button.bmp")
if @error Then Exit(MsgBox(0,"MsgError19","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"BUTTON","IMGES")
if @error Then Exit(MsgBox(0,"MsgError20","Error ==> " & @error))


Return True
EndFunc

Func UpdateResource($Dll_Exe_FileName,$DataStruct,$lpName,$lpType,$wLanguage = 0)
if Not IsDllStruct($DataStruct) Then Return SetError(1,0,False)
Local $lpData = DllStructGetPtr($DataStruct),$cbData = DllStructGetSize($DataStruct)
$HANDLE = DllCall("kernel32.dll","ptr","BeginUpdateResourceW","wstr",$Dll_Exe_FileName,"BOOL",False)
if @error Or $HANDLE[0] = 0 Then Return SetError(2,0,False)
$hUpdate = $HANDLE[0]
if IsString($lpType) Then
$DataType1 = "wstr"
$lpType = StringUpper($lpType)
ELSE
$DataType1 = "long"
EndIf
if IsString($lpName) Then
$DataType2 = "wstr"
$lpName = StringUpper($lpName)
ELSE
$DataType2 = "long"
EndIf
$BOOL = DllCall("kernel32.dll","BOOL","UpdateResourceW","ptr",$hUpdate,$DataType1 _
,$lpType,$DataType2,$lpName,"WORD",$wLanguage,"ptr",$lpData,"DWORD",$cbData)
if @error Or $BOOL[0] = 0 Then Return SetError(3,0,False)
$BOOL = DllCall("kernel32.dll","BOOL","EndUpdateResourceW","HANDLE",$hUpdate,"BOOL",False)
if @error Or $BOOL[0] = 0 Then Return SetError(4,0,False)
Return SetError(0,0,True)
EndFunc
 
 

Res_Example.au3

#AutoIt3Wrapper_Res_File_Add=Gif.gif,IMGES,GIF,0
#AutoIt3Wrapper_Res_File_Add=Bmp.bmp,IMGES,BMP,0
#AutoIt3Wrapper_Res_File_Add=jpg.jpg,IMGES,JPG,0
#AutoIt3Wrapper_Res_File_Add=Ico.ico,IMGES,ICO,0
#AutoIt3Wrapper_Res_File_Add=EMF.EMF,IMGES,EMF,0
#AutoIt3Wrapper_Res_File_Add=Button.bmp,IMGES,BUTTON,0
#AutoIt3Wrapper_Res_File_Add=BKGND.bmp,IMGES,BKGND,0
#AutoIt3Wrapper_Res_File_Add=ANSI.txt,STR,ANSI,0
#AutoIt3Wrapper_Res_File_Add=UNICODE.txt,STR,UNICODE,0
#include "Res_Ctrl.au3"
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

if Not (@Compiled) Then Exit(MsgBox(0,"Err","Must compile the Res_Example.au3 With Options"))

$Gui = GUICreate("Gui Example",500,500,0,0)
$ClID1 = ResCtrlCreatePicEx(10,10,200,100,"GIF","IMGES","GIF",-1,"",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
$ClID2 = ResCtrlCreatePicEx(295,10,200,100,"BMP","IMGES","BMP",-1,"",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
$ClID3 = ResCtrlCreatePicEx(10,120,200,100,"JPG","IMGES","JPG",-1,"",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
$ClID4 = ResCtrlCreatePicEx(295,120,200,100,"ICO","IMGES","ICO",-1,"",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
$ClID5 = ResCtrlCreatePicEx(10,230,480,160,"EMF","IMGES","EMF",-1,"",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
$ClID6 = ResCtrlCreate_Button(214,100,-1,-1,"IMGES","BUTTON",-1,"",0,0,True)
;$W = -1 $H = -1 // $ReSize = True
$BOOL = ResSetBackGroundBmp($Gui,"IMGES","BKGND",-1,"")
$BOOL = ResSndPlaySound("IMGES","WAV",-1,"Res.Dll",True); LOOP = True
GUICtrlCreateLabel(StringResGet("STR","ANSI",-1,False,""),10,400,480,40,BitOR($WS_BORDER,$SS_CENTER,$SS_CENTERIMAGE))
GUICtrlCreateLabel(StringResGet("STR","UNICODE",-1,True,""),10,450,480,40,BitOR($WS_BORDER,$SS_CENTER,$SS_CENTERIMAGE))
GUISetState()

Do
$msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE
 
 
Edited by wolf9228
2 people like this

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

MsgBox(0,AddRes(),"Success AddRes")

to change

#AutoIt3Wrapper_Run_After="%scriptfile%.EXE"

If not FileExists("Res.Dll ") Then AddRes()

nice

Edited by mesale0077

Share this post


Link to post
Share on other sites

MsgBox(0,AddRes(),"Success AddRes")

to change

#AutoIt3Wrapper_Run_After="%scriptfile%.EXE"

If not FileExists("Res.Dll ") Then AddRes()

nice

 

What do you mean I do not understand ...Anyway thank you :)


صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

#include "Res_Ctrl.au3"
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#AutoIt3Wrapper_Run_After="%scriptfile%.EXE"
If not FileExists("Res.Dll ") Then AddRes()
;MsgBox(0,AddRes(),"Success AddRes")

$Gui = GUICreate("Gui Example",500,500,0,0)
$ClID1 = ResCtrlCreatePicEx(10,10,200,100,"GIF","IMGES","GIF",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
$ClID2 = ResCtrlCreatePicEx(295,10,200,100,"BMP","IMGES","BMP",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
$ClID3 = ResCtrlCreatePicEx(10,120,200,100,"JPG","IMGES","JPG",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
$ClID4 = ResCtrlCreatePicEx(295,120,200,100,"ICO","IMGES","ICO",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
$ClID5 = ResCtrlCreatePicEx(10,230,480,160,"EMF","IMGES","EMF",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
$ClID6 = ResCtrlCreate_Button(214,100,-1,-1,"IMGES","BUTTON",-1,"Res.Dll",0,0,True)
;$W = -1 $H = -1 // $ReSize = True
$BOOL = ResSetBackGroundBmp($Gui,"IMGES","BKGND",-1,"Res.Dll")
$BOOL = ResSndPlaySound("IMGES","WAV",-1,"Res.Dll",True); LOOP = True
GUICtrlCreateLabel(StringResGet("STR","ANSI",-1,False,"Res.Dll"),10,400,480,40,BitOR($WS_BORDER,$SS_CENTER,$SS_CENTERIMAGE))
GUICtrlCreateLabel(StringResGet("STR","UNICODE",-1,True,"Res.Dll"),10,450,480,40,BitOR($WS_BORDER,$SS_CENTER,$SS_CENTERIMAGE))
GUISetState()

Do
$msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE

Func FileToByteStruct($FileName)
Local $nBytes
$FileSize = FileGetSize($FileName)
$FileStruct = DllStructCreate("byte[" & $FileSize & "]")
if @error Then Return SetError(1,0,0)
$hFile = _WinAPI_CreateFile($FileName,2,2)
if @error Then Return SetError(2,0,0)
_WinAPI_ReadFile($hFile,DllStructGetPtr($FileStruct),$FileSize,$nBytes)
if @error Then Return SetError(3,0,0)
_WinAPI_CloseHandle($hFile)
Return SetError(0,0,$FileStruct)
EndFunc

Func AddRes()
if Not FileExists(@ScriptDir & "\Res.Dll") Then FileCopy(@SystemDir & "\ole32.dll",@ScriptDir & "\Res.Dll")
$DataStruct = FileToByteStruct("Gif.gif")
if @error Then Exit(MsgBox(0,"MsgError1","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"GIF","IMGES")
if @error Then Exit(MsgBox(0,"MsgError2","Error ==> " & @error))
$DataStruct = FileToByteStruct("Bmp.bmp")
if @error Then Exit(MsgBox(0,"MsgError3","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"BMP","IMGES")
if @error Then Exit(MsgBox(0,"MsgError4","Error ==> " & @error))
$DataStruct = FileToByteStruct("jpg.jpg")
if @error Then Exit(MsgBox(0,"MsgError5","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"JPG","IMGES")
if @error Then Exit(MsgBox(0,"MsgError6","Error ==> " & @error))
$DataStruct = FileToByteStruct("Ico.ico")
if @error Then Exit(MsgBox(0,"MsgError7","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"ICO","IMGES")
if @error Then Exit(MsgBox(0,"MsgError8","Error ==> " & @error))
$DataStruct = FileToByteStruct("EMF.EMF")
if @error Then Exit(MsgBox(0,"MsgError9","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"EMF","IMGES")
if @error Then Exit(MsgBox(0,"MsgError10","Error ==> " & @error))
$DataStruct = FileToByteStruct("BKGND.bmp")
if @error Then Exit(MsgBox(0,"MsgError11","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"BKGND","IMGES")
if @error Then Exit(MsgBox(0,"MsgError12","Error ==> " & @error))
$DataStruct = FileToByteStruct("Wav.wav")
if @error Then Exit(MsgBox(0,"MsgError13","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"WAV","IMGES")
if @error Then Exit(MsgBox(0,"MsgError14","Error ==> " & @error))
$DataStruct = DllStructCreate("CHAR[" & StringLen("ANSI String") & "]")
if @error Then Exit(MsgBox(0,"MsgError15","Error ==> " & @error))
DllStructSetData($DataStruct,1,"ANSI String")
UpdateResource("Res.Dll",$DataStruct,"ANSI","STR")
if @error Then Exit(MsgBox(0,"MsgError16","Error ==> " & @error))
$DataStruct = DllStructCreate("WCHAR[" & StringLen("UNICODE Wide Character String") & "]")
if @error Then Exit(MsgBox(0,"MsgError17","Error ==> " & @error))
DllStructSetData($DataStruct,1,"UNICODE Wide Character String")
UpdateResource("Res.Dll",$DataStruct,"UNICODE","STR")
if @error Then Exit(MsgBox(0,"MsgError18","Error ==> " & @error))
$DataStruct = FileToByteStruct("Button.bmp")
if @error Then Exit(MsgBox(0,"MsgError19","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"BUTTON","IMGES")
if @error Then Exit(MsgBox(0,"MsgError20","Error ==> " & @error))


Return True
EndFunc

Func UpdateResource($Dll_Exe_FileName,$DataStruct,$lpName,$lpType,$wLanguage = 0)
if Not IsDllStruct($DataStruct) Then Return SetError(1,0,False)
Local $lpData = DllStructGetPtr($DataStruct),$cbData = DllStructGetSize($DataStruct)
$HANDLE = DllCall("kernel32.dll","ptr","BeginUpdateResourceW","wstr",$Dll_Exe_FileName,"BOOL",False)
if @error Or $HANDLE[0] = 0 Then Return SetError(2,0,False)
$hUpdate = $HANDLE[0]
if IsString($lpType) Then
$DataType1 = "wstr"
$lpType = StringUpper($lpType)
ELSE
$DataType1 = "long"
EndIf
if IsString($lpName) Then
$DataType2 = "wstr"
$lpName = StringUpper($lpName)
ELSE
$DataType2 = "long"
EndIf
$BOOL = DllCall("kernel32.dll","BOOL","UpdateResourceW","ptr",$hUpdate,$DataType1 _
,$lpType,$DataType2,$lpName,"WORD",$wLanguage,"ptr",$lpData,"DWORD",$cbData)
if @error Or $BOOL[0] = 0 Then Return SetError(3,0,False)
$BOOL = DllCall("kernel32.dll","BOOL","EndUpdateResourceW","HANDLE",$hUpdate,"BOOL",False)
if @error Or $BOOL[0] = 0 Then Return SetError(4,0,False)
Return SetError(0,0,True)
EndFunc

look

Share this post


Link to post
Share on other sites

Nice!!!

:thumbsup:

 

Thank you and your resources project also Nice :bye:


صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites
#include "Res_Ctrl.au3"
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#AutoIt3Wrapper_Run_After="%scriptfile%.EXE"
If not FileExists("Res.Dll ") Then AddRes()
;MsgBox(0,AddRes(),"Success AddRes")

$Gui = GUICreate("Gui Example",500,500,0,0)
$ClID1 = ResCtrlCreatePicEx(10,10,200,100,"GIF","IMGES","GIF",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
$ClID2 = ResCtrlCreatePicEx(295,10,200,100,"BMP","IMGES","BMP",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
$ClID3 = ResCtrlCreatePicEx(10,120,200,100,"JPG","IMGES","JPG",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
$ClID4 = ResCtrlCreatePicEx(295,120,200,100,"ICO","IMGES","ICO",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
$ClID5 = ResCtrlCreatePicEx(10,230,480,160,"EMF","IMGES","EMF",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
$ClID6 = ResCtrlCreate_Button(214,100,-1,-1,"IMGES","BUTTON",-1,"Res.Dll",0,0,True)
;$W = -1 $H = -1 // $ReSize = True
$BOOL = ResSetBackGroundBmp($Gui,"IMGES","BKGND",-1,"Res.Dll")
$BOOL = ResSndPlaySound("IMGES","WAV",-1,"Res.Dll",True); LOOP = True
GUICtrlCreateLabel(StringResGet("STR","ANSI",-1,False,"Res.Dll"),10,400,480,40,BitOR($WS_BORDER,$SS_CENTER,$SS_CENTERIMAGE))
GUICtrlCreateLabel(StringResGet("STR","UNICODE",-1,True,"Res.Dll"),10,450,480,40,BitOR($WS_BORDER,$SS_CENTER,$SS_CENTERIMAGE))
GUISetState()

Do
$msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE

Func FileToByteStruct($FileName)
Local $nBytes
$FileSize = FileGetSize($FileName)
$FileStruct = DllStructCreate("byte[" & $FileSize & "]")
if @error Then Return SetError(1,0,0)
$hFile = _WinAPI_CreateFile($FileName,2,2)
if @error Then Return SetError(2,0,0)
_WinAPI_ReadFile($hFile,DllStructGetPtr($FileStruct),$FileSize,$nBytes)
if @error Then Return SetError(3,0,0)
_WinAPI_CloseHandle($hFile)
Return SetError(0,0,$FileStruct)
EndFunc

Func AddRes()
if Not FileExists(@ScriptDir & "\Res.Dll") Then FileCopy(@SystemDir & "\ole32.dll",@ScriptDir & "\Res.Dll")
$DataStruct = FileToByteStruct("Gif.gif")
if @error Then Exit(MsgBox(0,"MsgError1","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"GIF","IMGES")
if @error Then Exit(MsgBox(0,"MsgError2","Error ==> " & @error))
$DataStruct = FileToByteStruct("Bmp.bmp")
if @error Then Exit(MsgBox(0,"MsgError3","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"BMP","IMGES")
if @error Then Exit(MsgBox(0,"MsgError4","Error ==> " & @error))
$DataStruct = FileToByteStruct("jpg.jpg")
if @error Then Exit(MsgBox(0,"MsgError5","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"JPG","IMGES")
if @error Then Exit(MsgBox(0,"MsgError6","Error ==> " & @error))
$DataStruct = FileToByteStruct("Ico.ico")
if @error Then Exit(MsgBox(0,"MsgError7","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"ICO","IMGES")
if @error Then Exit(MsgBox(0,"MsgError8","Error ==> " & @error))
$DataStruct = FileToByteStruct("EMF.EMF")
if @error Then Exit(MsgBox(0,"MsgError9","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"EMF","IMGES")
if @error Then Exit(MsgBox(0,"MsgError10","Error ==> " & @error))
$DataStruct = FileToByteStruct("BKGND.bmp")
if @error Then Exit(MsgBox(0,"MsgError11","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"BKGND","IMGES")
if @error Then Exit(MsgBox(0,"MsgError12","Error ==> " & @error))
$DataStruct = FileToByteStruct("Wav.wav")
if @error Then Exit(MsgBox(0,"MsgError13","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"WAV","IMGES")
if @error Then Exit(MsgBox(0,"MsgError14","Error ==> " & @error))
$DataStruct = DllStructCreate("CHAR[" & StringLen("ANSI String") & "]")
if @error Then Exit(MsgBox(0,"MsgError15","Error ==> " & @error))
DllStructSetData($DataStruct,1,"ANSI String")
UpdateResource("Res.Dll",$DataStruct,"ANSI","STR")
if @error Then Exit(MsgBox(0,"MsgError16","Error ==> " & @error))
$DataStruct = DllStructCreate("WCHAR[" & StringLen("UNICODE Wide Character String") & "]")
if @error Then Exit(MsgBox(0,"MsgError17","Error ==> " & @error))
DllStructSetData($DataStruct,1,"UNICODE Wide Character String")
UpdateResource("Res.Dll",$DataStruct,"UNICODE","STR")
if @error Then Exit(MsgBox(0,"MsgError18","Error ==> " & @error))
$DataStruct = FileToByteStruct("Button.bmp")
if @error Then Exit(MsgBox(0,"MsgError19","Error ==> " & @error))
UpdateResource("Res.Dll",$DataStruct,"BUTTON","IMGES")
if @error Then Exit(MsgBox(0,"MsgError20","Error ==> " & @error))


Return True
EndFunc

Func UpdateResource($Dll_Exe_FileName,$DataStruct,$lpName,$lpType,$wLanguage = 0)
if Not IsDllStruct($DataStruct) Then Return SetError(1,0,False)
Local $lpData = DllStructGetPtr($DataStruct),$cbData = DllStructGetSize($DataStruct)
$HANDLE = DllCall("kernel32.dll","ptr","BeginUpdateResourceW","wstr",$Dll_Exe_FileName,"BOOL",False)
if @error Or $HANDLE[0] = 0 Then Return SetError(2,0,False)
$hUpdate = $HANDLE[0]
if IsString($lpType) Then
$DataType1 = "wstr"
$lpType = StringUpper($lpType)
ELSE
$DataType1 = "long"
EndIf
if IsString($lpName) Then
$DataType2 = "wstr"
$lpName = StringUpper($lpName)
ELSE
$DataType2 = "long"
EndIf
$BOOL = DllCall("kernel32.dll","BOOL","UpdateResourceW","ptr",$hUpdate,$DataType1 _
,$lpType,$DataType2,$lpName,"WORD",$wLanguage,"ptr",$lpData,"DWORD",$cbData)
if @error Or $BOOL[0] = 0 Then Return SetError(3,0,False)
$BOOL = DllCall("kernel32.dll","BOOL","EndUpdateResourceW","HANDLE",$hUpdate,"BOOL",False)
if @error Or $BOOL[0] = 0 Then Return SetError(4,0,False)
Return SetError(0,0,True)
EndFunc

look

 

I understand now thank you :bye:


صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

func  ResCtrlCreatePicEx add png file  

png file show

thank you now

Share this post


Link to post
Share on other sites

Interesting. Will have to give this a test.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

func  ResCtrlCreatePicEx add png file  

png file show

thank you now

 

I did not see this post came Four days late

First

#AutoIt3Wrapper_Run_After="%scriptfile%.EXE"
If not FileExists("Res.Dll ") Then AddRes()

This does not mean anything ... Why use the FileExists function does not require

And why use # AutoIt3Wrapper_Run_After

Must be updated resource in each time running the script

This formats Images can be used only in this project

Gif / Bmp / jpg / Emf

thank you


صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

Interesting. Will have to give this a test.

 

thank you


صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0