Sign in to follow this  
Followers 0
Marcdk

Making a picture into a button?

6 posts in this topic

#1 ·  Posted (edited)

Hey guys, i'm trying to create a script where i have a picture in a GUI. This picture needs to work as a button, so once it's pressed it will run Notepad.

I'm not the best programmer yet, and i also searched around the forum, didn't find any clear answer to my question, and if i did, i just didn't understand it.

My script:

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

#Region ### START Koda GUI section ### Form=C:\Program Files\AutoIt3\SciTE\Koda\Forms\test.kxf
$Form1 = GUICreate("Just a simple program", 321, 401, 193, 125)
GUISetBkColor(0x808080)
$Label1 = GUICtrlCreateLabel("", 40, 32, 4, 4)
GUICtrlCreateInput("", 168, 40, 121, 21)
$Account = GUICtrlCreateLabel("Account", 24, 48, 73, 17)
$Label2 = GUICtrlCreateLabel("Username", 24, 80, 95, 17)
$Input1 = GUICtrlCreateInput("", 168, 72, 121, 21)
$Label3 = GUICtrlCreateLabel("Select which email you would like to use", 64, 152, 194, 17)
$Button = GUICtrlCreateButton ("", 736, 224, 131, 25,$BS_BITMAP)
GUICtrlSetImage ($Button, ".\temp.bmp")
$Pic1 = GUICtrlCreatePic("C:\Users\Marc\Desktop\Temp.jpg", 88, 184, 142, 185, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            Run ("notepad.exe");
    EndSwitch
WEnd

Any help? :/

Edited by Marcdk

Share this post


Link to post
Share on other sites



If you want to save a picture as an icon file, download this: http://www.jhepple.com/iconmkr.htm

I don't know about buttons though. Never really tried.


The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share this post


Link to post
Share on other sites

Hey guys, i'm trying to create a script where i have a picture in a GUI. This picture needs to work as a button, so once it's pressed it will run Notepad.

I'm not the best programmer yet, and i also searched around the forum, didn't find any clear answer to my question, and if i did, i just didn't understand it.

Your code as posted should work, except that with this line:

$Button = GUICtrlCreateButton ("", 736, 224, 131, 25,$BS_BITMAP)

you've positioned your button way off your GUI so it won't be visible.

You've got it at left 736 but your GUI is only 321 wide!

Share this post


Link to post
Share on other sites

Hey guys, i'm trying to create a script where i have a picture in a GUI. This picture needs to work as a button, so once it's pressed it will run Notepad.

I'm not the best programmer yet, and i also searched around the forum, didn't find any clear answer to my question, and if i did, i just didn't understand it.

My script:

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

#Region ### START Koda GUI section ### Form=C:\Program Files\AutoIt3\SciTE\Koda\Forms\test.kxf
$Form1 = GUICreate("Just a simple program", 321, 401, 193, 125)
GUISetBkColor(0x808080)
$Label1 = GUICtrlCreateLabel("", 40, 32, 4, 4)
GUICtrlCreateInput("", 168, 40, 121, 21)
$Account = GUICtrlCreateLabel("Account", 24, 48, 73, 17)
$Label2 = GUICtrlCreateLabel("Username", 24, 80, 95, 17)
$Input1 = GUICtrlCreateInput("", 168, 72, 121, 21)
$Label3 = GUICtrlCreateLabel("Select which email you would like to use", 64, 152, 194, 17)
$Button = GUICtrlCreateButton ("", 736, 224, 131, 25,$BS_BITMAP)
GUICtrlSetImage ($Button, ".\temp.bmp")
$Pic1 = GUICtrlCreatePic("C:\Users\Marc\Desktop\Temp.jpg", 88, 184, 142, 185, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            Run ("notepad.exe");
    EndSwitch
WEnd

Any help? :/

Label, input, button and pic are all controls in a Graphic User Interface, GUI.

When these GUI Controls, GUICtrl, are created, GUICtrlCreate, a control identification, ID, is assigned to that control.

$Account = GUICtrlCreateLabel("Account", 24, 48, 73, 17)

$Input1 = GUICtrlCreateInput("", 168, 72, 121, 21)

$Button = GUICtrlCreateButton ("", 136, 224, 131, 25,$BS_BITMAP)

$Pic1 = GUICtrlCreatePic("C:\Program Files\Autoio\Examples\Images\test.jpg", 88, 184, 142, 185, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))

$Account is a variable containing the Control ID of the created label.

$Input1 is a variable containing the Control ID of the created input.

$Button is a variable containing the Control ID of the created button

$Pic1 is a variable containing the Control ID of the created pic.

When the script is running and there is a mouse click event on any control within the GUI, the variable $nMsg is assigned from the event message the Control ID value of the of the control that was clicked with $nMsg = GUIGetMsg(),

The Switch statement uses $nMsg to compare the Case values for a match. When there is a match between $nMsg equals to a case value, that case is executed.

If the control ID of the Pic control, $Pic1, is added as a case value to the switch statement, then, when the picture in the pic control is clicked, that click should find its way to the Case $Pic1 for comparison and execution.

Short answer is put

Case $Pic1
            Run ("notepad.exe");

in Switch statement.

Works for me.

Share this post


Link to post
Share on other sites

Label, input, button and pic are all controls in a Graphic User Interface, GUI.

When these GUI Controls, GUICtrl, are created, GUICtrlCreate, a control identification, ID, is assigned to that control.

$Account = GUICtrlCreateLabel("Account", 24, 48, 73, 17)

$Input1 = GUICtrlCreateInput("", 168, 72, 121, 21)

$Button = GUICtrlCreateButton ("", 136, 224, 131, 25,$BS_BITMAP)

$Pic1 = GUICtrlCreatePic("C:\Program Files\Autoio\Examples\Images\test.jpg", 88, 184, 142, 185, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))

$Account is a variable containing the Control ID of the created label.

$Input1 is a variable containing the Control ID of the created input.

$Button is a variable containing the Control ID of the created button

$Pic1 is a variable containing the Control ID of the created pic.

When the script is running and there is a mouse click event on any control within the GUI, the variable $nMsg is assigned from the event message the Control ID value of the of the control that was clicked with $nMsg = GUIGetMsg(),

The Switch statement uses $nMsg to compare the Case values for a match. When there is a match between $nMsg equals to a case value, that case is executed.

If the control ID of the Pic control, $Pic1, is added as a case value to the switch statement, then, when the picture in the pic control is clicked, that click should find its way to the Case $Pic1 for comparison and execution.

Short answer is put

Case $Pic1
            Run ("notepad.exe");

in Switch statement.

Works for me.

Thanks :lmao: Worked :)

Share this post


Link to post
Share on other sites

Marcdk

Also see the _GUICtrlButton_SetImageList example in the help. :)

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