Jump to content
Sign in to follow this  
Valnurat

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.

Share this post


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.

Share this post


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

Share this post


Link to post
Share on other sites

I don't have much, as I don't know how to start.

But yes, it is just one image with different animals in it.


Yours sincerely

Kenneth.

Share this post


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

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By learner123
      Hi All,
       
      I am new to this AUTO IT and I have created a script that will open an app,enter pin and copy the code generated to clipboard. My java code call this autoIT script and use the copied generated code from clipboard.
      This works fine when server  window is on focus. My server is an windows server. 
      But when I minimize or disconnect the server, the script opens the app.exe but doesn't copy any value to clipboard.  
      Can anyone help me on this 😐
       
      Run("C:\Program Files (x86)\RSA SecurID Software Token\SecurID.exe")
      Local $hWnd=WinWait("abc - RSA SecurID Token") ; waits until the window is the active window
      $hWin = WinGetHandle("abc - RSA SecurID Token");
      ControlSend($hWnd,"","","1111") ; simulates pressing the Home key
      ControlSend($hWnd,"","","{ENTER}");
      ControlSend($hWnd,"","","^c");
      Sleep(1000) ;
      ControlSend($hWnd,"","","^c");
       
    • By learner123
      Hi All,
      So I have created a small autoIT script to enter pin into a RSA token(app which generate new code every 30 second), and copy the generated code.
      I have a java application which requires this code so every time my java-code requires this RSA code, it runs the autoIT script and the copied generated code is then used in my java application. 
      I have deployed this code on a windows server and it works fine when I am logged in and the window is on focus, But as soon as I schedule task and disconnect the server (not logged out only disconnect), or even minimize the server window, the autoIT scripts fails and its not able to copy the value.
       
      Please find below the code for AUTOIT.
       
      WinActivate("rsa - RSA SecurID Token") ; activates the window that has old in the tilte bar
      WinWaitActive("rsa - RSA SecurID Token") ; waits until the window is the active window
      Send("1111") ; simulates pressing the Home key, enters password to get the code
      Send("{ENTER}") ; simulates pressing the Enter key
      Sleep(1000) ;
      Send("^c") ; simulates pressing the CTRL+c keys (copy)
       
      Also I saw some post regarding that WINACTIVE only works when window is active. But my below AUTO IT script to handle windows pop up  works perfectly fine when the server is disconnected. 
       
      Opt("WinTitleMatchMode", 1)
      WinWait("https://url","","10")
      WinWaitActive("https://url","","10")
      Sleep(2000)
      Send("userid")
      Sleep(1000)
      Send("{TAB}")
      Sleep(1000)
      Send("passwrd")
      Send("{TAB}")
      Sleep(500)
      Send("{ENTER}")
       
       
    • By JuanFelipe
      Hello gyus, I try to make a code to login in a web page in my job, buy i can’t understand why my form is blocked, this is my code: 
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <StringConstants.au3> #include <WindowsConstants.au3> #include <WinAPIFiles.au3> #include <FileConstants.au3> #include <File.au3> #include <Array.au3> #include <IE.au3> #include <Excel.au3> #include <GuiEdit.au3> #include <GuiStatusBar.au3> #include <DateTimeConstants.au3> #include <Date.au3> #Region ### START Koda GUI section ### Form=C:\noentry\koda_1.7.3.0\Forms\spoa.kxf $Form1 = GUICreate("Eva y Vehículos", 1200, 1000, 10, 10) $prueba = GUICtrlCreateButton("Prueba",10,990,50,20) ;VARIABLES ========================================================================================== $psi = "https://psi.policia.gov.co/PSI/Login.aspx?ReturnUrl=%2fPSI#no-back-button" $chequeVehiculos = "https://psi.policia.gov.co/PSI/frm_lista_chk.aspx" $evaluacionEva = "https://psi.policia.gov.co/PSI/eva_frmver.aspx" $oIE = ObjCreate("Shell.Explorer.2") $GUIActiveX = GUICtrlCreateObj ($oIE, 10, 10, 1180, 980) ;GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW) $oIE.navigate($psi) ;_IELoadWait($oIE) _InicioSesion() #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $prueba _InicioSesion() EndSwitch WEnd Func _InicioSesion() Local $username = _IEGetObjByName($oIE, "txtUsuario") Local $pass = _IEGetObjByName($oIE, "txtClave") Local $logina = _IEGetObjByName($oIE, "btnIngresar") $username.value="example" $pass.value="examplepass" _IEAction($logina, 'click') _IELoadWait($oIE) MsgBox(16,"","") EndFunc  
    • By shelly
      Here is the below code for handling pop-up when window is  inactive ..but I don't know how to change sleep and when i run this script it runs sometimes and sometimes it stops .
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{SPACE}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{DOWN}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{ENTER}")
      --- these 3 lines never worked while TAB lines works sometimes but not in accurate way
      I am new too AutoIt .. help me out why this script behaves in strange way
      ControlFocus("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog", "", "Internet Explorer_Server1","1")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog", "", "Internet Explorer_Server1","the request is send")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{SPACE}")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{DOWN}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{ENTER}")
       
×
×
  • Create New...