Jump to content
Sign in to follow this  
newsak2005

OneTouchButton

Recommended Posts

newsak2005

OneTouchButton

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

$hForm = GUICreate("OneTouchButton", 308, 95, -1, -1)
$Button = GUICtrlCreateButton("Button1", 112, 56, 75, 25, $WS_GROUP)
GUICtrlSetCursor(-1, 0)
$Label = GUICtrlCreateLabel("Clicked Report", 110, 16, 100, 17)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            If $nMsg = $Button Then
                GUICtrlSetData($Label, "You Clicked..Button1")
                GUISetBkColor(0xFF0000)
                GUICtrlSetData($Button, "Button2") ;add statement1 here.
                While 1
                    $msg = GUIGetMsg()
                    If $msg = -3 Then Exit
                    If $msg = $Button Then
                        GUICtrlSetData($Label, "You Clicked..Button2")
                        GUISetBkColor(0x00FF00)
                        GUICtrlSetData($Button, "Button3") ;add statement2 here.
                        ExitLoop
                    EndIf
                WEnd
                Do
                    $msg = GUIGetMsg()
                    If $msg = -3 Then Exit
                    If $msg = $Button Then
                        GUICtrlSetData($Label, "You Clicked..Button3")
                        GUISetBkColor(0x0000FF)
                        GUICtrlSetData($Button, "Button1") ;add statement3 here.
                        ExitLoop
                    EndIf
                Until False
            EndIf
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites
Melba23

newsak2005,

Simpler to use a Switch to do this: :mellow:

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

$hForm = GUICreate("OneTouchButton", 308, 95, -1, -1)
$Button = GUICtrlCreateButton("Button 1", 112, 56, 75, 25)
$Label = GUICtrlCreateLabel("Clicked Report", 90, 16, 110, 17, $SS_CENTER)
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            Switch GUICtrlRead($Button)
                Case "Button 1"
                    GUICtrlSetData($Label, "You Clicked..Button 1 ")
                    GUISetBkColor(0xFFCCCC)
                    GUICtrlSetData($Button, "Button 2")
                Case "Button 2"
                    GUICtrlSetData($Label, "You Clicked..Button 2")
                    GUISetBkColor(0xCCFFCC)
                    GUICtrlSetData($Button, "Button 3")
                Case "Button 3"
                    GUICtrlSetData($Label, "You Clicked..Button 3")
                    GUISetBkColor(0xCCCCFF)
                    GUICtrlSetData($Button, "Button 1")
            EndSwitch
    EndSwitch
WEnd

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
newsak2005

Use Select Case.

Melba23. Borrowing the idea of.........

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

$hForm = GUICreate("OneTouchButton", 308, 95, -1, -1)
$Button = GUICtrlCreateButton("Button 1", 112, 56, 75, 25)
$Label = GUICtrlCreateLabel("Clicked Report", 90, 16, 110, 17, $SS_CENTER)
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            $iButton = GUICtrlRead($Button)
            Select
                Case $iButton="Button 1"
                    GUICtrlSetData($Label, "You Clicked..Button 1 ")
                    GUISetBkColor(0xFFCCCC)
                    GUICtrlSetData($Button, "Button 2")
                Case $iButton="Button 2"
                    GUICtrlSetData($Label, "You Clicked..Button 2")
                    GUISetBkColor(0xCCFFCC)
                    GUICtrlSetData($Button, "Button 3")
                Case $iButton="Button 3"
                    GUICtrlSetData($Label, "You Clicked..Button 3")
                    GUISetBkColor(0xCCCCFF)
                    GUICtrlSetData($Button, "Button 1")
            EndSelect
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites
newsak2005

Use include GuiButton.au3 With _GUICtrlButton_GetText()

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

$hForm = GUICreate("OneTouchButton", 308, 95, -1, -1)
$Button = GUICtrlCreateButton("Button 1", 112, 56, 75, 25)
$Label = GUICtrlCreateLabel("Clicked Report", 90, 16, 110, 17, $SS_CENTER)
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            Switch _GUICtrlButton_GetText($Button)
                Case "Button 1"
                    GUICtrlSetData($Label, "You Clicked.."& _GUICtrlButton_GetText($Button))
                    GUISetBkColor(0xFFCCCC)
                    GUICtrlSetData($Button, "Button 2")
                Case "Button 2"
                    GUICtrlSetData($Label, "You Clicked.."& _GUICtrlButton_GetText($Button))
                    GUISetBkColor(0xCCFFCC)
                    GUICtrlSetData($Button, "Button 3")
                Case "Button 3"
                    GUICtrlSetData($Label, "You Clicked.."& _GUICtrlButton_GetText($Button))
                    GUISetBkColor(0xCCCCFF)
                    GUICtrlSetData($Button, "Button 1")
            EndSwitch
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites
newsak2005

Use Library Include

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

$hForm = GUICreate("OneTouchButton", 308, 95, -1, -1)
$Button = GUICtrlCreateButton("Button 1", 112, 56, 75, 25)
$Label = GUICtrlCreateLabel("Clicked Report", 90, 16, 110, 17, $SS_CENTER)
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            Switch GUICtrlButton_GetText($Button)
                Case "Button 1"
                    GUICtrlSetData($Label, "You Clicked.."& GUICtrlButton_GetText($Button))
                    GUISetBkColor(0xFFCCCC)
                    GUICtrlSetData($Button, "Button 2")
                Case "Button 2"
                    GUICtrlSetData($Label, "You Clicked.."& GUICtrlButton_GetText($Button))
                    GUISetBkColor(0xCCFFCC)
                    GUICtrlSetData($Button, "Button 3")
                Case "Button 3"
                    GUICtrlSetData($Label, "You Clicked.."& GUICtrlButton_GetText($Button))
                    GUISetBkColor(0xCCCCFF)
                    GUICtrlSetData($Button, "Button 1")
            EndSwitch
    EndSwitch
WEnd

Func GUICtrlButton_GetText($hWnd)
    If $Debug_Btn Then __UDF_ValidateClassName($hWnd, $__BUTTONCONSTANT_ClassName)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    If WinAPI_IsClassName($hWnd, $__BUTTONCONSTANT_ClassName) Then Return WinAPI_GetWindowText($hWnd)
    Return ""
EndFunc

Func WinAPI_IsClassName($hWnd, $sClassName)
    Local $sSeparator = Opt("GUIDataSeparatorChar")
    Local $aClassName = StringSplit($sClassName, $sSeparator)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    Local $sClassCheck = WinAPI_GetClassName($hWnd)
    For $x = 1 To UBound($aClassName) - 1
        If StringUpper(StringMid($sClassCheck, 1, StringLen($aClassName[$x]))) = StringUpper($aClassName[$x]) Then Return True
    Next
    Return False
EndFunc

Func WinAPI_GetWindowText($hWnd)
    Local $aResult = DllCall("user32.dll", "int", "GetWindowTextW", "hwnd", $hWnd, "wstr", "", "int", 4096)
    If @error Then Return SetError(@error, @extended, "")
    Return SetExtended($aResult[0], $aResult[2])
EndFunc

Func WinAPI_GetClassName($hWnd)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    Local $aResult = DllCall("user32.dll", "int", "GetClassNameW", "hwnd", $hWnd, "wstr", "", "int", 4096)
    If @error Then Return SetError(@error, @extended, False)
    Return SetExtended($aResult[0], $aResult[2])
EndFunc

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.