Sign in to follow this  
Followers 0
sublimnl

Button Image missing on other machines

13 posts in this topic

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")

Share this post


Link to post
Share on other sites



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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks for the help. I didn't want to go through the fileinstall routine, so I will check out the resources UDF! >_

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by Zedna

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (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.  >_<

M23

No problem Melba.

Today I will probably fix my Resource UDF topic - broken AU3 tags

I thought that some control classname identification inside _SetBitmapToCtrl() could help to add correct style according to control's classname

but I don't know how exactly to do this.

EDIT

I forgot to mention:

and you must use $BM_SETIMAGE message instead of $STM_SETIMAGE message inside _SetBitmapToCtrl()

Edited by Zedna

Share this post


Link to post
Share on other sites

Thanks Zedna. Will keep it all in mind when I get back to the script >_

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#11 ·  Posted (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 by matthardwick

Share this post


Link to post
Share on other sites

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.htm

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).

Share this post


Link to post
Share on other sites

#13 ·  Posted (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 by matthardwick

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