Jump to content

PNG Button Active


lowbred
 Share

Recommended Posts

Hello

I'm trying to implement a toggle effect when a button is clicked. I have successfully created a button using MrCreatoR's GUICtrlOnHover and its function. What I would like visually is the ($button1) to stay active until ($button2) is clicked. I tried all day yesterday trying ideas from examples in the forum, including MrCreatoR's examples and GUICtrlCreateCheckbox without success. Would I need another function or can it be within the same? Maybe another Switch?

Func PrimaryDown_Proc($iCtrlID)
    Switch $iCtrlID
        Case $Button1
            SendImageToPicControl("done_active.png", $Button1)

;???????????????????????????????

    EndSwitch
EndFunc
Edited by lowbred
Link to comment
Share on other sites

Here is what I have so far. It's an awful hack job but kinda gives the effect I want... Only that when I hover over button1 it goes back to normal.

#include <GUIConstantsEx.au3>
#include <ColorConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIGdi.au3>
#include <ButtonConstants.au3>
#include <GUICtrlOnHover.au3>
#include <GDIPlus.au3>

_GDIPlus_Startup()

Local $hGUI = GUICreate("Example", 500, 250)
GUICtrlCreatePic("background.jpg", 0, 0, 0, 0)
GUICtrlSetState(-1, $GUI_DISABLE)

