Jump to content

Image buttons


flynch
 Share

Recommended Posts

#include <GUIConstants.au3>

GUICreate("test",240,180)
$button1 = GUICtrlCreateButton ("1", 0,0,40,40,$BS_ICON)
GUICtrlSetImage (-1, "shell32.dll",5)
$button2 = GUICtrlCreateButton ("2", 40,00,40,40,$BS_ICON)
GUICtrlSetImage (-1, "shell32.dll",7)
$button3 = GUICtrlCreateButton ("3", 80,00,40,40,$BS_ICON)
GUICtrlSetImage (-1, "shell32.dll",22)
$button4 = GUICtrlCreateButton ("4", 120,0,40,40,$BS_ICON)
GUICtrlSetImage (-1, "shell32.dll",23)
$button5 = GUICtrlCreateButton ("5", 160,0,40,40,$BS_ICON)
GUICtrlSetImage (-1, "shell32.dll",32)
$buttonclose = GUICtrlCreateButton ("close", 200,0,40,40,$BS_ICON)
GUICtrlSetImage (-1, "shell32.dll",28)
GUISetState()

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg() 
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

GUIDelete()

Link to comment
Share on other sites

Or event better look here.

This way allows you to create a picture with a label on top of it. When the mouse hovers over the button it will call the function. In the function you have change the picture to a different one.

This assumes that you are wanting to have you own buttons... which means you need to create the image for when the button is pressed or hovered on or normal.

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

Do picture controls not notify? I was sure they did... they do for me.

#include <GUIConstants.au3>

$gui = GUICreate('', 200, 200)
$pic = GUICtrlCreatePic('C:\windows\Prairie Wind.bmp', 0, 0, 100, 100)
$lb = GUICtrlCreateLabel('Click the picture!', 0, 120, 100, 20)
GUISetState()

While 1
    $gm = GUIGetMsg()
    Switch $gm
        Case $pic
            MsgBox(0, '', 'You clicked the picture')
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
Link to comment
Share on other sites

Try this <_<

#include <GUIConstants.au3>

$GUI = GUICreate("My GUI")
$ic = GUICtrlCreatePic('C:\windows\Greenstone.bmp',0,0,160,160)
GUICtrlSetState(-1, $GUI_DISABLE)
$b = GUICtrlCreatePic('C:\windows\Gone Fishing.bmp',0,0,160,160)
GUICtrlSetState(-1,$GUI_HIDE)
$2 =  GUICtrlCreatePic('C:\windows\Prairie Wind.bmp',0,0,160,160)
GUICtrlSetState(-1,$GUI_HIDE)

GUISetState()

While 1

    $m = GUIGetMsg()
   
    If $m = -3 then Exit
   
    $c = GUIGetCursorInfo($GUI)
    If $c[4] = $ic Then
        GUICtrlSetState( $b, $GUI_SHOW)
        GUICtrlSetState( $ic, $GUI_HIDE)
   ;Sleep(100)
        $c = GUIGetCursorInfo($GUI)
            While $c[4] = $b
                If GUIGetMsg() = $b Then Do_Function()
                $c = GUIGetCursorInfo($GUI)
            WEnd
        GUICtrlSetState( $2, $GUI_HIDE)
        GUICtrlSetState( $b, $GUI_HIDE)
        GUICtrlSetState( $ic, $GUI_SHOW)
    EndIf
WEnd

Func Do_Function()
    GUICtrlSetState( $2, $GUI_SHOW)
    MsgBox(0x0, "tset", "OK.....    ", 3)
EndFunc

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Link to comment
Share on other sites

Sorry to drag this topic back up. I've been using the method Saunders said and it's worked for ages. Now look at this:

;¦¦Startup
#include <GUIConstants.au3>
Opt("TrayMenuMode",1)
opt("TrayIconHide",1)
HotKeySet("{F10}","_DExit")
$AXScreenY = @DesktopHeight-230
$AXScreenX = @DesktopWidth-100

;¦¦GUI Startup
$AXMain = GUICreate("AXWindow",100,200,$AXScreenX,$AXScreenY,$WS_POPUP,$WS_EX_TOPMOST+$WS_EX_TOOLWINDOW)
$AXMainBG = GUICtrlCreatePic(@ScriptDir & "\Source\Images\bg.bmp",0,0,100,200)
$AXMainUP = GUICtrlCreatePic(@ScriptDir & "\Source\Images\up.bmp",13,20,50,20)
GUISetState(@SW_SHOW,$AXMain)
While 1
    $AXMsg = GUIGetMsg()
    Switch $AXMsg
        Case $AXMainUP
            MsgBox(0, '', 'You clicked the picture')
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
Func _DExit()
    Exit
EndFunc

When I click the picture no popup comes up. But it did in Saunders example, and does in another of my scripts. What am I doing wrong =/.

Edit: WTH. I put a comment before the bg.bmp line and it worked. Also if I make the button to press appear before the background (swap the lines) it also works, but the buttons invisible because the bg is put over it. =/

Edited by flynch
Link to comment
Share on other sites

Visually, controls are evaluated in the order you create them. So if you create a picture control, then create another one in the same spot, picture 2 will overwrite picture 1.

However, notification is received in the opposite order. So in the above example, if you click on the set of two images, the one on the bottom gives the notification. Thus in your situation your background image is receiving the click because it was created first.

To solve this, disable the background image with GUICtrlSetState($AXMainBG, $GUI_DISABLE). That should work.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...