Module_Res_Example.au3


SUBMITTED BY: Guest

DATE: May 28, 2013, 6:21 a.m.

FORMAT: Text only

SIZE: 6.1 kB

HITS: 1856

  1. #include "Res_Ctrl.au3"
  2. #include <WinAPI.au3>
  3. #include <GUIConstantsEx.au3>
  4. #include <WindowsConstants.au3>
  5. #include <StaticConstants.au3>
  6. MsgBox(0,AddRes(),"Success AddRes")
  7. $Gui = GUICreate("Gui Example",500,500,0,0)
  8. $ClID1 = ResCtrlCreatePicEx(10,10,200,100,"GIF","IMGES","GIF",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
  9. $ClID2 = ResCtrlCreatePicEx(295,10,200,100,"BMP","IMGES","BMP",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
  10. $ClID3 = ResCtrlCreatePicEx(10,120,200,100,"JPG","IMGES","JPG",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
  11. $ClID4 = ResCtrlCreatePicEx(295,120,200,100,"ICO","IMGES","ICO",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
  12. $ClID5 = ResCtrlCreatePicEx(10,230,480,160,"EMF","IMGES","EMF",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2)
  13. $ClID6 = ResCtrlCreate_Button(214,100,-1,-1,"IMGES","BUTTON",-1,"Res.Dll",0,0,True)
  14. ;$W = -1 $H = -1 // $ReSize = True
  15. $BOOL = ResSetBackGroundBmp($Gui,"IMGES","BKGND",-1,"Res.Dll")
  16. $BOOL = ResSndPlaySound("IMGES","WAV",-1,"Res.Dll",True); LOOP = True
  17. GUICtrlCreateLabel(StringResGet("STR","ANSI",-1,False,"Res.Dll"),10,400,480,40,BitOR($WS_BORDER,$SS_CENTER,$SS_CENTERIMAGE))
  18. GUICtrlCreateLabel(StringResGet("STR","UNICODE",-1,True,"Res.Dll"),10,450,480,40,BitOR($WS_BORDER,$SS_CENTER,$SS_CENTERIMAGE))
  19. GUISetState()
  20. Do
  21. $msg = GUIGetMsg()
  22. Until $msg = $GUI_EVENT_CLOSE
  23. Func FileToByteStruct($FileName)
  24. Local $nBytes
  25. $FileSize = FileGetSize($FileName)
  26. $FileStruct = DllStructCreate("byte[" & $FileSize & "]")
  27. if @error Then Return SetError(1,0,0)
  28. $hFile = _WinAPI_CreateFile($FileName,2,2)
  29. if @error Then Return SetError(2,0,0)
  30. _WinAPI_ReadFile($hFile,DllStructGetPtr($FileStruct),$FileSize,$nBytes)
  31. if @error Then Return SetError(3,0,0)
  32. _WinAPI_CloseHandle($hFile)
  33. Return SetError(0,0,$FileStruct)
  34. EndFunc
  35. Func AddRes()
  36. if Not FileExists(@ScriptDir & "\Res.Dll") Then FileCopy(@SystemDir & "\ole32.dll",@ScriptDir & "\Res.Dll")
  37. $DataStruct = FileToByteStruct("Gif.gif")
  38. if @error Then Exit(MsgBox(0,"MsgError1","Error ==> " & @error))
  39. UpdateResource("Res.Dll",$DataStruct,"GIF","IMGES")
  40. if @error Then Exit(MsgBox(0,"MsgError2","Error ==> " & @error))
  41. $DataStruct = FileToByteStruct("Bmp.bmp")
  42. if @error Then Exit(MsgBox(0,"MsgError3","Error ==> " & @error))
  43. UpdateResource("Res.Dll",$DataStruct,"BMP","IMGES")
  44. if @error Then Exit(MsgBox(0,"MsgError4","Error ==> " & @error))
  45. $DataStruct = FileToByteStruct("jpg.jpg")
  46. if @error Then Exit(MsgBox(0,"MsgError5","Error ==> " & @error))
  47. UpdateResource("Res.Dll",$DataStruct,"JPG","IMGES")
  48. if @error Then Exit(MsgBox(0,"MsgError6","Error ==> " & @error))
  49. $DataStruct = FileToByteStruct("Ico.ico")
  50. if @error Then Exit(MsgBox(0,"MsgError7","Error ==> " & @error))
  51. UpdateResource("Res.Dll",$DataStruct,"ICO","IMGES")
  52. if @error Then Exit(MsgBox(0,"MsgError8","Error ==> " & @error))
  53. $DataStruct = FileToByteStruct("EMF.EMF")
  54. if @error Then Exit(MsgBox(0,"MsgError9","Error ==> " & @error))
  55. UpdateResource("Res.Dll",$DataStruct,"EMF","IMGES")
  56. if @error Then Exit(MsgBox(0,"MsgError10","Error ==> " & @error))
  57. $DataStruct = FileToByteStruct("BKGND.bmp")
  58. if @error Then Exit(MsgBox(0,"MsgError11","Error ==> " & @error))
  59. UpdateResource("Res.Dll",$DataStruct,"BKGND","IMGES")
  60. if @error Then Exit(MsgBox(0,"MsgError12","Error ==> " & @error))
  61. $DataStruct = FileToByteStruct("Wav.wav")
  62. if @error Then Exit(MsgBox(0,"MsgError13","Error ==> " & @error))
  63. UpdateResource("Res.Dll",$DataStruct,"WAV","IMGES")
  64. if @error Then Exit(MsgBox(0,"MsgError14","Error ==> " & @error))
  65. $DataStruct = DllStructCreate("CHAR[" & StringLen("ANSI String") & "]")
  66. if @error Then Exit(MsgBox(0,"MsgError15","Error ==> " & @error))
  67. DllStructSetData($DataStruct,1,"ANSI String")
  68. UpdateResource("Res.Dll",$DataStruct,"ANSI","STR")
  69. if @error Then Exit(MsgBox(0,"MsgError16","Error ==> " & @error))
  70. $DataStruct = DllStructCreate("WCHAR[" & StringLen("UNICODE Wide Character String") & "]")
  71. if @error Then Exit(MsgBox(0,"MsgError17","Error ==> " & @error))
  72. DllStructSetData($DataStruct,1,"UNICODE Wide Character String")
  73. UpdateResource("Res.Dll",$DataStruct,"UNICODE","STR")
  74. if @error Then Exit(MsgBox(0,"MsgError18","Error ==> " & @error))
  75. $DataStruct = FileToByteStruct("Button.bmp")
  76. if @error Then Exit(MsgBox(0,"MsgError19","Error ==> " & @error))
  77. UpdateResource("Res.Dll",$DataStruct,"BUTTON","IMGES")
  78. if @error Then Exit(MsgBox(0,"MsgError20","Error ==> " & @error))
  79. Return True
  80. EndFunc
  81. Func UpdateResource($Dll_Exe_FileName,$DataStruct,$lpName,$lpType,$wLanguage = 0)
  82. if Not IsDllStruct($DataStruct) Then Return SetError(1,0,False)
  83. Local $lpData = DllStructGetPtr($DataStruct),$cbData = DllStructGetSize($DataStruct)
  84. $HANDLE = DllCall("kernel32.dll","ptr","BeginUpdateResourceW","wstr",$Dll_Exe_FileName,"BOOL",False)
  85. if @error Or $HANDLE[0] = 0 Then Return SetError(2,0,False)
  86. $hUpdate = $HANDLE[0]
  87. if IsString($lpType) Then
  88. $DataType1 = "wstr"
  89. $lpType = StringUpper($lpType)
  90. ELSE
  91. $DataType1 = "long"
  92. EndIf
  93. if IsString($lpName) Then
  94. $DataType2 = "wstr"
  95. $lpName = StringUpper($lpName)
  96. ELSE
  97. $DataType2 = "long"
  98. EndIf
  99. $BOOL = DllCall("kernel32.dll","BOOL","UpdateResourceW","ptr",$hUpdate,$DataType1 _
  100. ,$lpType,$DataType2,$lpName,"WORD",$wLanguage,"ptr",$lpData,"DWORD",$cbData)
  101. if @error Or $BOOL[0] = 0 Then Return SetError(3,0,False)
  102. $BOOL = DllCall("kernel32.dll","BOOL","EndUpdateResourceW","HANDLE",$hUpdate,"BOOL",False)
  103. if @error Or $BOOL[0] = 0 Then Return SetError(4,0,False)
  104. Return SetError(0,0,True)
  105. EndFunc

comments powered by Disqus