Jump to content

Add image to GUI and tell me what kind of an animal.


Recommended Posts

My image has a lot of small pictures with different kinds of animals.

My idea is, when you press each pictures a messagebox should apear with the word of what kind of animal.

How do I add an image to a GUI and how do I control the mouse to tell me what kind of picture I pressed?

Yours sincerely

Kenneth.

Link to post
Share on other sites

Hmmm need more information, what have you tried? Is it one image file with different animals in it?

If it's one image you can use GUICtrlCreatePic and load your image, define the areas of each animal yourself (x, y, width, height of the animal, I'd suggest an array), and when the user clicks the picture, grab the x, y coordinates of the click. Go through the array and use _WinApi_PtinRectEx to test if the click was in the area for each animal. Alternatively you can just create labels where each animal are and set an OnEvent for each label (Or a case for each label, depending on if you use GUIOnEvent mode or not). Whenever the user clicks the picture they'll click the underlying label and activate what you want to do.

Link to post
Share on other sites

I'd use the images as if they were buttons, and do something like this.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>

Example()

Func Example()
    GUICreate("My Draw")
    Local $idTech = GUICtrlCreatePic("\AutoIt3\Examples\Helpfile\Extras\Tech.bmp", 10, 10, 100, 100) ; <<<<<<<<<<<<<  Change this to the path that your AutoIt installation is in.
    Local $idAutoIt = GUICtrlCreatePic("\AutoIt3\Examples\Helpfile\Extras\AutoIt.bmp", 120, 10, 100, 100) ; <<<<<<<<<<<<<  Change this to the path that your AutoIt installation is in.
    GUISetState(@SW_SHOW)

    Do
        $idMsg = GUIGetMsg()
        Switch $idMsg
            Case $idTech
                MsgBox($mb_systemmodal, "Clicked", "Tech clicked")
            Case $idAutoIt
                MsgBox($mb_systemmodal, "Clicked", "AutoIt clicked")
        EndSwitch
    Until $idMsg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

 

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

Link to post
Share on other sites