$Button1 = GUICtrlCreatePic('', 0, 0, 0, 0)
_GUICtrl_OnHoverRegister(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")
SendImageToPicControl("done_normal.png", $Button1)

$Button2 = GUICtrlCreatePic('', 0, 100, 0, 0)
_GUICtrl_OnHoverRegister(-1, "_Hover_Proc2", "_Leave_Hover_Proc2", "PrimaryDown_Proc2", "PrimaryUp_Proc2")
SendImageToPicControl("done_normal2.png", $Button2)

GUISetState(@SW_SHOW, $hGUI)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $Button1
                HotKeySet("{1}", "sendit")
                HotKeySet("{2}", "sendit2")
                Sleep (400)
                SendImageToPicControl("done_active.png", $Button1)

            Case $Button2
                HotKeySet("{1}")
                HotKeySet("{2}")
                SendImageToPicControl("done_normal.png", $Button1)

       EndSwitch
    WEnd

    GUIDelete($hGUI)


Func sendit()
    Send (".jpg")
EndFunc

Func sendit2()
    Send (".png")
EndFunc

Func SendImageToPicControl($sImage, $iCtrlID)
    Local Const $hImage = _GDIPlus_ImageLoadFromFile($sImage)
    Local Const $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _WinAPI_DeleteObject(GUICtrlSendMsg($iCtrlID, 0x0172, $IMAGE_BITMAP, $hHBitmap))
    _WinAPI_DeleteObject($hHBitmap)
    _GDIPlus_ImageDispose($hImage)
EndFunc   ;==>SendImageToPicControl

;;;;;;;;;;;;;;;;;;;;;;;;;;PNG Button 1;;;;;;;;;;;;;;;;;;;;;;;;;;
Func _Hover_Proc($iCtrlID)
    Switch $iCtrlID
        Case $Button1
            SendImageToPicControl("done_pressed.png", $Button1)
    EndSwitch
EndFunc   ;==>_Hover_Proc

Func _Leave_Hover_Proc($iCtrlID)
    Switch $iCtrlID
        Case $Button1
            SendImageToPicControl("done_normal.png", $Button1)
    EndSwitch
EndFunc   ;==>_Leave_Hover_Proc

Func PrimaryDown_Proc($iCtrlID)
    Switch $iCtrlID
        Case $Button1
        SendImageToPicControl("done_active.png", $Button1)
    EndSwitch
EndFunc   ;==>PrimaryDown_Proc

Func PrimaryUp_Proc($iCtrlID)
    Switch $iCtrlID
        Case $Button1
            SendImageToPicControl("done_pressed.png", $Button1)
    EndSwitch
EndFunc   ;==>PrimaryUp_Proc
;;;;;;;;;;;;;;;;;;;;;;;;;;PNG Button 1;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;PNG Button 2;;;;;;;;;;;;;;;;;;;;;;;;;;
Func _Hover_Proc2($iCtrlID)
    Switch $iCtrlID
        Case $Button2
            SendImageToPicControl("done_pressed2.png", $Button2)
    EndSwitch
EndFunc   ;==>_Hover_Proc

Func _Leave_Hover_Proc2($iCtrlID)
    Switch $iCtrlID
        Case $Button2
            SendImageToPicControl("done_normal2.png", $Button2)
    EndSwitch
EndFunc   ;==>_Leave_Hover_Proc

Func PrimaryDown_Proc2($iCtrlID)
    Switch $iCtrlID
        Case $Button2
            SendImageToPicControl("done_active2.png", $Button2)
    EndSwitch
EndFunc   ;==>PrimaryDown_Proc

Func PrimaryUp_Proc2($iCtrlID)
    Switch $iCtrlID
        Case $Button2
            SendImageToPicControl("done_pressed2.png", $Button2)
    EndSwitch
EndFunc   ;==>PrimaryUp_Proc
;;;;;;;;;;;;;;;;;;;;;;;;;;PNG Button 2;;;;;;;;;;;;;;;;;;;;;;;;;;
Edited by lowbred
Link to comment
Share on other sites

You MVP's are gonna look at this and say to yourself, "Ah... Yeah, OK" but it's definitely working. Criticism and pointers are welcome. This is the best I could come up with to accomplish the functionality I initially hoped for... Well, about 98% of the functionality. There are two issues I would like to address, I'm sure I understand why they happen... Do...Until.

1. The GUI's window menu (restore, move, resize, minimize, maximize, close) appears just above the taskbar when button1 is "enabled" and the GUI is minimized.

2. When button1 is "enabled" the window close button does not work.

This is my first GUI ever and it will be nothing more than an autotyper. I'm calling it "AutoIType", how original, eh? I will be using it with my HEX editor, Word and I'm sure I will find other useful implications. Overall, I'm happy thus far with it but like i said, criticism and pointers are welcome.

#include <GUIConstantsEx.au3>
#include <ColorConstants.au3>
#include <WindowsConstants.au3>
#include <GUICtrlOnHover.au3>
#include <GDIPlus.au3>
#include <SendMessage.au3>

_GDIPlus_Startup()

HotKeySet("{ESC}", "On_Exit")

Global Const $SC_DRAGMOVE = 0xF012

Local $hGUI = GUICreate("AutoIType", 500, 250)
GUICtrlCreatePic("background.jpg", 0, 0, 0, 0)
GUICtrlSetState(-1, $GUI_DISABLE)

$Button1 = GUICtrlCreatePic('', 0, 0, 142, 62)
_GUICtrl_OnHoverRegister(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")
SendImageToPicControl("normal_1.png", $Button1)

$Button2 = GUICtrlCreatePic('', 0, 80, 142, 62)
_GUICtrl_OnHoverRegister(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")
SendImageToPicControl("normal_1.png", $Button2)

Local $sFont = "Comic Sans MS"
GUISetFont(9, 400, "", $sFont)
GUICtrlSetDefColor($COLOR_White)

Local $idLabel = GUICtrlCreateLabel("PNG = 1", 250, 40)
GUICtrlSetBkColor($idLabel, $GUI_BKCOLOR_TRANSPARENT)
;GUICtrlSetColor($idLabel, $COLOR_RED)
Local $idLabel = GUICtrlCreateLabel("JPG = 2", 250, 60)
GUICtrlSetBkColor($idLabel, $GUI_BKCOLOR_TRANSPARENT)

GUISetState(@SW_SHOW, $hGUI)

GUIRegisterMsg($WM_COMMAND, "Killswitch")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE ;, $Button3
            ExitLoop

        Case $GUI_EVENT_PRIMARYDOWN
            _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)

        Case $Button1
            HotKeySet("{1}", "sendit")
            HotKeySet("{2}", "sendit2")
            Do
                _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
                ;Sleep(25)
                SendImageToPicControl("enabled_1.png", $Button1)
            Until GUIGetMsg() = $Button1
            SendImageToPicControl("normal_1.png", $Button1)
            HotKeySet("{1}")
            HotKeySet("{2}")
    EndSwitch
WEnd

_GDIPlus_Shutdown()
GUIDelete($hGUI)

Func On_Exit()
    Exit
EndFunc   ;==>On_Exit

Func sendit()
    Send(".png")
EndFunc   ;==>sendit

Func sendit2()
    Send(".jpg")
EndFunc   ;==>sendit2

Func Killswitch($hWnd, $Msg, $wParam, $lParam)
    Switch BitAND($wParam, 0x0000FFFF)
        Case $Button2
            Sleep(300)
            Exit
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>Killswitch

Func SendImageToPicControl($sImage, $iCtrlID)
    Local Const $hImage = _GDIPlus_ImageLoadFromFile($sImage)
    Local Const $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _WinAPI_DeleteObject(GUICtrlSendMsg($iCtrlID, 0x0172, $IMAGE_BITMAP, $hHBitmap))
    _WinAPI_DeleteObject($hHBitmap)
    _GDIPlus_ImageDispose($hImage)
EndFunc   ;==>SendImageToPicControl


Func _Hover_Proc($iCtrlID)
    Switch $iCtrlID
        Case $Button1
            SendImageToPicControl("hover_1.png", $Button1)
        Case $Button2
            SendImageToPicControl("hover_1.png", $Button2)
    EndSwitch
EndFunc   ;==>_Hover_Proc

Func _Leave_Hover_Proc($iCtrlID)
    Switch $iCtrlID
        Case $Button1
            SendImageToPicControl("normal_1.png", $Button1)
        Case $Button2
            SendImageToPicControl("normal_1.png", $Button2)
    EndSwitch
EndFunc   ;==>_Leave_Hover_Proc

Func PrimaryDown_Proc($iCtrlID)
    Switch $iCtrlID
        Case $Button1
            SendImageToPicControl("pressed_1.png", $Button1)
        Case $Button2
            SendImageToPicControl("pressed_1.png", $Button2)
    EndSwitch
EndFunc   ;==>PrimaryDown_Proc

Func PrimaryUp_Proc($iCtrlID)
    Switch $iCtrlID
        Case $Button1
            SendImageToPicControl("enabled_1.png", $Button1)
        Case $Button2
            SendImageToPicControl("enabled_1.png", $Button2)
    EndSwitch
EndFunc   ;==>PrimaryUp_Proc
Edited by lowbred
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...