Ebola57 Posted April 16, 2019 Share Posted April 16, 2019 (edited) Hi community This is months am on this problem, I found tricks, but time is to solve it I am intending to add some extra files (in this case, image files) into the output EXE, I tried allmost every piece of code thereby and even more tried using <ResourcesEX.au3> UDF Nothing to do, each EXE compiled never display the "theorically embeded files" Note : Am compiling using SciteAutoIT 4.12 My AutoIT install is 3.3.14.5 #AutoIt3Wrapper_Icon=Offline.ico #AutoIt3Wrapper_Res_Icon_Add=Offline.ico #include <GUIConstantsEx.au3> Global $hGUI = GUICreate("Test",150,50) ; This doesn't work Global $butIcon = GUICtrlCreateButton("",10,10,20,20) GUICtrlSetImage(-1, "Offline.ico", 0) ; This works Global $picIcon = GUICtrlCreateIcon("Offline.ico",0,100,10,16,16) GUISetState(@SW_SHOW) While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd So, any suggestion to get my goal would be highly appreciated Regards Edited April 17, 2019 by Ebola57 Link to comment Share on other sites More sharing options...
benched42 Posted April 16, 2019 Share Posted April 16, 2019 The file "Offline.ico" needs to be in the same folder as your script, whether the script is compiled or not. Looking at the code you have it seems that when compiling it can add the "Offline.ico" to be the icon used by the EXE file. But that does nothing for the button. Typically, here's what I do: 1. I use a function to create a random folder within the user's temp folder: ; #FUNCTION# ==================================================================================================================== ; Name ..........: __RandomTempFolder ; Description ...: Creates a random temp folder to use while this is running in order to store any files needed and included in ; the script run ; Syntax ........: __RandomTempFolder() ; Parameters ....: None ; Return values .: None ; =============================================================================================================================== Func __RandomTempFolder() Local $theFolderName, $i, $theRandomCharacter $theFolderName = "\~" For $i = 1 To 10 $theRandomCharacter = Random(97, 122, 1) $theFolderName = $theFolderName & Chr($theRandomCharacter) Next Return $theFolderName EndFunc ;==>__RandomTempFolder 2. I use a variable within the script and set it to the path of the newly created temp folder: $theSource = @TempDir & __RandomTempFolder() 3. I then use an initializing function to place all of my needed images in the newly created folder (this only shows .ICO icon files, but they can be any file type that your script might need): ; #FUNCTION# ==================================================================================================================== ; Name ..........: __Initialize ; Description ...: Makes sure that images and support files exist for this wizard ; Syntax ........: __Initialize() ; Parameters ....: None ; Return values .: None ; =============================================================================================================================== Func __Initialize() If FileExists($theSource) Then DirRemove($theSource) EndIf DirCreate($theSource) FileInstall("{the exact path to the image file}\error.ico", $theSource & "\error.ico", 1) FileInstall("{the exact path to the image file}\info.ico", $theSource & "\info.ico", 1) FileInstall("{the exact path to the image file}\question.ico", $theSource & "\question.ico", 1) FileInstall("{the exact path to the image file}\warning.ico", $theSource & "\warning.ico", 1) EndFunc 4. Finally, when I set the button with an image on it, I use the path to the image file (I typically use variables to place the buttons and set the size of the buttons so that if I need to make the overall window wider or taller, the buttons adjust accordingly): $btnMsgOK = GUICtrlCreateButton("", {button left}, {button top}, {button width}, {button height}, $BS_ICON) GUICtrlSetImage(-1, $theSource & "\ok.ico") GUICtrlSetTip(-1, "OK", "", 0, 1) One more thing: I always, always, always delete the random temp folder after closing the window at the end of a script run. Windows doesn't clean up after itself, but that doesn't mean my scripts shouldn't. Who lied and told you life would EVER be fair? Link to comment Share on other sites More sharing options...
Nine Posted April 16, 2019 Share Posted April 16, 2019 (edited) If you want to use ressources included in the .exe, I would strongly recommend that you use RessourceEX UDF, unless you want to reinvent the wheel. The example provided show you how to add different resources. But if you only need icon to a button, you can do it like this : #AutoIt3Wrapper_Res_Icon_Add=%AUTOITDIR%\Examples\Helpfile\Extras\Soccer.ico #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> Local Const $iHeight = 450, $iWidth = 470 $g_hGUI = GUICreate('Resources Example', $iWidth, $iHeight, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX)) Local $iBall = GUICtrlCreateButton('Click', $iWidth - 168, 72, 68, 71, $BS_ICON) GUICtrlSetImage($iBall, @AutoItExe, '201') ; Icon resources added with #AutoIt3Wrapper_Res_Icon_Add, can be directly used without the UDF. Global $picIcon = GUICtrlCreateIcon(@AutoItExe,201,100,10,32,32) GUISetState(@SW_SHOW, $g_hGUI) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd You will need to compile the script first... Edited April 16, 2019 by Nine Ebola57 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Rex Posted April 16, 2019 Share Posted April 16, 2019 (edited) Another way to this is to embed the resource icon/image as Base64 code directly in the script code, and using this from @UEZ I use these functions (I not 100%, but quit sure I got them from @UEZ also) to add images to either button or to a pic control. ; Set gui button images using Base64 and memwrite Func SetBtnImg($hButton, $dString) Local $Bmp_Button = _GDIPlus_BitmapCreateFromMemory($dString, True) _WinAPI_DeleteObject(_SendMessage($hButton, $BM_SETIMAGE, $IMAGE_BITMAP, $Bmp_Button)) _WinAPI_UpdateWindow($hButton) _WinAPI_DeleteObject($Bmp_Button) EndFunc ;==>SetBtnImg ;Set gui images using Base64 and memwrite Func SetImg($idImg, $dString) Local $hBmp = _GDIPlus_BitmapCreateFromMemory($dString, True) ;to load an image from the net Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp) _WinAPI_DeleteObject(GUICtrlSendMsg($idImg, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp)) EndFunc ;==>SetImg Only drawback is if the images is updated, then you need to regenerate the Base64 code Cheers /Rex Edited April 16, 2019 by Rex Link to comment Share on other sites More sharing options...
Ebola57 Posted April 17, 2019 Author Share Posted April 17, 2019 (edited) 16 hours ago, benched42 said: The file "Offline.ico" needs to be in the same folder as your script, whether the script is compiled or not. Looking at the code you have it seems that when compiling it can add the "Offline.ico" to be the icon used by the EXE file. But that does nothing for the button. Typically, here's what I do: 1. I use a function to create a random folder within the user's temp folder: [...] After closing the window at the end of a script run. Windows doesn't clean up after itself, but that doesn't mean my scripts shouldn't. Thanks for this answer but my main goal is having a stand alone EXE without having to install any file 16 hours ago, Nine said: If you want to use ressources included in the .exe, I would strongly recommend that you use RessourceEX UDF, unless you want to reinvent the wheel. The example provided show you how to add different resources. But if you only need icon to a button, you can do it like this : You will need to compile the script first... This is the code line that seems I was lacking. Going to try, Many thanks GUICtrlSetImage($iBall, @AutoItExe, '201') ; Icon resources added with #AutoIt3Wrapper_Res_Icon_Add, can be directly used without the UDF. Global $picIcon = GUICtrlCreateIcon(@AutoItExe,201,100,10,32,32) 14 hours ago, Rex said: Another way to this is to embed the resource icon/image as Base64 code directly in the script code, and using this from @UEZ I[...] /Rex Will try if ResourcesEX fails, Thanks for alternate solution Edited April 17, 2019 by Ebola57 Link to comment Share on other sites More sharing options...
Ebola57 Posted April 17, 2019 Author Share Posted April 17, 2019 16 hours ago, Nine said: If you want to use ressources included in the .exe, I would strongly recommend that you use RessourceEX UDF, unless you want to reinvent the wheel. The example provided show you how to add different resources. But if you only need icon to a button, you can do it like this : @AutoItExe You will need to compile the script first... That maccro was the key, works flalessly now Grateful thanks Link to comment Share on other sites More sharing options...
Ebola57 Posted April 17, 2019 Author Share Posted April 17, 2019 17 hours ago, Nine said: If you want to use ressources included in the .exe, I would strongly recommend that you use RessourceEX UDF, unless you want to reinvent the wheel. The example provided show you how to add different resources. But if you only need icon to a button, you can do it like this : #AutoIt3Wrapper_Res_Icon_Add=%AUTOITDIR%\Examples\Helpfile\Extras\Soccer.ico #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> Local Const $iHeight = 450, $iWidth = 470 $g_hGUI = GUICreate('Resources Example', $iWidth, $iHeight, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX)) Local $iBall = GUICtrlCreateButton('Click', $iWidth - 168, 72, 68, 71, $BS_ICON) GUICtrlSetImage($iBall, @AutoItExe, '201') ; Icon resources added with #AutoIt3Wrapper_Res_Icon_Add, can be directly used without the UDF. Global $picIcon = GUICtrlCreateIcon(@AutoItExe,201,100,10,32,32) GUISetState(@SW_SHOW, $g_hGUI) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd You will need to compile the script first... Last but not least, that method rox for one icon icon, but to adress others as I need to ad seeveral icons in EXE ? Link to comment Share on other sites More sharing options...
Nine Posted April 17, 2019 Share Posted April 17, 2019 8 minutes ago, Ebola57 said: Last but not least, that method rox for one icon icon, but to adress others as I need to ad seeveral icons in EXE ? It starts at 201, just add 1 for each icon (like 2nd is 202, 3rd is 203, etc...) Ebola57 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy 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