Popular Post Zedna Posted August 10, 2007 Popular Post Share Posted August 10, 2007 (edited) Link to pages with general resources descriptionMSDN - Resources OverView & ReferenceYou can embed any binary data into your AutoIt compiled EXE files in it's resources at compile time.As opposite to FileInstall() with resources you can use your embedded data directly without any temporary files on disk.If you wish you can save resources to disk with _ResourceSaveToFile() however.Adding data to resources can be done simply by AutoIt3Wrapper directive:#AutoIt3Wrapper_Res_File_Add=FileName, ResType, ResNameAs data can be used for example images,cursors,texts,sounds,videos,binary files etc.For loading/using data from resources at run time I made this tiny helper Resources UDF.Functions inside UDF:_ResourceGet($ResName, $ResType = $RT_RCDATA, $ResLang = 0, $DLL = -1)_ResourceGetAsString($ResName, $ResType = $RT_RCDATA, $ResLang = 0, $DLL = -1)_ResourceGetAsStringW($ResName, $ResType = $RT_RCDATA, $ResLang = 0, $DLL = -1)_ResourceGetAsBytes($ResName, $ResType = $RT_RCDATA, $ResLang = 0, $DLL = -1)_ResourceGetAsImage($ResName, $ResType = $RT_RCDATA, $DLL = -1)_ResourceGetAsBitmap($ResName, $ResType = $RT_RCDATA, $DLL = -1)_ResourceSaveToFile($FileName, $ResName, $ResType = $RT_RCDATA, $ResLang = 0, $CreatePath = 0, $DLL = -1)_ResourceSetImageToCtrl($CtrlId, $ResName, $ResType = $RT_RCDATA, $DLL = -1)_SetBitmapToCtrl($CtrlId, $hBitmap)_ResourcePlaySound($ResName, $Flag = 0, $DLL = -1)Notes:* to compile all script examples you must have installed Scite4AutoIt3 --> you must compile script by F7 from full Scite* for using #AutoIt3Wrapper_Res_File_Add directive you must have AutoIt3Wrapper at least version 2.0.1.22 (it's part of latest Scite4AutoIt3)* to compile all script examples must be apropriate resource data files in script directory (from resource_data.zip) * _ResourceGet() always returns pointer to data (for RT_BITMAP returns hBitmap), returning other types can be done by additional wrapper functions like _ResourceGetAsString() or _ResourceGetAsBytes()* _ResourceGetAsStringW() is for Unicode strings (Widechar)* you can use also #number instead of resource name, see examples* general supported resource types are listed in UDF as constants ($RT_BITMAP, $RT_RCDATA, ...)* information about playing video files (AVI) from resources is here thanks matrixnz* information/examples about using animated GIFs from resources is here and here thanks smashly/ProgAndy* information about running EXE files/DLL functions directly from resources is here thanks trancexx/WardKnown problems/limitations:* _ResourceGet() returns resource size (in bytes) in @extended macro but not for resource type RT_BITMAP* _ResourceSetImageToCtrl() works with "static/button" type of controls (picture,label,icon,button,checkbox,radiobutton,groupbox)* _ResourcePlaySound() plays only WAV files (not MP3 files)* _ResourceGetAsBytes() doesn't work for RT_BITMAP type because _ResourceGet() returns hBitmap instead of memory pointer in this case there could be used _ResourceGetAsImage() as workaround* _ResourceGet() has potential memory leak releasing of resources UnlockResource,FreeResource (opposite of LoadResource,LockResource) is not done because it must be done after using of resources at the end and not inside UDF* _GDIPlus_Startup() is called once at start of whole include --> no _GDIPlus_Shutdown() is calledHistory:expandcollapse popup2011-06-20 - fixed x64 compatibility (type: int->ptr) - internal change: FindResourceA -> FindResourceW (& type: str->wstr) - _SetBitmapToCtrl() --> $CtrlId parameter now supports also -1 (thanks guinness) - _WinAPI_LoadLibraryEx($DLL, $LOAD_LIBRARY_AS_DATAFILE) instead of _WinAPI_LoadLibrary($DLL) (thanks arcker) - added au3.user.calltips.api, au3.userudfs.properties (thanks guinness) - merged resource_au3.zip + resource_data.zip to one file resources.zip 2010-02-12 - all examples now use fixed #AutoIt3Wrapper_Res_File_Add directive from latest Scite4Autoit3 (no need for ResHacker.exe) - added support for buttons (also checkboxes,radiobuttons,groupboxes) in _ResourceSetImageToCtrl()/_SetBitmapToCtrl() thanks Melba 2009-08-25 - fixed corrupted topic (appeared after forum upgrade) - removed some AU3 tags from topic, note: all AU3 code is untouched inside attached ZIP 2008-11-27 - added _ResourceGetAsStringW() --> for Unicode strings (Widechar) 2008-11-10 - added two very simple examples 2008-08-14 - change: _GDIPlus_Startup() is called once at start of whole include--> no _GDIPlus_Shutdown() is called - fixed support for animated GIFs in _ResourceGetAsImage() --> removed_MemGlobalFree($hData) - used simpler UDF syntax (from WinAPI) instead of DllCall() where possible - added new example for animated GIF image 2008-07-08 - just corrected some typos in this topic (no code changes) 2008-06-25 - big thanks to ProgAndy for ideas,improvements! - added _ResourceGetAsImage(), _ResourceGetAsBitmap() - added optional $DLL parameter to all functions - for loading resources from external EXE,DLL files - fixed previous limitation in _ResourceSaveToFile() - now supports also RT_BITMAP type - new examples in resource_test.au3 2008-05-02 - added new RT,SND constants - fixed bad order of parameters ResName x ResType in FindResourceExA (thanks SmOke_N) - added DeleteObject of oldBmp from STM_SETIMAGE in _SetBitmapToCtrl (thanks ProgAndy) - added settinng SS_BITMAP style to control before STM_SETIMAGE in_SetBitmapToCtrl (support for labels) 2008-04-24 - added support for JPG,GIF,PNG in _ResourceSetImageToCtrl() using GDI+ - thanks ProgAndy - reverted all examples back from #AutoIt3Wrapper_Res_File_Add= to#AutoIt3Wrapper_run_after=ResHacker.exe -add - updated both ZIP archives 2007-10-16 - added _ResourcePlaySound() - thanks Larry - corrected local declaration of $struxt - was problem when Opt("MustDeclareVars",1) - updated resource_test.au3 and resource.au3 in resource_au3.zip 2007-09-14 - added optional parameter $CreatePath in _ResourceSaveToFile() - updated resource_test.au3 and resource.au3 in resource_au3.zip 2007-09-11 - in examples used new AutoIt3Wrapper directive#AutoIt3Wrapper_Res_File_Add from latest Scite4AutoIt3 (instead of #AutoIt3Wrapper_run_after=ResHacker.exe -add ...) - updated resource_test.au3 and resource_test_ie.au3 in resource_au3.zip 2007-09-05 - in #AutoIt3Wrapper_run_after=ResHacker.exe -add ... directive can be resource type in text form -->rcdata instead of 10, bitmap instead of 2 and so on (note: but for htmlmust be used 23 still) - updated only resource_test.au3 in resource_au3.zip 2007-09-04 - added description at top of this topic - added _ResourceSaveToFile() - source is also example for using _ResourceGetAsBytes() - more error checking in UDF and error codes are now differrent todistinguish possible problem - default ResType = 10 ($RT_RCDATA) in all functions - updated both ZIP archives 2007-08-29 - added TODO list - removed not used local variables in _ResourceSetImageToCtrl() - ziparchive not updated yet - revisited WWW links and TODO list and added list of functions 2007-08-10 - first versionresource_test_min1.au3 - very simple example script of using UDF#AutoIt3Wrapper_Res_File_Add=image3.jpg, rt_rcdata, TEST_JPG_1 #include "resources.au3" $gui = GUICreate("Data from resources simple example 1",400,150) $pic1 = GUICtrlCreatePic("",0,0,400,150) _ResourceSetImageToCtrl($pic1, "TEST_JPG_1") ; set JPG image to picture control from resource GUISetState(@SW_SHOW) While 1 If GUIGetMsg() = -3 Then Exit WEndresource_test.au3 - complex example script of using UDFexpandcollapse popup#AutoIt3Wrapper_Res_File_Add=test_1.txt, rt_rcdata, TEST_TXT_1 #AutoIt3Wrapper_Res_File_Add=image1.bmp, rt_bitmap, TEST_BMP_1 #AutoIt3Wrapper_Res_File_Add=image2.bmp, rt_bitmap, TEST_BMP_2 #AutoIt3Wrapper_Res_File_Add=image3.jpg, rt_rcdata, TEST_JPG_3 #AutoIt3Wrapper_Res_File_Add=binary1.dat, rt_rcdata, TEST_BIN_1 #AutoIt3Wrapper_Res_File_Add=C:\WINDOWS\Media\tada.wav, sound, TEST_WAV_1 #include "resources.au3" $gui = GUICreate("Data from resources example",820,400) $pic1 = GUICtrlCreatePic("",0,0,400,300) $pic2 = GUICtrlCreatePic("",400,0,400,150) $pic3 = GUICtrlCreatePic("",400,150,400,150) $pic4 = GUICtrlCreatePic("",600,320,400,100) $label1 = GUICtrlCreateLabel("",20,320,380,100) $label2 = GUICtrlCreateLabel("",400,320,200,100) GUISetState(@SW_SHOW) ; get string from resource $string = _ResourceGetAsString("TEST_TXT_1") GUICtrlSetData($label1, $string) ; set BMP image to picture control from resource bitmap _ResourceSetImageToCtrl($pic1, "TEST_BMP_1", $RT_BITMAP) ; get bitmap from resource (as pointer) $hBmp = _ResourceGet("TEST_BMP_2", $RT_BITMAP) ; and use it for whatever you like _SetBitmapToCtrl($pic2, $hBmp) ; set JPG image to picture control from resource _ResourceSetImageToCtrl($pic3, "TEST_JPG_3") ; set image to picture control from external DLL resource _ResourceSetImageToCtrl($pic4, "#14355", $RT_BITMAP, @SystemDir & "\shell32.dll") ; get/use picture from resources as hImage type $size1 = _ResourceGetImageSize("TEST_BMP_1", $RT_BITMAP) $size2 = _ResourceGetImageSize("TEST_JPG_3") GUICtrlSetData($label2, $size1 & @CRLF & $size2) ; save binary data or another type (image) from resource to file and get its size in bytes $size1 = _ResourceSaveToFile(@ScriptDir & "\binary_data1.dat", "TEST_BIN_1") $size2 = _ResourceSaveToFile(@ScriptDir & "\binary_data2.bmp", "TEST_BMP_1", $RT_BITMAP) ; save binary data from resource to file (create not existing directory) _ResourceSaveToFile("C:\Dir1\SubDir2\binary_data1.dat", "TEST_BIN_1", $RT_RCDATA, 0, 1) _ResourceSaveToFile("C:\Dir1\SubDir2\binary_data2.bmp", "TEST_BMP_1", $RT_BITMAP, 0, 1) ; play WAV from resource (sync/async) _ResourcePlaySound("TEST_WAV_1") _ResourcePlaySound("TEST_WAV_1", $SND_ASYNC) While 1 If GUIGetMsg() = -3 Then Exit WEnd Func _ResourceGetImageSize($ResName, $ResType = 10) ; $RT_RCDATA = 10 ; get/use picture from resources as hImage type $hImage = _ResourceGetAsImage($ResName, $ResType) $width = _GDIPlus_ImageGetWidth ($hImage) $height = _GDIPlus_ImageGetHeight($hImage) Return "Size of " & $ResName & " is: " & $width & "x" & $height EndFuncresources.zip - UDF + examples + sample resource data for examplesau3.user.calltips.apiau3.userudfs.propertiesresources.au3Examples\resource_test.au3Examples\resource_test_ani_gif.au3Examples\resource_test_ie.au3Examples\resource_test_min1.au3Examples\resource_test_min2.au3Examples\ binary1.datExamples\gif-Green-UFO.gifExamples\image1.bmpExamples\image2.bmpExamples\image3.jpgExamples\test_1.gifExamples\test_1.htmExamples\test_1.txtPrevious downloads: 7195resources.zip Edited June 21, 2011 by Zedna yutijang, tarretarretarre, DinFuv and 12 others 14 1 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted August 11, 2007 Author Share Posted August 11, 2007 (edited) Note: I have problems with edit original post from my Opera (second autoit script in autoit tags gets corrupted)so I will add it here:Some descriptions:#compiler_run_after=ResHacker.exe -add resource_test.exe, resource_test.exe, test_1.txt , 10, TEST_1, 0in the above directivetest_1.txt means file with data (may be TXT or binary) to be included as resource10 means RT_RCDATA type of resourceTEST_1 is choosen resource name0 at the end is LangId - lang_neutral = 0#compiler_run_after=ResHacker.exe -add resource_test.exe, resource_test.exe, test_1.txt , 10, TEST_1, 0can be also replaced by adding precompiled RES file:Test_1.rcTEST_1 RCDATA "test_1.txt"compile RC file to RES file:rc.exe Test_1.rcchanged directive for adding precompiled RES resource instead of source data file (Test_1.txt)#compiler_run_after=ResHacker.exe -add resource_test.exe, resource_test.exe, test_1.res ,,,Maybe some AutoIt3Wrapper resource directive could be added for simplicify adding such resources,something similar to #AutoIt3Wrapper_Res_Icon_Add= for example:1) precompiled resources#AutoIt3Wrapper_Res_Add=filename1.res #AutoIt3Wrapper_Res_Add=filename2.resand/or2) data from source files#AutoIt3Wrapper_Res_Data_Add=filename1.txt,RT_RCDATA,res_name1 #AutoIt3Wrapper_Res_Data_Add=filename2.dat,RT_RCDATA,res_name2 #AutoIt3Wrapper_Res_Data_Add=filename3.jpg,RT_RCDATA,res_name3 #AutoIt3Wrapper_Res_Data_Add=filename4.bmp,RT_BITMAP,res_name4so it's: #AutoIt3Wrapper_Res_Data_Add=filename,datatype,resource nameEDIT:but the best solution will be direct Autoit directive (similar to #include)#resource=filename1.res #resource=filename2.resNote: bitmap resources can be used by using LoadLibrary, LoadImage API calls, see Larry's LoadImage examples from this and this - SetBitmapResourceToPicCtrl() Edited August 11, 2007 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
martin Posted August 11, 2007 Share Posted August 11, 2007 (edited) This looks like what a lot of people have been asking for, and although you only created this thread yesterday, I'm surpised there aren't a lot of replies already. I haven't tried it yet but it looks like your usual excellent work Zedna. Thanks for this script. Edited August 11, 2007 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Zedna Posted August 11, 2007 Author Share Posted August 11, 2007 This looks like what a lot of people have been asking for, and although you only created this thread yesterday, I'm surpised there aren't a lot of replies already. I haven't tried it yet but it looks like your usual excellent work Zedna. Thanks for this script. Thanks for positive feedback martin. JdeB said that he can add some Autoi3Wrapper directive if we can simplify all that resource process/examples. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
rover Posted August 11, 2007 Share Posted August 11, 2007 Zedna this is great how do I use for internal bitmap? I've run the text demo above O.K. I'm already using Larry's UDF in one of my scripts to use internal bitmaps without using fileinstall or a resource dll is it the _ResourceGetAsPointer function? if so what data / format is used for $ResSize? $pic = _ResourceGetAsBytes("WINNT_BMP", $RT_BITMAP) $pic = _ResourceGetAsPointer("WINNT_BMP", $RT_BITMAP) obviously needs third parameter i know to use directive: #AutoIt3Wrapper_Run_After=ResHacker.exe -add resource_test.exe, resource_test.exe, winnt.bmp , 2, WINNT_BMP, 0oÝ÷ ÛÇ+ZÖæ¦)ìjg¢W^«+zÈZrG«ë!iÉ®»§¶èºpªiz¸Z²ènW¦Â+a²zȧ¥«a© J®¢Óë¢ Úø¥zÊ®¢Ør©W¬¶¢¨{h¶Å觶٦Ƕ*'¡úÞ²«qëºÜ!jج¶ºw-Ú×è®f¶h¶¬jg²Øb±«¢+ØÀÌØíÕ¥Á¥ÄôU% Ñɱ ÉÑA¥ ÅÕ½ÐìÅÕ½Ðì°À°À°ÈÜÔ°ÄÜа´Ä°ÀÌØí]M}a}1eI¤((íÌÕÍÝ¥Ñ 1ÉÉäÌäíÌUMÑ ¥ÑµÁIͽÕÉQ½A¥ ÑÉ°()MÑ ¥ÑµÁIͽÕÉQ½A¥ ÑÉ° ÀÌØíÕ¤°ÀÌØíÕ¥Á¥Ä±MÉ¥ÁÑÕ±±AÑ °ÅÕ½Ðí]%99Q} 5@ÅÕ½Ðì Thanks! I see fascists... Link to comment Share on other sites More sharing options...
Zedna Posted August 11, 2007 Author Share Posted August 11, 2007 (edited) Zedna this is greathow do I use for internal bitmap?I've run the text demo above O.K.I'm already using Larry's UDF in one of my scripts to use internal bitmaps without using fileinstall or a resource dllThanks!I will accomodate Larry's SetBitmapResourceToPicCtrl() function to make it more compatible/usable with my UDFand will make also example for bitmaps.Stay tuned ... Edited August 11, 2007 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted August 12, 2007 Author Share Posted August 12, 2007 (edited) Here is promised first working bitmap from resource example with changed (simplified) Larry's SetBitmapResourceToPicCtrl() function: Unfortunatelly #compiler_run_after=upx.exe --compress-resources=0 resource_test_bmp.exe will cause not adding bitmap resource so it must be compiled without UPX I discovered that problem is in second #compiler_run_after= which will not wait for the first #compiler_run_after= to be finished - with my big testing bitmap) note: image1.bmp is in my case 800x600 and 1.5MB size and is located in script directory resource_test_bmp.au3 expandcollapse popup#compiler_useupx=n #compiler_run_after=ResHacker.exe -add resource_test_bmp.exe, resource_test_bmp.exe, image1.bmp, 2, TEST_BMP_1, 0 ;#compiler_run_after=upx.exe --compress-resources=0 resource_test_bmp.exe $gui = GUICreate("Bitmap from resources test",900,700) $pic = GUICtrlCreatePic("",0,0,800,600) GUISetState() SetBitmapResourceToPicCtrl($gui,$pic,"TEST_BMP_1") While 1 If GUIGetMsg() = -3 Then Exit WEnd Func SetBitmapResourceToPicCtrl($hwnd,$ctrl,$resource) Local Const $STM_SETIMAGE = 0x0172 Local Const $IMAGE_BITMAP = 0 Local Const $LR_CREATEDIBSECTION = 0x2000 Local Const $LR_COPYDELETEORG = 8 $hwnd = ControlGetHandle($hwnd,"",$ctrl) Local $hInstance = DllCall("kernel32.dll","int","GetModuleHandleA", "int",0) $hInstance = $hInstance[0] Local $hBitmap = DLLCall("user32.dll","hwnd","LoadImage","hwnd",$hInstance,"str",$resource, _ "int",$IMAGE_BITMAP,"int",0,"int",0,"int",0) $hBitmap = $hBitmap[0] DeleteObject(_SendMessage($hwnd,$STM_SETIMAGE,$IMAGE_BITMAP,$hBitmap,0,"int","int","hwnd")) EndFunc Func _SendMessage($hWnd, $msg, $wParam = 0, $lParam = 0, $r = 0, $t1 = "int", $t2 = "int", $t3 = "long") Local $ret = DllCall("user32.dll", $t3, "SendMessage", "hwnd", $hWnd, "int", $msg, $t1, $wParam, $t2, $lParam) If @error Then Return SetError(@error, @extended, "") If $r >= 0 And $r <= 4 Then Return $ret[$r] Return $ret EndFunc ; _SendMessage() Func DeleteObject($hObj) Local $bResult = DllCall('gdi32.dll', 'int', 'DeleteObject', 'hwnd', $hObj) Return $bResult[0] EndFunc ;==>DeleteObject I will make some change in my resources.au3 UDF to be more general. Idea is to to have one general function _ResourceGet($ResName, $ResType, $ResLang = 0) which will return result based on the given type also ResSize will be returned in @extended macro I have not too much time now, so stay tuned ... Edited August 12, 2007 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted August 12, 2007 Author Share Posted August 12, 2007 (edited) Some notes about directives for adding resources: - 10=RT_RCDATA, 2=RT_BITMAP - instead of EXE name can be used %out% parameter - in new Scite4Autoit3 is #AutoIt3Wrapper_Run_After= directive instead of old #compiler_run_after= directive RT_RCDATA example old way #compiler_run_after=ResHacker.exe -add resource_test.exe, resource_test.exe, test_1.txt, 10, TEST_1, 0 #compiler_run_after=upx.exe --compress-resources=0 resource_test.exe RT_RCDATA example better way with %out% #compiler_run_after=ResHacker.exe -add %out%, %out%, test_1.txt, 10, TEST_1, 0 #compiler_run_after=upx.exe --compress-resources=0 %out% *** RT_BITMAP example old way #compiler_run_after=ResHacker.exe -add resource_test_bmp.exe, resource_test_bmp.exe, image1.bmp, 2, TEST_BMP_1, 0 #compiler_run_after=upx.exe --compress-resources=0 resource_test_bmp.exe RT_BITMAP example better way with %out% #compiler_run_after=ResHacker.exe -add %out%, %out%, image1.bmp, 2, TEST_BMP_1, 0 #compiler_run_after=upx.exe --compress-resources=0 %out% Edited August 12, 2007 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
RazerM Posted August 12, 2007 Share Posted August 12, 2007 (edited) I had to make sure reshacker was in same dir as files (didn't use upx), but it works well. I hope it becomes easier to use. Edited August 12, 2007 by RazerM My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop. Link to comment Share on other sites More sharing options...
Zedna Posted August 12, 2007 Author Share Posted August 12, 2007 (edited) this fails #AutoIt3Wrapper_Run_After="%scitedir%\AutoIt3Wrapper\ResHacker.exe" -script C:\Program Files\AutoIt3\Examples\reshack.txt this fails #AutoIt3Wrapper_Run_After="%scitedir%\AutoIt3Wrapper\ResHacker.exe" -script "C:\Program Files\AutoIt3\Examples\reshack.txt" this works #AutoIt3Wrapper_Run_After="%scitedir%\AutoIt3Wrapper\ResHacker.exe" -script C:\Compile\reshack.txt reshacker script method (same method as used in autoit3wrapper.au3, that's whats used for extra icon add) try this: #AutoIt3Wrapper_Run_After="%scitedir%\AutoIt3Wrapper\ResHacker.exe" -script "C:\Progra~1\AutoIt3\Examples\reshack.txt" Zedna, I noticed when first trying Larry's UDF that it used a variation on _SendMessage() (and same name) in Misc.au3 include which your example above has, they being essentially the same if you remove this "hwnd" from the DeleteObject line. otherwise if you use Misc.au3 in your script you will get a conflict with having two same named functions or wrong number of arguments message if you don't use the modified function from DeleteObject(_SendMessage($hwnd,$STM_SETIMAGE,$IMAGE_BITMAP,$hBitmap,0,"int","int","hwnd")) to DeleteObject(_SendMessage($hwnd,$STM_SETIMAGE,$IMAGE_BITMAP,$hBitmap,0,"int","int")) You are right. I know about that _SendMessage variation from Larry. He made it due to differrent output type (hwnd instead of long. I tried it also with standard output type (long) from Misc.au3 and it works fine. So in final UDF version will be used _SendMessage from Misc.au3. also, I guess/assume that ResSize has to do with resizing image? ResSize is output parameter for get resource size. This ResSize is used later for DllSctructCreate(). I said that this will be changed - resource size will be returned in @extended macro. one thing about compiling bitmaps as resources is you can't resize the image, you have to adjust your image size to what you want before compiling into exe. Thanks for your above bitmap example and the work your doing on this UDF, not much comment here yet, but obvious interest in other threads on this in the forum, especially Larry's UDFOK. Edit: upx compression works if run manually after compiling exe i noticed in my case that when using icon add and compiling in bitmaps for my toolbar that upx compressing after exe compiled would break the link to the internal icon resources but not the default program icon or bitmaps (blank toolbar) Read my above post. I discovered this too. It's probably error in Autoit3Wrapper: I discovered that problem is in second #compiler_run_after= which will not wait for the first #compiler_run_after= to be finished - with my big testing bitmap) As I said: I will make some changes and cleanup later. Stay tuned... Edited August 12, 2007 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted August 13, 2007 Author Share Posted August 13, 2007 (edited) Good news folks!! Here is new version of my resource UDF and new simple/clean example for using:resource_test.au3 - example for TXT and BMP data in resourcesexpandcollapse popup#compiler_useupx=n #compiler_run_after=ResHacker.exe -add %out%, %out%, test_1.txt, 10, TEST_TXT_1, 0 #compiler_run_after=ResHacker.exe -add %out%, %out%, image1.bmp, 2, TEST_BMP_1, 0 #compiler_run_after="c:\program files\Autoit3\Aut2Exe\upx.exe" --compress-resources=0 "%out%" #include "resources.au3" $gui = GUICreate("Data from resources test",900,700) $pic = GUICtrlCreatePic("",0,0,800,600) $label = GUICtrlCreateLabel("",20,620,800,100) GUISetState(@SW_SHOW) ; string from resource $string = _ResourceGetAsString("TEST_TXT_1", $RT_RCDATA) GUICtrlSetData($label, $string) ; bitmap from resource $hBmp = _ResourceGet("TEST_BMP_1", $RT_BITMAP) _SetBitmapToCtrl($gui, $pic, $hBmp) While 1 If GUIGetMsg() = -3 Then Exit WEnd Func _SetBitmapToCtrl($hWnd, $CtrlId, $hBitmap) Local Const $STM_SETIMAGE = 0x0172 Local Const $IMAGE_BITMAP = 0 $hWnd = ControlGetHandle($hWnd, "", $CtrlId) DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap) DllCall('gdi32.dll', 'int', 'DeleteObject', 'hwnd', $hBitmap) EndFuncoÝ÷ ÙºÞ²«që»uöÚºÚ"µÍÚ[ÛYK[ÛÙQÛØ[ÛÛÝ ÌÍÔÐÕTÓÔHBÛØ[ÛÛÝ ÌÍÔÐUPTHÛØ[ÛÛÝ ÌÍÔÒPÓÓHÂÛØ[ÛÛÝ ÌÍÔÓQSHH ÛØ[ÛÛÝ ÌÍÔÑPSÑÈH BÛØ[ÛÛÝ ÌÍÔÔÕSÈH ÛØ[ÛÛÝ ÌÍÔÑÓTH ÂÛØ[ÛÛÝ ÌÍÔÑÓHÛØ[ÛÛÝ ÌÍÔÐPÐÑSTUÔÈHBÛØ[ÛÛÝ ÌÍÔÔÑUHHLÛØ[ÛÛÝ ÌÍÔÓQTÔÐQÑUPHHLBÛØ[ÛÛÝ ÌÍÔÑÔÕTÐÕTÓÔHLÛØ[ÛÛÝ ÌÍÔÑÔÕTÒPÓÓHMÛØ[ÛÛÝ ÌÍÔÕTÒSÓHMÛØ[ÛÛÝ ÌÍÔÐSPÕTÓÔHBÛØ[ÛÛÝ ÌÍÔÐSRPÓÓHÛØ[ÛÛÝ ÌÍÔÒSHÂÛØ[ÛÛÝ ÌÍÔÓPSQTÕH[ÈÔÛÝÙQÙ] ÌÍÔÓ[YK ÌÍÔÕK ÌÍÔÓ[ÈH BØØ[ÛÛÝ ÌÍÒSPQÑWÐUPTHØØ[ ÌÍÚ[Ý[ÙK ÌÍÚ]X ÌÍÒ[ÐØÚË ÌÍÑÛØ[Y[[ÜPØÚË ÌÍÓY[[ÜTÚ[ ÌÍÔÔÚ^B ÌÍÚ[Ý[ÙHHØ[ ][ÝÚÙ[Ì ][ÝË ][ÝÚ[ ][ÝË ][ÝÑÙ][Ù[R[PI][ÝË ][ÝÚ[ ][ÝË B ÌÍÚ[Ý[ÙHH ÌÍÚ[Ý[ÙVÌHY ÌÍÔÕHH ÌÍÔÐUPT[ ÌÍÚ]XHØ[ ][ÝÝÙÌ ][ÝË ][ÝÚÛ ][ÝË ][ÝÓØY[XYÙI][ÝË ][ÝÚÛ ][ÝË ÌÍÚ[Ý[ÙK ][ÝÜÝ][ÝË ÌÍÔÓ[YK ][ÝÚ[ ][ÝË ÌÍÒSPQÑWÐUPT ][ÝÚ[ ][ÝË ][ÝÚ[ ][ÝË ][ÝÚ[ ][ÝË B ÌÍÚ]XH ÌÍÚ]XÌB] ÌÍÚ]XÈ]È[HÈ]X[YY ÌÍÔÓ[È ÉÝÈ[ ÌÍÒ[ÐØÚÈHØ[ ][ÝÚÙ[Ì ][ÝË ][ÝÚ[ ][ÝË ][ÝÑ[ÛÝÙQ^I][ÝË ][ÝÚ[ ][ÝË ÌÍÚ[Ý[ÙK ][ÝÜÝ][ÝË ÌÍÔÓ[YK ][ÝÛÛÉ][ÝË ÌÍÔÕK ][ÝÜÚÜ ][ÝË ÌÍÔÓ[ÊB[ÙB ÌÍÒ[ÐØÚÈHØ[ ][ÝÚÙ[Ì ][ÝË ][ÝÚ[ ][ÝË ][ÝÑ[ÛÝÙPI][ÝË ][ÝÚ[ ][ÝË ÌÍÚ[Ý[ÙK ][ÝÜÝ][ÝË ÌÍÔÓ[YK ][ÝÛÛÉ][ÝË ÌÍÔÕJB[YYÜ[]Ù]ÜK B ÌÍÒ[ÐØÚÈH ÌÍÒ[ÐØÚÖÌBY ÌÍÒ[ÐØÚÈH[]Ù]ÜK B ÌÍÔÔÚ^HHØ[ ][ÝÚÙ[Ì ][ÝË ][ÝÙÛÜ ][ÝË ][ÝÔÚ^[ÙÛÝÙI][ÝË ][ÝÚ[ ][ÝË ÌÍÚ[Ý[ÙK ][ÝÚ[ ][ÝË ÌÍÒ[ÐØÚÊBYÜ[]Ù]ÜK B ÌÍÔÔÚ^HH ÌÍÔÔÚ^VÌBY ÌÍÔÔÚ^HH[]Ù]ÜK B ÌÍÑÛØ[Y[[ÜPØÚÈHØ[ ][ÝÚÙ[Ì ][ÝË ][ÝÚ[ ][ÝË ][ÝÓØYÛÝÙI][ÝË ][ÝÚ[ ][ÝË ÌÍÚ[Ý[ÙK ][ÝÚ[ ][ÝË ÌÍÒ[ÐØÚÊBYÜ[]Ù]ÜK B ÌÍÑÛØ[Y[[ÜPØÚÈH ÌÍÑÛØ[Y[[ÜPØÚÖÌBY ÌÍÑÛØ[Y[[ÜPØÚÈH[]Ù]ÜK B ÌÍÓY[[ÜTÚ[HØ[ ][ÝÚÙ[Ì ][ÝË ][ÝÚ[ ][ÝË ][ÝÓØÚÔÛÝÙI][ÝË ][ÝÚ[ ][ÝË ÌÍÑÛØ[Y[[ÜPØÚÊBYÜ[]Ù]ÜK B ÌÍÓY[[ÜTÚ[H ÌÍÓY[[ÜTÚ[ÌBY ÌÍÓY[[ÜTÚ[H[]Ù]ÜK BÙ]^[Y ÌÍÔÔÚ^JB] ÌÍÓY[[ÜTÚ[[[Ñ[ÈÔÛÝÙQÙ]ÔÝ[Ê ÌÍÔÓ[YK ÌÍÔÕK ÌÍÔÓ[ÈH BØØ[ ÌÍÔÔÚ[ ÌÍÔÔÚ^H ÌÍÔÔÚ[HÔÛÝÙQÙ] ÌÍÔÓ[YK ÌÍÔÕK ÌÍÔÓ[ÊBYÜ[Ù]ÜK B] ÌÎNÉÌÎNÂ[Y ÌÍÔÔÚ^HH^[Y ÌÍÜÝXÝHÝXÝÜX]J ][ÝØÚÉ][ÝÈ [È ÌÍÔÔÚ^H [È ][Ý×I][ÝË ÌÍÔÔÚ[B]ÝXÝÙ]]J ÌÍÜÝXÝJHÈ]ÈÝ[Â[[Ñ[ÈÔÛÝÙQÙ]Ð]Ê ÌÍÔÓ[YK ÌÍÔÕK ÌÍÔÓ[ÈH BØØ[ ÌÍÔÔÚ[ ÌÍÔÔÚ^H ÌÍÔÔÚ[HÔÛÝÙQÙ] ÌÍÔÓ[YK ÌÍÔÕK ÌÍÔÓ[ÊBYÜ[]Ù]ÜK B ÌÍÔÔÚ^HH^[Y]ÝXÝÜX]J ][ÝØ]VÉ][ÝÈ [È ÌÍÔÔÚ^H [È ][Ý×I][ÝË ÌÍÔÔÚ[HÈ]ÈÚ[È]Â[[Notes:- ResHacker.exe must be in script directory at compile time- Image1.bmp, Test_1.txt must be in script directory at compile time- ;#compiler_run_after=upx.exe --compress-resources=0 %out% can't be used directly due to Autoit3Wrapper bug (see above posts) so for now you can run command upx.exe --compress-resources=0 resource_test.exe after compilationEDIT: solved: sorry JdeB for my mistake- _ResourceGet() always returns pointer, returning other types can be done by additional wrapper functions like _ResourceGetAsString() or _ResourceGetAsBytes() - see resource.au3 UDF- LoadImage can be used also for icons and cursors. For icons it's not neccessary because icons (from resources) are supported by GUICtrlSetImage already- _ResourceGet() returns resource size (in bytes) in @extended macro but not for resource type RT_BITMAP- _SetBitmapToCtrl() is changed Larry's SetBitmapResourceToPicCtrl() which is used in my example as separate function not included in my resource UDF because it's not resource related functionPost your comments to this stuff ... EDIT: UPX directive solved: sorry JdeB for my mistake Edited August 13, 2007 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Developers Jos Posted August 13, 2007 Developers Share Posted August 13, 2007 Notes:- ResHacker.exe must be in script directory at compile time- Image1.bmp, Test_1.txt must be in script directory at compile time- ;#compiler_run_after=upx.exe --compress-resources=0 %out% can't be used directly due to Autoit3Wrapper bug (see above posts) so for now you can run command upx.exe --compress-resources=0 resource_test.exe after compilation- _ResourceGet() always returns pointer, returning other types can be done by additional wrapper functions like _ResourceGetAsString() or _ResourceGetAsBytes() - see resource.au3 UDF- LoadImage can be used also for icons and cursors. For icons it's not neccessary because icons (from resources) are supported by GUICtrlSetImage already- _ResourceGet() returns resource size (in bytes) in @extended macro but not for resource type RT_BITMAP- _SetBitmapToCtrl() is changed Larry's SetBitmapResourceToPicCtrl() which is used in my example as separate function not included in my resource UDF because it's not resource related functionPost your comments to this stuff ...Give this a try for RUN_After:#AutoIt3Wrapper_run_after=""c:\program files\Autoit3\Aut2Exe\upx.exe" --compress-resources=0 "%out%"" SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Zedna Posted August 13, 2007 Author Share Posted August 13, 2007 Give this a try for RUN_After:#AutoIt3Wrapper_run_after=""c:\program files\Autoit3\Aut2Exe\upx.exe" --compress-resources=0 "%out%"" Sorry JdeB for my mistake and thanks for working solution. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Developers Jos Posted August 13, 2007 Developers Share Posted August 13, 2007 Sorry JdeB for my mistake and thanks for working solution.No problem .... its all a bit goofy depending on the OS used.... Its something you need to know how to code it ... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Zedna Posted August 13, 2007 Author Share Posted August 13, 2007 (edited) Bad news.Edit post with autoit code tags on this forum is absolutely amazing!!Therefore I will post my au3 code here as attachments:EDIT:removed attachments (number of previous downloads: 29 + 33)see first post for the most recent version ... Edited August 30, 2007 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
martin Posted August 13, 2007 Share Posted August 13, 2007 (edited) Bad news.Edit post with autoit code tags on this forum is absolutely amazing!!Therefore I will post my au3 code here as attachments:Fantastic Zedna. I've tested with a 5Mb bitmap and it works just as the manufacturer said it would! And amazingly, if I compress it with upx it reduces the size from 5.61Mb to 4.88Mb and it still works.If I compile it a second time then it produces a file which is 4.9Mb which runs ok, and if I use upx again it reduces to 4.3Mb and still runs. If I delete the reshacker.ini and the reshacker.log files then if I compile again it is back to 5.61Mb So I don't understand (among other things) the line#compiler_run_after="c:\program files\Autoit3\Aut2Exe\upx.exe" --compress-resources=0 "%out%" Edited August 13, 2007 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Zedna Posted August 13, 2007 Author Share Posted August 13, 2007 Fantastic Zedna. I've tested with a 5Mb bitmap and it works just as the manufacturer said it would! And amazingly, if I compress it with upx it reduces the size from 5.61Mb to 4.88Mb and it still works.If I compile it a second time then it produces a file which is 4.9Mb which runs ok, and if I use upx again it reduces to 4.3Mb and still runs. If I delete the reshacker.ini and the reshacker.log files then if I compile again it is back to 5.61Mb So I don't understand (among other things) the line#compiler_run_after="c:\program files\Autoit3\Aut2Exe\upx.exe" --compress-resources=0 "%out%"Good to hear that it's working fine If you want the best compression you can add another parametres to upx.exe, for example:#compiler_run_after="c:\program files\Autoit3\Aut2Exe\upx.exe" -9 --compress-resources=0 "%out%"or#compiler_run_after="c:\program files\Autoit3\Aut2Exe\upx.exe" --best --compress-resources=0 "%out%"Note:--compress-resources=0 means: Don't compress any resources at all.So bitmap stored as resource must stay uncompressed by UPX to be usable by resource API functions.Maybe sometimes in the future somebody will observe how to use also GIF,JPG,PNG directly from resources through some API functions (maybe GDI+) ... Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
martin Posted August 13, 2007 Share Posted August 13, 2007 Good to hear that it's working fine If you want the best compression you can add another parametres to upx.exe, for example:#compiler_run_after="c:\program files\Autoit3\Aut2Exe\upx.exe" -9 --compress-resources=0 "%out%"or#compiler_run_after="c:\program files\Autoit3\Aut2Exe\upx.exe" --best --compress-resources=0 "%out%"Note:--compress-resources=0 means: Don't compress any resources at all.So bitmap stored as resource must stay uncompressed by UPX to be usable by resource API functions.Maybe sometimes in the future somebody will observe how to use also GIF,JPG,PNG directly from resources through some API functions (maybe GDI+) ...The point is that the -resources=0 doesn't seem to make any significant difference, which is to say if I remove it the exe still works. If I omit the whole line and manually compress the exe with upx the exe is smaller and still works. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Zedna Posted August 13, 2007 Author Share Posted August 13, 2007 The point is that the -resources=0 doesn't seem to make any significant difference, which is to say if I remove it the exe still works. If I omit the whole line and manually compress the exe with upx the exe is smaller and still works. Really - you are right! I'm surprised by this behaviour. In my little test was best result with this UPX directive: #compiler_run_after="c:\program files\Autoit3\Aut2Exe\upx.exe" --best "%out%" With this directive it works with smallest size but ResHacker couldn't show included resources (it recognize them but not show it's content) and say: "File has non-standard resource layout. It's probably been compressed with an EXE compressor" But sometimes it makes corrupted EXE (non worling without resources at all). I tried recompile it several times and only sometimes it makes a crap. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted August 14, 2007 Author Share Posted August 14, 2007 I did search for some GDI plus reference about loading images (BMP,GIF,JPG,PNG,TIFF,WMF,...) and found only this MSDN link about Image Functions. There are functions GdipLoadImageFromFile() and GdipLoadImageFromStream() but there is no detailed description.Can somebody tell me where is detailed reference of these GDI plus functions.Note: GdipLoadImageFromFile() is in Auto3Lib GdipLoadImageFromStream() is not in Auto3Lib and maybe could be used to load compressed images (GIF,JPG,PNG) from resources Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now