Jump to content

Custom buttons with GDI+ [solved]


 Share

Recommended Posts

Greetings to everyone... while experimenting with GDI+, I ran into a bit of trouble.

CODE:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

; create variables and objects

_GDIPlus_Startup()

$gpsind0=_GDIPlus_ImageLoadFromFile("search.png")
$Form1 = GUICreate("A problem to solve", 150, 150)
$btn = GUICtrlCreateButton('Button', 10, 10, 90, 30)
GUISetState(@SW_SHOW)
$hGraphic=_GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($btn))

; main program code

_GDIPlus_GraphicsDrawImage($hGraphic,$gpsind0,0,0)
GUIRegisterMsg($WM_PAINT, "WM_ERASEBKGND")

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_GDIPlus_ImageDispose($gpsind0)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ShutDown()
Exit

Case $btn
msgbox(64, '', 'you clicked a button')

EndSwitch
WEnd

Func WM_ERASEBKGND()
_GDIPlus_GraphicsDrawImage($hGraphic,$gpsind0,0,0)
EndFunc

Well, the image disappears once the mouse hovers over the button (or when the button is clicked etc). Can someone please help me in this issue.

Also, could someone please guide me as how to change the image once the button is clicked, mouse hovered, button is pressed and so on...

Thank you for your time and invaluable guidance.

Regards,

MKISH

IMAGE ATTACHED BELOW:

Edited by MKISH

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Link to comment
Share on other sites

buttons are painted onhover - you see a blue focus rectangle

instead try with a label :)

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

:bye: I have already accomplished all this with a label using GUIRegisterMsg() and all, but what I am asking, is to do such things for a button control (like changing images on hover, mousedown, button press etc.).

Thank you for your time once again.

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Link to comment
Share on other sites

If you use _GUICtrlButton_SetImageList you can specify the image for every condition for a button. This might work for what you're trying to achieve. Or, there's a script in the Examples section that deals with button hover somewhere in the depths of that forum that might also be helpful.

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

Link to comment
Share on other sites

Try this:

#include <ButtonConstants.au3>
#include <Constants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
;~ #include <WindowsConstants.au3>;~~~

; create variables and objects

_GDIPlus_Startup()

$gpsind0 = _GDIPlus_ImageLoadFromFile("search.png")
$hHBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($gpsind0)
$Form1 = GUICreate("A problem to solve", 150, 150)
$btn = GUICtrlCreateButton('Button', 10, 10, 90, 30, $BS_BITMAP)
GUISetState(@SW_SHOW)
_WinAPI_DeleteObject(GUICtrlSendMsg($btn, $BM_SETIMAGE, $IMAGE_BITMAP, $hHBMP))


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GDIPlus_ImageDispose($gpsind0)
            _WinAPI_DeleteObject($hHBMP)
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit

        Case $btn
            MsgBox(64, '', 'you clicked a button')

    EndSwitch
WEnd

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

:guitar: @BrewManNH, that solves the problem.

@UEZ, nice trick once again... I'll remember that one.

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

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

×
×
  • Create New...