Jump to content
Sign in to follow this  
Nieeru

Button image question

Recommended Posts

Nieeru

Hi there!

I recently started getting into AutoIt and have already started creating my first "program" so to speak, getting more into the GUI part of it.

Since I'm not that good at working with Koda and such, I've decided to use various overlapping images to style and make the base/main GUI look the way I want it to and also created button-spesific images.

What I'm wondering about is if it's possible for me to create some kind of a "on click" event for every button that I have an image attached to, to make a visual representation of the button being clicked.

I've looked around on the forum here with little to no luck and been reading the Info file but I haven't found anything that can help me. Maybe I've overlooked something.

Would be awesome if any of you guys could help me with this or point me in the right direction!

-- Nieeru

Share this post


Link to post
Share on other sites
Yoriz

GUICtrlSetOnHover UDF

or combined with icons udf see GUICtrlSetOnHover & Icons UDFs Demonstration


GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

Share this post


Link to post
Share on other sites
Nieeru

Awesome, mate! That's exactly what I was looking for.

A simple to understand by powerfull script/addon to pretty much do anything I want. :idea:

I'll try it out and implement it into my code, if crap hits the fan, I'll be back. :)

-- Nieeru

Share this post


Link to post
Share on other sites
Nieeru

Excuse the double posting. :< Couldn't edit my previous post.

After playing around with both plugins for quite a while, when I got home to my own computer to test them out (running Windows 7 Professional x64) they won't actually work at all, however, they were working on my parent's laptop running Windows Vista.

Also, it looks like as if it somehow destroys my *.jpg or *.bmp files in the process while trying to run the script as some pretty weird black 1px dots appear randomly around on the buttons for some reason.

Any suggestions? I've tried everything now!

-- Nieeru

Edited by Nieeru

Share this post


Link to post
Share on other sites
Nieeru

Ah yeah, I probably should've done that earlier.

I've gone through all the examples that I could think of and tried creating seperate functions for every event but it still produces the same problems. It's still not doing anything, all though other scripts are working running them under x86 (Got AutoIt installed under x64 Win Vista/Win 7) so I don't really understand why it's breaking appart my BMP or JPG files.

I've attached the images I'm using at the moment with the high quality BMP's available (I didn't bother converting them to jpeg's again) just to make it easier to see what I'm trying to achieve.

-- Nieeru

#include <GUIConstantsEx.au3>
#Include <GUICtrlSetOnHover_UDF.au3>

Global $file_path = @ScriptDir & "\images"

$Avira = GUICreate("Avira - GUI Test", 821, 561)
$client_background = GUICtrlCreatePic($file_path & "\background.jpg", 0, 0, 820, 560)

$start = GUICtrlCreatePic($file_path & "\start.bmp", 664, 512, 140, 33)
_GUICtrl_SetOnHover(-1, "_hover", "_normal", "_clicked", "_normal")

$stop = GUICtrlCreatePic($file_path & "\stop.bmp", 520, 512, 140, 33)
_GUICtrl_SetOnHover(-1, "_hover", "_normal", "_clicked", "_normal")

$save = GUICtrlCreatePic($file_path & "\save.bmp", 376, 512, 140, 33)
_GUICtrl_SetOnHover(-1, "_hover", "_normal", "_clicked", "_normal")

$about = GUICtrlCreatePic($file_path & "\about.bmp", 232, 512, 140, 33)
_GUICtrl_SetOnHover(-1, "_normal", "_normal", "_clicked", "_normal")

GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func _hover($iCtrlID)
    Switch $iCtrlID
        Case $start
            GUICtrlSetImage($iCtrlID, $file_path & "\start.bmp")
        Case $stop
            GUICtrlSetImage($iCtrlID, $file_path & "\stop.bmp")
        Case $save
            GUICtrlSetImage($iCtrlID, $file_path & "\save.bmp")
        Case $about
            GUICtrlSetImage($iCtrlID, $file_path & "\about.bmp")
    EndSwitch
EndFunc

Func _clicked($iCtrlID)
    Switch $iCtrlID
        Case $start
            GUICtrlSetImage($iCtrlID, $file_path & "\start_click.bmp")
        Case $stop
            GUICtrlSetImage($iCtrlID, $file_path & "\stop_click.bmp")
        Case $save
            GUICtrlSetImage($iCtrlID, $file_path & "\save_click.bmp")
        Case $about
            GUICtrlSetImage($iCtrlID, $file_path & "\about_click.bmp")
    EndSwitch
EndFunc

Share this post


Link to post
Share on other sites
notsure

Hmm, since i downloaded the latest version of autoit this UDF seems not to work anymore.

I get the following error in the GuiCtrlSetOnHover_UDF:

GUICtrlSetOnHover_UDF.au3(15,107) : ERROR: Opt() called with illegal argument 1: "OnExitFunc"
Global $__GUICtrl_SetOnHover_sOriginal_OnExitFunc   = Opt("OnExitFunc", "__GUICtrl_SetOnHover_OnAutoItExit")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

Anyone?

Edited by notsure

Share this post


Link to post
Share on other sites
Yoriz

I altered mine to work as below.

;~ Global $__GUICtrl_SetOnHover_sOriginal_OnExitFunc    = Opt("OnExitFunc", "__GUICtrl_SetOnHover_OnAutoItExit")
OnAutoItExitRegister("__GUICtrl_SetOnHover_ReleaseResources_Proc")

this bit might or might not need changing, not sure if i changed this or it was like this already.

;Release resources function
Func __GUICtrl_SetOnHover_ReleaseResources_Proc()
    If $__GUICtrl_SetOnHover_pTimerProc > 0 Then DllCallbackFree($__GUICtrl_SetOnHover_pTimerProc)
    If $__GUICtrl_SetOnHover_iTimerID > 0 Then _
        DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "int", $__GUICtrl_SetOnHover_iTimerID)

    GUIRegisterMsg($__GUICtrl_SetOnHover_WM_COMMAND, "")
    GUIRegisterMsg($__GUICtrl_SetOnHover_WM_LBUTTONDOWN, "")

    $__GUICtrl_SetOnHover_pTimerProc = 0
    $__GUICtrl_SetOnHover_iTimerID = 0
EndFunc

;Release the CallBack resources when exit
;~ Func __GUICtrl_SetOnHover_OnAutoItExit()
;~  Call($__GUICtrl_SetOnHover_sOriginal_OnExitFunc)

;~  __GUICtrl_SetOnHover_ReleaseResources_Proc()
;~ EndFunc

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

Share this post


Link to post
Share on other sites
notsure

Nice, you pwn. thx

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  

×