I was bored.... This would be one way to do it, you probably don't have to get as detailed as I did to outline the animals with labels (take out the for $i = $lblPikachu loop to see where all the labels are).  This won't work on all computers, my desktop resolution is 1920x1080, some may have larger or smaller resolutions.

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Global $hWndGui = GUICreate("Example", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
Global $picImage = GUICtrlCreatePic(@ScriptDir & "\Image.jpg", 0, 0, @DesktopWidth, @DesktopHeight)
Global $lblPikachu1 = GUICtrlCreateLabel("", 115, 700, 95, 50)
Global $lblPikachu2 = GUICtrlCreateLabel("", 180, 675, 50, 30)
Global $lblSquirtle1 = GUICtrlCreateLabel("", 315, 678, 70, 90)
Global $lblSquirtle2 = GUICtrlCreateLabel("", 385, 735, 28, 25)
GLobal $lblLugia1 = GUICtrlCreateLabel("", 1245, 205, 50, 50)
GLobal $lblLugia2 = GUICtrlCreateLabel("", 1295, 225, 30, 20)
GLobal $lblLugia3 = GUICtrlCreateLabel("", 1325, 210, 20, 20)
GLobal $lblLugia4 = GUICtrlCreateLabel("", 1285, 160, 40, 35)
GLobal $lblLugia5 = GUICtrlCreateLabel("", 1325, 185, 20, 20)
GLobal $lblLugia6 = GUICtrlCreateLabel("", 1345, 190, 70, 95)
GLobal $lblLugia7 = GUICtrlCreateLabel("", 1400, 135, 50, 70)
GLobal $lblLugia8 = GUICtrlCreateLabel("", 1410, 255, 50, 22)
Global $lblEevee1 = GUICtrlCreateLabel("", 605, 735, 165, 120)
Global $lblEevee2 = GUICtrlCreateLabel("", 750, 720, 35, 30)
Global $lblEevee3 = GUICtrlCreateLabel("", 775, 700, 30, 30)
Global $lblCharizard1 = GUICtrlCreateLabel("", 1290, 650, 100, 40)
Global $lblCharizard2 = GUICtrlCreateLabel("", 1315, 630, 50, 20)
Global $lblCharizard3 = GUICtrlCreateLabel("", 1340, 620, 25, 10)
Global $lblCharizard4 = GUICtrlCreateLabel("", 1380, 607, 50, 30)
Global $lblCharizard5 = GUICtrlCreateLabel("", 1410, 635, 20, 40)
Global $lblCharizard6 = GUICtrlCreateLabel("", 1430, 645, 5, 30)
Global $lblCharizard7 = GUICtrlCreateLabel("", 1355, 685, 100, 75)
Global $lblCharizard8 = GUICtrlCreateLabel("", 1390, 665, 150, 50)
Global $lblCharizard9 = GUICtrlCreateLabel("", 1475, 625, 50, 40)
Global $lblCharizard10 = GUICtrlCreateLabel("", 1320, 720, 60, 55)
Global $lblCharizard11 = GUICtrlCreateLabel("", 1455, 725, 25, 55)
Global $lblCharizard12 = GUICtrlCreateLabel("", 1480, 745, 20, 15)
Global $lblCharizard12 = GUICtrlCreateLabel("", 1500, 715, 25, 25)
Global $lblBulbasaur1 = GUICtrlCreateLabel("", 1700, 815, 150, 100)
Global $lblBulbasaur2 = GUICtrlCreateLabel("", 1760, 800, 75, 15)

For $i = $lblPikachu1 To $lblBulbasaur2
    GUICtrlSetBkColor($i, $GUI_BKCOLOR_TRANSPARENT)
Next

GUICtrlSetState($picImage, $GUI_DISABLE)

GUISetState(@SW_SHOW, $hWndGui)

While (True)
    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $lblPikachu1 to $lblPikachu2
            MsgBox("", "", "You clicked Pikachu!")
        Case $lblSquirtle1 to $lblSquirtle2
            MsgBox("", "", "You clicked Squirtle!")
        Case $lblLugia1 to $lblLugia8
            MsgBox("", "", "You clicked Lugia!")
        Case $lblEevee1 to $lblEevee3
            MsgBox("", "", "You clicked Eevee!")
        Case $lblCharizard1 to $lblCharizard12
            MsgBox("", "", "You clicked Charizard!")
        Case $lblBulbasaur1 to $lblBulbasaur2
            MsgBox("", "", "You clicked Bulbasaur!")
    EndSwitch
WEnd

GUIDelete($hWndGui)

 

Image.jpg

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By DJ143
      I have a autoit exe file which is used in upload/browse file functionality.  This has been integrated with selenium framework and I am invoking the autoit exe using Java process and runtime. 
      Now the issue is when I run the scripts and invoke the autoit exe in local it works perfectly.  But when I use selenium grid or jenkins to run the scripts in another windows server it is not working.
      Can anyone please suggest any solution for this?
    • By Hermes
      Hello, the script below will read column A from an excel file - and if a value matches in the browser, it will click the corresponding link and click on a specific button to paste the data, then writes "Completed" in Column B. It will continue to read from the excel file and do the same thing for all the remaining rows.
      #Include "Chrome.au3" #Include "wd_core.au3" #Include "wd_helper.au3" #Include "WinHttp.au3" #include <MsgBoxConstants.au3> #include <File.au3> #include <IE.au3> #include <Array.au3> #include <INet.au3> #include <AutoItConstants.au3> #include <WinAPIFiles.au3> #include <GDIPlus.au3> #include <Excel.au3> #Include "WinHttp.au3" #Include "_HtmlTable2Array.au3" Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_LoadWait($sSession) _WD_Navigate($sSession, "table1.html") _WD_LoadWait($sSession) _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='main']") Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='main']") ;ConsoleWrite ("mat-table " & $sElement & @CRLF) Local $aArray1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//td[contains(@class,'data')]", $sElement, True) sleep(1000) For $i = 0 to UBound($aArray1) - 1 $aArray1[$i] = _WD_ElementAction($sSession, $aArray1[$i], 'text') Next ;_ArrayDisplay($aArray1) ;Email variables $SmtpServer = "" ; address for the smtp-server to use - REQUIRED $FromName = "Hermes" ; name from who the email was sent $FromAddress = "sender@gmail.com" ; address from where the mail should come $ToAddress = "recipient@gmail.com" ; destination address of the email - REQUIRED, use commas (,) to add more email addresses $Subject = "File not found" ; subject from the email - can be anything you want it to be $Body = "File not found!" ; the messagebody from the mail - can be left blank but then you get a blank mail $AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed $CcAddress = "" ; address for cc - leave blank if not needed $BccAddress = "" ; address for bcc - leave blank if not needed $Importance = "High" ; Send message priority: "High", "Normal", "Low" $Username = "" ; username for the account used from where the mail gets sent - REQUIRED $Password = "" ; password for the account used from where the mail gets sent - REQUIRED $IPPort = 25 ; port used for sending the mail $ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS $tls = 0 ; enables/disables TLS when required Local $oAppl = _Excel_Open() Local $sWorkbook = "c:\test.xlsx" Local $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook) ;open excel and pass both parameters If FileExists($sWorkbook) Then ;Check if the file exist. Local $oAppl = _Excel_Open() Local $sWorkbook = "c:\test.xlsx" Local $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook) ;open excel and pass both parameters Local $aArray2 = _Excel_RangeRead($oWorkbook,Default,$oWorkbook.ActiveSheet.Usedrange.Columns("A:A")) Local $iIdx Local $Skipline = 0 ;0==> first line Do Local $temprf For $i = 0 To UBound($aArray2) - 1 $temprf &= $aArray2[$i] _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, ".//a[contains(@class,'edit') and contains(text(),'Edit')]") Local $aElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//a[contains(@class,'edit') and contains(text(),'Edit')]", $sElement, True) $iIdx = _ArraySearch($aArray1, $aArray2[$i]) If @error Then ContinueLoop _WD_ElementAction($sSession, $aElement[$iIdx], 'click') If $i < $Skipline Then ContinueLoop $oRange = $oWorkbook.ActiveSheet.Range("B" & $i + 1 & ":XFD" & $i + 1) _Excel_RangeCopyPaste($oWorkbook.Activesheet, $oRange) ;Paste Local $oTest4 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "pastebutton") _WD_ElementAction($sSession, $oTest4, 'click') Sleep(1000) ;Save Button Local $save3 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "button.button") _WD_ElementAction($sSession, $save3, 'click') _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "Completed", "B" & $i+1) sleep(1000) Next Until (Not @error) _Excel_Close($oWorkbook) Else _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl, $tls) Exit EndIf _WD_LoadWait($sSession) ;Attaching files to emails Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0, $tls = 0) Local $objEmail = ObjCreate("CDO.Message") $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress Local $i_Error = 0 Local $i_Error_desciption = "" If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress $objEmail.Subject = $s_Subject If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then $objEmail.HTMLBody = $as_Body Else $objEmail.Textbody = $as_Body & @CRLF EndIf $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer If Number($IPPort) = 0 then $IPPort = 25 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort ;Authenticated SMTP If $s_Username <> "" Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password EndIf ; Set security params If $ssl Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True If $tls Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendtls") = True ;Update settings $objEmail.Configuration.Fields.Update ; Set Email Importance Switch $s_Importance Case "High" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High" Case "Normal" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal" Case "Low" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low" EndSwitch $objEmail.Fields.Update ; Sent the Message $objEmail.Send $objEmail="" EndFunc ;==>_INetSmtpMailCom Local $aDir = _FileListToArrayRec(@TempDir, "scoped_dir*;chrome_*", $FLTAR_FOLDERS, $FLTAR_NORECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) Sleep(2000) For $i = 1 To $aDir[0] DirRemove($aDir[$i], $DIR_REMOVE) Next _WD_LoadWait($sSession) _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome If the excel file doesn't exists in the folder, it will send an email to a specific recipient.
      What i am trying figure out now is if the excel crashes while the script/loop is running, I want to relaunch the excel file continue to the last row before the excel crashed. So if the value of column B is not marked as "completed", it should continue from that row
      Appreciate any help that I can get to achieve this.
      table1.html test.xlsx
    • By adityaparakh
      Hello ,
      I am trying to use Websockets in AutoIt.
      It is to fetch live stock market prices , API is provided and documentation available for python language.
      The link for the code snippet is :
      https://symphonyfintech.com/xts-market-data-front-end-api-v2/#tag/Introduction
      https://symphonyfintech.com/xts-market-data-front-end-api-v2/#tag/Instruments/paths/~1instruments~1subscription/post
       
      https://github.com/symphonyfintech/xts-pythonclient-api-sdk
       
      Second Link is to subscribe to a list of ExchangeInstruments.
      Now I would like to get live stock ltp (LastTradedPrice) for a few stocks whose "ExchangeInstrumentID" I know.
      I am able to use the WinHttp object to perform actions using simple codes like below :
      I have the secretKey and appkey and can generate the needed token. And get the unique ExchangeInstrumentID.

      Below code is just for example of how I am using WinHttp. Unrelated to socket part.
      Global $InteractiveAPItoken = IniRead(@ScriptDir & "\Config.ini", "token", "InteractiveAPItoken", "NA") $baseurl = "https://brokerlink.com/interactive/" $functionurl = "orders" $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $baseurl & $functionurl, False) $oHTTP.SetRequestHeader("Content-Type", "application/json;charset=UTF-8") $oHTTP.SetRequestHeader("authorization", $InteractiveAPItoken) $pD = '{ "exchangeSegment": "NSEFO", "exchangeInstrumentID": ' & $exchangeInstrumentID & ', "productType": "' & $producttype & '", "orderType": "MARKET", "orderSide": "' & $orderside & '", "timeInForce": "DAY", "disclosedQuantity": 0, "orderQuantity": ' & $qty & ', "limitPrice": 0, "stopPrice": 0, "orderUniqueIdentifier": "' & $orderidentifier & '"}' $oHTTP.Send($pD) $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status
          
          
      But am struggling to understand and use socket.
      Would be of great help if you can have a look at the link mentioned above and help with the code sample for AutoIt.
      To connect and listen to a socket.
      Thanks a lot
       
    • By Hermes
      Hi, I have a site that has the following elements below: 
      <div>More element here</div> <div>More element here</div> <div>More element here</div> When I do this in Auto It:
      Local $oSelectDiv = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "div") _WD_HighlightElement($sSession, $oSelectDiv, 1) I also tried to add [3], but it doesnt seems to work:
      Local $oSelectDiv = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "div[3]") _WD_HighlightElement($sSession, $oSelectDiv, 1) It always highlight the first one, but I am trying to highlight the 3rd in the list. Is there anyway to select the 3rd div without having to add any class/id in the divs, and without using XPATH? The structure of the elements in that site were built that way.
    • By meety
      My au3 script program needs administrator privileges on win10 to be executed correctly, because it needs to be added to the boot---Script code:RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", @ScriptName, "REG_SZ", @ScriptFullPath)
      I need to let the program automatically get administrator privileges, so I use a function of #RequireAdmin. Although the program can be added to the boot, but does not execute after system boot up? why is that?
      What should I do?
      --------------------------------------------------------------------
      Update:
      I found that after using the #RequireAdmin function, the program cannot be executed after system boot up.
      An example is given below. after it is compiled, it will not be executed after system boot up in the following two ways.
      1. C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\
      2. RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", @ScriptName, "REG_SZ", @ScriptFullPath)
      why is that?
      example
      #include <MsgBoxConstants.au3>
      #RequireAdmin
      Func test()
          MsgBox(0, "", "this is test message")
      EndFunc   ;==>test
      test()
       
       
×
×
  • Create New...