nassausky

Using an image from the web on a button

26 posts in this topic

I have found a few old scripts with ideas on how to use graphics from the web.  Everything I have tried has come up with errors. A few examples use the variable $ghGDIPDLL and this looks like it is because Autoit code has changed over time.  I added Global $ghGDIPDLL = $__g_hGDIPDll to the beginning of the samples of code but then there were other errors like $hBitmap = $hBitmap[2] Error:Subscript used on non-accessible variable.

Does anyone have complete recent code that works in the latest Autoit that can start a basic gui with a single button on it of any graphic from the web.  From that I can probably figure out how to add it to my app.

Thanks for all help. 

Share this post


Link to post
Share on other sites



No need to work with WMI or dll's or whatnot... Here's what I would do. Save the downloaded file, then use it in the GUICtrlSetImage. Hopefully this is what you're looking for.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>

Example()

Func Example()
    GUICreate("My GUI") ; will create a dialog box that when displayed is centered

    GUICtrlCreateButton("my picture button", 10, 20, 60, 60, $BS_BITMAP)
    GUICtrlSetImage(-1, "c:\Temp\something.bmp")

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd
EndFunc   ;==>Example

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

 

No need to work with WMI or dll's or whatnot... Here's what I would do. Save the downloaded file, then use it in the GUICtrlSetImage. Hopefully this is what you're looking for.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>

Example()

Func Example()
    GUICreate("My GUI") ; will create a dialog box that when displayed is centered

    GUICtrlCreateButton("my picture button", 10, 20, 60, 60, $BS_BITMAP)
    GUICtrlSetImage(-1, "c:\Temp\something.bmp")

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd
EndFunc   ;==>Example

 

Thanks the website images change frequently.  Either I will need to find code to have autoit download these to a local file dynamically or I might still need code to display the image directly from the website on the buttons. I will think about this.  If anyone else has other ideas it would be great too.

Thanks @sadbunny I will see about maybe using inetget together with your code.

Edited by nassausky

Share this post


Link to post
Share on other sites

Try this:

#include <GDIplus.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

_GDIPlus_Startup()
Global $hHBitmap = _GDIPlus_BitmapCreateFromMemory(InetRead("http://icons.iconarchive.com/icons/hopstarter/soft-scraps/64/User-Administrator-Blue-icon.png"), 1)
Global $hGUI = GUICreate("Bitmap from inet", 300, 200)
GUISetBkColor(0xFFFFFF)
Global $iBtn = GUICtrlCreateButton("", (300 - 72) / 2, (200 - 72) / 2, 72, 72, $BS_BITMAP), $hBtn = GUICtrlGetHandle($iBtn)
_WinAPI_DeleteObject(_SendMessage($hBtn, $BM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap))
GUISetState()

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _WinAPI_DeleteObject($hHBitmap)
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit
        Case $iBtn
            MsgBox(0, "Info", "Image in button was downloaded from web and used directly without saving to disk first!")
    EndSwitch
Until False

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Excellent @UEZ just what I was looking for.   I'm going to play with that a bit and thanks again @SadBunny for the option.

Share this post


Link to post
Share on other sites

this is awesome but i have a question how can we get the original  image say its 480 x 560 but we want to fit into a button that 240 x 280  just for an example

 

Share this post


Link to post
Share on other sites

No need to work with WMI or dll's or whatnot... Here's what I would do. Save the downloaded file, then use it in the GUICtrlSetImage. Hopefully this is what you're looking for.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>

Example()

Func Example()
    GUICreate("My GUI") ; will create a dialog box that when displayed is centered

    GUICtrlCreateButton("my picture button", 10, 20, 60, 60, $BS_BITMAP)
    GUICtrlSetImage(-1, "c:\Temp\something.bmp")

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd
EndFunc   ;==>Example

i cant get this to work at all...

i was thinking it was because of spaces in the folder files as such:  
 "C:\Documents and Settings\settop\Desktop\Imgs/ArIII.bmp

so i changed the code to this:

