sublimnl Posted August 24, 2009 Share Posted August 24, 2009 Hi, I have a GUI that has a button with an image on it rather than text. I have this working using the code below, however on other machines the image is missing. I know that this is because the icon file is not in the location I specified in the path below. Is there a way to have AutoIt compile the script with the icon included? $btnGo = GuiCtrlCreateButton("Go",520,12,40,20,$BS_ICON+$BS_DEFPUSHBUTTON) _GUICtrlButton_SetImage($btnGo,"C:\program files\autoit3\icons\findx16.ico") Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 24, 2009 Moderators Share Posted August 24, 2009 sublimnl,A couple of possibilities to get images into a compiled .exe:1. FileInstall. This places a copy of a file in your .exe which you can load onto the user's machine and then use from within your script. Read the Help file carefully and search for the many forum threads.2. Zedna's excellent Resources UDF (which you can find here). This is more complicated to use, but allows you to use files stored in your .exe without having to copy them onto the user's machine. It requires more effort from the coder to get everything into the .exe, but does have the advantage of not having to load files onto a new machine - everything is self-contained. If you want to use this you MUST read the Resources thread carefully and try out the examples - the UDF is not difficult to use, but if you do not take the trouble to learn how to use it properly, you will have problems.I would recommend trying FileInstall first - if you can get what you want that way it is far simpler.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
sublimnl Posted August 24, 2009 Author Share Posted August 24, 2009 Thanks for the help. I didn't want to go through the fileinstall routine, so I will check out the resources UDF! >_ Link to comment Share on other sites More sharing options...
Zedna Posted August 24, 2009 Share Posted August 24, 2009 (edited) Just one note: My Resource UDF implicitly support only static controls (picture,label,icon) and not buttons. You can easily make modification to add support for button: in _SetBitmapToCtrl() change $SS_BITMAP to $BS_BITMAP and you must use $BM_SETIMAGE message instead of $STM_SETIMAGE message I didn't added this to my UDF because I don't know yet how to make it and leave it general (for all type of controls) so you could make modified function like _SetBitmapToButton() with $BS_BITMAP inside it. and modify all needed calls to _SetBitmapToCtrl() to _SetBitmapToButton(). But if you want to work with more types of controls at the same time you must make more copies of all functions where _SetBitmapToCtrl() is called from. EDIT: some more descriptions. Edited August 24, 2009 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 24, 2009 Moderators Share Posted August 24, 2009 Zedna, Thank you for that clarification - it is some time since I looked at your UDF. Thanks again for the explanation of how to add the functionality to the UDF. >_< M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Zedna Posted August 24, 2009 Share Posted August 24, 2009 (edited) Zedna,Thank you for that clarification - it is some time since I looked at your UDF. Thanks again for the explanation of how to add the functionality to the UDF. >_< M23No problem Melba.Today I will probably fix my Resource UDF topic - broken AU3 tagsI thought that some control classname identification inside _SetBitmapToCtrl() could help to add correct style according to control's classnamebut I don't know how exactly to do this.EDITI forgot to mention:and you must use $BM_SETIMAGE message instead of $STM_SETIMAGE message inside _SetBitmapToCtrl() Edited August 24, 2009 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
sublimnl Posted August 24, 2009 Author Share Posted August 24, 2009 Thanks Zedna. Will keep it all in mind when I get back to the script >_ Link to comment Share on other sites More sharing options...
ogeiz Posted August 25, 2009 Share Posted August 25, 2009 sublimnl, A couple of possibilities to get images into a compiled .exe: 1. FileInstall. This places a copy of a file in your .exe which you can load onto the user's machine and then use from within your script. Read the Help file carefully and search for the many forum threads. 2. Zedna's excellent Resources UDF (which you can find here). This is more complicated to use, but allows you to use files stored in your .exe without having to copy them onto the user's machine. It requires more effort from the coder to get everything into the .exe, but does have the advantage of not having to load files onto a new machine - everything is self-contained. If you want to use this you MUST read the Resources thread carefully and try out the examples - the UDF is not difficult to use, but if you do not take the trouble to learn how to use it properly, you will have problems. I would recommend trying FileInstall first - if you can get what you want that way it is far simpler. M23 Hi sublimnl There is a 3rd possibility. You can use the keyword #AutoIt3Wrapper_Res_Icon_Add=c:\path\to.icn to automatically put some icons into the excuteable by the compiler. Some icons are already in the exe after compiling your script, so typically you will find your first user defined icon with index number 4. ; this is the program icon #AutoIt3Wrapper_Icon=program.ico ; There are three predefined Icons, the first user-defined one starts with index 4.. #AutoIt3Wrapper_Res_Icon_Add=save.ico $_SaveIconIdx = 4 ; The second one has index 5 #AutoIt3Wrapper_Res_Icon_Add=exit.ico $_ExitIconIdx = 5 ; load the icons and add it to some buttons (example) If @Compiled Then ; compiled version: load from ressources in executable GUISetIcon(@AutoItExe, 1) ; window icon _GUICtrlButton_SetImageList($b_Save, _GetImageListHandle(@AutoItExe, $_SaveIconIdx), 0) ; button icon, 0=align left _GUICtrlButton_SetImageList($b_Exit, _GetImageListHandle(@AutoItExe, $_ExitIconIdx), 1) ; button icon, 1=align right Else ; script version: load from disk GUISetIcon(@ScriptDir & "\program.ico") ; window icon _GUICtrlButton_SetImageList($b_Save, _GetImageListHandle(@ScriptDir & "\save.ico", 0), 0) ; button icon, 0=align left _GUICtrlButton_SetImageList($b_Exit, _GetImageListHandle(@ScriptDir & "\exit.ico", 0), 1) ; button icon, 1=align right EndIf ; using image list to set image and text on button Func _GetImageListHandle($sFile, $nIconID = 0) Local $hImage = _GUIImageList_Create(16, 16, 5, 3) ; use small icons (16x16) _GUIImageList_AddIcon($hImage, $sFile, $nIconID) Return $hImage EndFunc ;==>_GetImageListHandle BR ogeiz Link to comment Share on other sites More sharing options...
Zedna Posted August 25, 2009 Share Posted August 25, 2009 @ogeiz Yes, for ICO files it's really the simplest way. For other file types than ICO is useful FileInstall() or my resource UDF. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
sublimnl Posted September 8, 2009 Author Share Posted September 8, 2009 Thanks guys. I finally got back to this today and ended up going with ogeiz's suggestion which looked like it would require the least amount of effort since I was already using ICO files. Link to comment Share on other sites More sharing options...
matthardwick Posted May 18, 2010 Share Posted May 18, 2010 (edited) So if I want to create a transparent picture, that doesn't interfer with interface elements, this is the preferred method as far as I understood it... $hGUI = GUICreate("Print Chooser Tool", 500, 500) GUISetIcon(@SystemDir & "\shell32.dll", -61) $pic = GUICreate("", 500, 500, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hGUI) $crest = GuiCtrlCreatePic("crest.gif",0,0, 0,0) However - adding the line _ResourceSetImageToCtrl($crest, "CREST_GIF_1") stops the app from working - as the picture now appears on top of the interface elements after compilation... anyone got any advice? Edited May 18, 2010 by matthardwick Link to comment Share on other sites More sharing options...
Zedna Posted May 18, 2010 Share Posted May 18, 2010 However - adding the line_ResourceSetImageToCtrl($crest, "CREST_GIF_1")stops the app from working - as the picture now appears on top of the interface elements after compilation... anyone got any advice?Read remarks in helpfile for GUICtrlCreatePic()http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreatePic.htmIf a picture is set as a background picture, as the other controls will overlap, it's important to disable the pic control and create it after the others controls: GuiCtrlSetState(-1,$GUI_DISABLE). Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
matthardwick Posted May 18, 2010 Share Posted May 18, 2010 (edited) If a picture is set as a background picture, as the other controls will overlap, it's important to disable the pic control and create it after the others controls: GuiCtrlSetState(-1,$GUI_DISABLE).It already worked. My point was that the resources thing broke it. Edited May 18, 2010 by matthardwick 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