Jump to content

_GUICtrlButton_Create w/ $BS_SPLITBUTTON


 Share

Recommended Posts

last how can i disable the button? i tried GUICtrlSetState($btn, $GUI_DISABLE) but doesnt work :)

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

I got it! $btn = ($BN_DISABLE) thanks anyway ;)

Wahh now the problem is how to return it ENABLE ;)

Edited by eracross
Link to comment
Share on other sites

  • Moderators

eracross,

In this script, each button enables/disables the other - look for the <<<<<<<<<<<<<< lines:

#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3>

Global $hButton_1, $hButton_2, $hButton_1_Handle

_Main()

Func _Main()
    Local $hGUI

    $hGUI = GUICreate("Buttons", 400, 400)

    $hButton_1 = GUICtrlCreateButton("Initial 1", 10, 10, 120, 30, $BS_SPLITBUTTON)
    $hButton_1_Handle = GUICtrlGetHandle(-1)
    $hButton_2 = _GUICtrlButton_Create($hGUI, "Initial 1", 270, 10, 120, 30, $BS_SPLITBUTTON)
    _GUICtrlButton_SetSplitInfo($hButton_2) ; puts icon to left

    GUISetState()

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $hButton_1
                ConsoleWrite("Button 1 Pressed - " & GUICtrlRead($hButton_1) & @CRLF)
        EndSwitch
    WEnd

    Exit

EndFunc   ;==>_Main

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)

    #forceref $hWnd, $Msg, $wParam

    Local $tNMBHOTITEM = DllStructCreate("hwnd hWndFrom;int IDFrom;int Code;dword dwFlags", $lParam)
    Local $nNotifyCode = DllStructGetData($tNMBHOTITEM, "Code")
    ;Local $nID = DllStructGetData($tNMBHOTITEM, "IDFrom")
    Local $hCtrl = DllStructGetData($tNMBHOTITEM, "hWndFrom")
    ;Local $dwFlags = DllStructGetData($tNMBHOTITEM, "dwFlags")

    Switch $nNotifyCode
        Case $BCN_DROPDOWN
            _Popup_Menu($hCtrl)
    EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY

Func _Popup_Menu($hCtrl)

    Local Enum $iOption_1 = 1000, $iOption_2
    Local $hMenu = _GUICtrlMenu_CreatePopup()
    _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Disable", $iOption_1)
    _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Enable", $iOption_2)
    Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $hCtrl, -1, -1, 1, 1, 2)
        Case $iOption_1
            Switch $hCtrl
                Case $hButton_1_Handle
                    ConsoleWrite("Button 1 - Option 1" & @CRLF)
                    GUICtrlSetData($hButton_1, "Option 1")
                    _GUICtrlButton_Enable($hButton_2, False) ; <<<<<<<<<<<<<<<<<<<<<<<<
                Case $hButton_2
                    ConsoleWrite("Button 2 - Option 1" & @CRLF)
                    _GUICtrlButton_SetText($hButton_2, "Option 1")
                    GUICtrlSetState($hButton_1, $GUI_DISABLE) ; <<<<<<<<<<<<<<<<<<<<<<<<
            EndSwitch
        Case $iOption_2
            Switch $hCtrl
                Case $hButton_1_Handle
                    ConsoleWrite("Button 1 - Option 2" & @CRLF)
                    GUICtrlSetData($hButton_1, "Option 2")
                    _GUICtrlButton_Enable($hButton_2, True) ; <<<<<<<<<<<<<<<<<<<<<<<<
                Case $hButton_2
                    ConsoleWrite("Button 2 - Option 2" & @CRLF)
                    _GUICtrlButton_SetText($hButton_2, "Option 2")
                    GUICtrlSetState($hButton_1, $GUI_ENABLE) ; <<<<<<<<<<<<<<<<<<<<<<<<
            EndSwitch
    EndSwitch
    _GUICtrlMenu_DestroyMenu($hMenu)

EndFunc   ;==>_Popup_Menu

; React on a button click
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)

    #forceref $hWnd, $Msg

    Local $nNotifyCode = BitShift($wParam, 16)
    ;Local $nID = BitAND($wParam, 0x0000FFFF)
    Local $hCtrl = $lParam
    Local $sText = ""
    Switch $hCtrl
        Case $hButton_2
            Switch $nNotifyCode
                Case $BN_CLICKED
                    $sText = "Button 2 Clicked - " & _GUICtrlButton_GetText($hButton_2)
            EndSwitch
    EndSwitch

    If $sText <> "" Then ConsoleWrite($sText & @CRLF)

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_COMMAND

All clear? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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...