Func Example()
    GUICreate("My GUI") ; will create a dialog box that when displayed is centered

   $img = "/Imgs/ArIII.bmp"
   $load  = '"' & @ScriptDir & $img & '"'

   ConsoleWrite( "Image Used:  " & $load   & @CRLF ) ; If you're in SciTE

   $Btn = GUICtrlCreateButton("my picture button", 10, 10, 260, 260, $BS_BITMAP)
   ;_GUICtrlButton_SetImage($Btn, $load)

   GUICtrlSetImage(-1, $load)

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd
 EndFunc   ;==>Example


any idea why it is not showing the image at all?
 

Share this post


Link to post
Share on other sites

Try

$load  = @ScriptDir & $img

instead and be sure that the file is in script dir.


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Try

$load  = @ScriptDir & $img

instead and be sure that the file is in script dir.

same thing nothing showing up as far as pic goes...   the console is writing out the location so i know it is correct location

Share this post


Link to post
Share on other sites

This works for me:

Func Example()
    GUICreate("My GUI") ; will create a dialog box that when displayed is centered

   $img = "\Imgs\ArIII.bmp"
   $load  = @ScriptDir & $img

   ConsoleWrite( "Image Used:  " & $load   & @CRLF ) ; If you're in SciTE

   $Btn = GUICtrlCreateButton("my picture button", 10, 10, 260, 260, $BS_BITMAP)
   ;_GUICtrlButton_SetImage($Btn, $load)

   GUICtrlSetImage(-1, $load)

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd
 EndFunc   ;==>Example

 


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

strange still nothing...  you think i am missing a  au3  file?

autoit.png

Share this post


Link to post
Share on other sites

A wise man on here once said, if you want help with code post the code, if you want help with a picture post a picture of your code. No one is going to type in your code from a picture of it.

(yes, I know it's posted in UEZ's post, just a friendly reminder)


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

i know, i wanted to show that the code is NOT showing the image

Share this post


Link to post
Share on other sites

Do you have a link to the image file you're using so we can test it with the same image?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

its any image not just this one.   but i added it

ArIII.bmp

Share this post


Link to post
Share on other sites

The image is not in bmp format - it is a jpg. Just convert it to bmp format and it should work.


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

but it say .bmp  and i even tried using some of your code to get it to work in case it is not a bmp  and still not working

 

#include <GDIplus.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

_GDIPlus_Startup()

Local Const $iWidth = 300, $iHeight = 300, $iBgColor = 0xFFE8FF ;$iBgColor format RRGGBB

Global $img = "\Imgs\ArIII.bmp"
Global $load  = @ScriptDir & $img


Global $hGUI = GUICreate("Bitmap from inet", 800, 600)
GUISetBkColor(0xFFFFFF)

;Global $hHBitmap = _GDIPlus_BitmapCreateFromMemory(InetRead("http://icons.iconarchive.com/icons/hopstarter/soft-scraps/64/User-Administrator-Blue-icon.png"), 1)
Global $hHBitmap = _GDIPlus_BitmapCreateFromMemory($load, 1)

Global $iBtn = GUICtrlCreateButton("", (300 - 72) / 2, (200 - 72) / 2, 272, 272, $BS_BITMAP), $hBtn = GUICtrlGetHandle($iBtn)
_WinAPI_DeleteObject(_SendMessage($hBtn, $BM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap))
GUISetState()

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _WinAPI_DeleteObject($hHBitmap)
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit
        Case $iBtn
            MsgBox(0, "Info", "Image in button was downloaded from web and used directly without saving to disk first!")
    EndSwitch
Until False

 

Share this post


Link to post
Share on other sites

The file is a jpg with a bmp extension. If you open it in paint and just "Save As" a bmp them rerun your script you will see the image on the button. 


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

i understand that i wont be able to always control that so i want to do it via  the code 

Share this post


Link to post
Share on other sites

i understand that i wont be able to always control that so i want to do it via  the code 

That did work, but again if i am just grabbing .png or a jpg  from a api or xml file i need to  do a different method i am going to  try that with the code presented above and come back

 

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