Jump to content
Sign in to follow this  

[SOLVED] Nice GUI Button - Click Handle

Recommended Posts

This function which creates a nice looking button even if windows has a 'classic' visual appearance.

The button is composed of an image and a label (with transparent background) on top.

I'm having issues where depending where I put the button.

I'm unable to get the click GUI msg from it.

If I set the image state to ($GUI_ONTOP + $GUI_SHOW)

Then it works wherever I put the button, but then the image is not visible and I only see the label

I've got some buttons lower down ontop of a window background image. I set the state of the window

s background image to $GUI_DISABLE, then they work fine, But I've still got another button in the middle of the form that doesn't give its GUI event ID.

Any Ideas?

Func CreateNiceButton($caption,$x,$y,Byref $h_btnlbl)
    ;returns handle for 'button' which is actually an image
    ;Requires _GDIPlus_Startup (), #include <ButtonConstants.au3>, #include <StaticConstants.au3>
    Local $h_btnimg=GUICtrlCreatePic($depfile_ButtonImage,$x,$y,$width_nicebtnimg,$height_nicebtnimg)
    $h_btnlbl = GUICtrlCreateLabel($caption, $x, $y, $width_nicebtnimg,$height_nicebtnimg,BitOR($SS_CENTER,$BS_CENTER))
    GUICtrlSetBkColor($h_btnlbl, $GUI_BKCOLOR_TRANSPARENT)
    Return $h_btnimg
Edited by Lope

Share this post

Link to post
Share on other sites

Maybe this is what you're looking for:

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

$Form1 = GUICreate("Form1", 278, 153)

$Pic1 = GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\msoobe.jpg", 0, 2, 276, 148)
GUICtrlSetState(-1, $GUI_DISABLE)

$Pic2 = GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\Advanced\Images\Green.bmp", 80, 48, 132, 44)
GUICtrlSetState(-1, $GUI_DISABLE)

$Label1 = GUICtrlCreateLabel("Click me!", 80, 48, 132, 44, BitOR($SS_CENTER,$SS_CENTERIMAGE))


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
        Case $Pic2, $Label1
            MsgBox(0,"Yep!","There it is!")

Share this post

Link to post
Share on other sites

Thank you... helped me solve it.

Another problem is I was drawing a label AFTER the button, which I should have drawn before.

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.

  • Create New...