Jump to content

One default button per tabsheet


Recommended Posts

Is there a way to have 1 default button per tabsheet?

currently it just makes the last button with the $BS_DEFPUSHBUTTON style the default for the whole form.

sorry if this has been asked before i did a quick search but wasn't sure of the wording to use and didn't find any results that answered my question.

Thanks

Link to comment
Share on other sites

I would change $BS_DEFPUSHBUTTON style of buttons according to active TabSheet selection.

Look here how to catch $TCN_SELCHANGE notification - when Tab selection changes

http://www.autoitscript.com/forum/index....owtopic=72894&st=0&p=531772&#entry531772

Edited by Zedna
Link to comment
Share on other sites

  • 4 weeks later...

I would change $BS_DEFPUSHBUTTON style of buttons according to active TabSheet selection.

Look here how to catch $TCN_SELCHANGE notification - when Tab selection changes

http://www.autoitscript.com/forum/index....owtopic=72894&st=0&p=531772&#entry531772

i tried something to that nature except i used _GUICtrlTab_GetCurFocus($tab) to determine the tab then a guictrlsetstyle depending on the tab

it seemed to work like the button outlined like it was the default but when i hit enter nothing would happen

how would i build the guictrlsetstyle?

Link to comment
Share on other sites

  • Moderators

timan12,

I would do it this way:

#include <GUIConstantsEx.au3>
#Include <GuiTab.au3>

$dll = DllOpen("user32.dll")

Global $aTabButtons[3]

$hGUI = GUICreate("Test", 500, 500)

$tab = GUICtrlCreateTab(10, 10, 200, 100)
$tabhandle = GUICtrlGetHandle($tab)

$tab0 = GUICtrlCreateTabItem("tab 0")
$aTabButtons[0] = GUICtrlCreateButton("Button 0", 20, 50, 50, 20)

$tab1 = GUICtrlCreateTabItem("tab 1")
$aTabButtons[1] = GUICtrlCreateButton("Button 1", 20, 50, 50, 20)

$tab2 = GUICtrlCreateTabItem("tab 2")
$aTabButtons[2] = GUICtrlCreateButton("Button 2", 20, 50, 50, 20)

GUISetState()

$iCurrIndex = 0

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $aTabButtons[0]
            _Pressed(0)
        Case $aTabButtons[1]
            _Pressed(1)
        Case $aTabButtons[2]
            _Pressed(2)
    EndSwitch

    $iIndex = _GUICtrlTab_GetCurFocus($tabhandle)
    If $iIndex <> $iCurrIndex Then
        $iCurrIndex = $iIndex
        GUICtrlSetState($aTabButtons[$iIndex], $GUI_FOCUS)
    EndIf

WEnd

Func _Pressed($iIndex)
    ConsoleWrite("Hit" & @CRLF)
    MsgBox(0, "", "Button " & $iIndex & " pressed")
EndFunc

I hope this helps. :)

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

timan12,

I would do it this way:

#include <GUIConstantsEx.au3>
#Include <GuiTab.au3>

$dll = DllOpen("user32.dll")

Global $aTabButtons[3]

$hGUI = GUICreate("Test", 500, 500)

$tab = GUICtrlCreateTab(10, 10, 200, 100)
$tabhandle = GUICtrlGetHandle($tab)

$tab0 = GUICtrlCreateTabItem("tab 0")
$aTabButtons[0] = GUICtrlCreateButton("Button 0", 20, 50, 50, 20)

$tab1 = GUICtrlCreateTabItem("tab 1")
$aTabButtons[1] = GUICtrlCreateButton("Button 1", 20, 50, 50, 20)

$tab2 = GUICtrlCreateTabItem("tab 2")
$aTabButtons[2] = GUICtrlCreateButton("Button 2", 20, 50, 50, 20)

GUISetState()

$iCurrIndex = 0

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $aTabButtons[0]
            _Pressed(0)
        Case $aTabButtons[1]
            _Pressed(1)
        Case $aTabButtons[2]
            _Pressed(2)
    EndSwitch

    $iIndex = _GUICtrlTab_GetCurFocus($tabhandle)
    If $iIndex <> $iCurrIndex Then
        $iCurrIndex = $iIndex
        GUICtrlSetState($aTabButtons[$iIndex], $GUI_FOCUS)
    EndIf

WEnd

Func _Pressed($iIndex)
    ConsoleWrite("Hit" & @CRLF)
    MsgBox(0, "", "Button " & $iIndex & " pressed")
EndFunc

I hope this helps. :)

M23

that is very close but the problem is when i got to type in the txt box the go becomes not the default button anymore

and when i hit enter nothing happens

Link to comment
Share on other sites

#Include <GUIConstantsEx.au3>

$hForm = GUICreate('MyGUI', 400, 400)
GUISetFont(8.5, 400, 0, 'MS Shell Dlg', $hForm)
$Tab = GUICtrlCreateTab(10, 10, 380, 380)
GUICtrlCreateTabItem('Tab1')
GUICtrlCreateEdit('Test1', 28, 48, 342, 298)
$Button1 = GUICtrlCreateButton('Button1', 165, 355, 70, 23)
GUICtrlSetState(-1, BitOR($GUI_DEFBUTTON, $GUI_FOCUS))
GUICtrlCreateTabItem('Tab2')
GUICtrlCreateEdit('Test2', 28, 48, 342, 298)
$Button2 = GUICtrlCreateButton('Button1', 165, 355, 70, 23)
GUICtrlCreateTabItem('')
GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Tab
            Switch GUICtrlRead($Tab)
                Case 0
                    $CtrlID = $Button1
                Case 1
                    $CtrlID = $Button2
            EndSwitch
            GUICtrlSetState($CtrlID, $GUI_DEFBUTTON)
            GUICtrlSetState($Tab, $GUI_FOCUS)
    EndSwitch
WEnd

Link to comment
Share on other sites

  • Moderators

tlman12,

If you do not ask the right question, you will not get the right answer. You had not mentioned input boxes! :)

Try this:

#include <GUIConstantsEx.au3>
#Include <GuiTab.au3>
#include <Misc.au3>

$dll = DllOpen("user32.dll")

Global $aTabButtons[3]

$hGUI = GUICreate("Test", 500, 500)

$tab = GUICtrlCreateTab(10, 10, 200, 100)
$tabhandle = GUICtrlGetHandle($tab)

$tab0 = GUICtrlCreateTabItem("tab 0")
$aTabButtons[0] = GUICtrlCreateButton("Button 0", 20, 50, 50, 20)
$hInput_0 = GUICtrlCreateInput("", 20, 80, 150, 20)

$tab1 = GUICtrlCreateTabItem("tab 1")
$aTabButtons[1] = GUICtrlCreateButton("Button 1", 20, 50, 50, 20)
$hInput_1 = GUICtrlCreateInput("", 50, 80, 150, 20)

$tab2 = GUICtrlCreateTabItem("tab 2")
$aTabButtons[2] = GUICtrlCreateButton("Button 2", 20, 50, 50, 20)
$hInput_2 = GUICtrlCreateInput("", 20, 80, 150, 20)

GUISetState()

$iCurrIndex = 0

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $aTabButtons[0]
            _Pressed(0)
        Case $aTabButtons[1]
            _Pressed(1)
        Case $aTabButtons[2]
            _Pressed(2)
    EndSwitch

    $iIndex = _GUICtrlTab_GetCurFocus($tabhandle)
    If $iIndex <> $iCurrIndex Then
        $iCurrIndex = $iIndex
        GUICtrlSetState($aTabButtons[$iIndex], $GUI_FOCUS)
    EndIf

    If _IsPressed("0D", $dll) Then _Pressed($iCurrIndex)

WEnd

Func _Pressed($iIndex)
    ConsoleWrite("Hit" & @CRLF)
    MsgBox(0, "", "Button " & $iIndex & " pressed")
EndFunc

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

tlman12,

If you do not ask the right question, you will not get the right answer. You had not mentioned input boxes! :)

Try this:

#include <GUIConstantsEx.au3>
#Include <GuiTab.au3>
#include <Misc.au3>

$dll = DllOpen("user32.dll")

Global $aTabButtons[3]

$hGUI = GUICreate("Test", 500, 500)

$tab = GUICtrlCreateTab(10, 10, 200, 100)
$tabhandle = GUICtrlGetHandle($tab)

$tab0 = GUICtrlCreateTabItem("tab 0")
$aTabButtons[0] = GUICtrlCreateButton("Button 0", 20, 50, 50, 20)
$hInput_0 = GUICtrlCreateInput("", 20, 80, 150, 20)

$tab1 = GUICtrlCreateTabItem("tab 1")
$aTabButtons[1] = GUICtrlCreateButton("Button 1", 20, 50, 50, 20)
$hInput_1 = GUICtrlCreateInput("", 50, 80, 150, 20)

$tab2 = GUICtrlCreateTabItem("tab 2")
$aTabButtons[2] = GUICtrlCreateButton("Button 2", 20, 50, 50, 20)
$hInput_2 = GUICtrlCreateInput("", 20, 80, 150, 20)

GUISetState()

$iCurrIndex = 0

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $aTabButtons[0]
            _Pressed(0)
        Case $aTabButtons[1]
            _Pressed(1)
        Case $aTabButtons[2]
            _Pressed(2)
    EndSwitch

    $iIndex = _GUICtrlTab_GetCurFocus($tabhandle)
    If $iIndex <> $iCurrIndex Then
        $iCurrIndex = $iIndex
        GUICtrlSetState($aTabButtons[$iIndex], $GUI_FOCUS)
    EndIf

    If _IsPressed("0D", $dll) Then _Pressed($iCurrIndex)

WEnd

Func _Pressed($iIndex)
    ConsoleWrite("Hit" & @CRLF)
    MsgBox(0, "", "Button " & $iIndex & " pressed")
EndFunc

M23

i tried using something along those lines but what would happen is if you click on another button then type something in the input box and hit enter it would hit both buttons (the one you wanted to be default, and the last button uses)

i know this is confusing and i'm thinking about dumping the default button altogeather and just make you have to click ok lol

Link to comment
Share on other sites

  • Moderators

tlman12,

what would happen is if you click on another button then type something in the input box and hit enter it would hit both buttons (the one you wanted to be default, and the last button uses)

Have you tried? :) Once you click in the input, the focus passes to the input - the last button pressed looses focus at this point. Then when you press Enter, it is as if you pressed the button you want as default. Try this and see:

#include <GUIConstantsEx.au3>
#Include <GuiTab.au3>
#include <Misc.au3>

$dll = DllOpen("user32.dll")

Global $aTabButtons[3]

$hGUI = GUICreate("Test", 500, 500)

$tab = GUICtrlCreateTab(10, 10, 200, 100)
$tabhandle = GUICtrlGetHandle($tab)

$tab0 = GUICtrlCreateTabItem("tab 0")
$aTabButtons[0] = GUICtrlCreateButton("Button 0", 20, 50, 50, 20)
$hInput_0 = GUICtrlCreateInput("", 20, 80, 150, 20)
GUICtrlCreateButton("Dummy", 100, 50, 50, 20)

$tab1 = GUICtrlCreateTabItem("tab 1")
$aTabButtons[1] = GUICtrlCreateButton("Button 1", 20, 50, 50, 20)
$hInput_1 = GUICtrlCreateInput("", 50, 80, 150, 20)
GUICtrlCreateButton("Dummy", 100, 50, 50, 20)

$tab2 = GUICtrlCreateTabItem("tab 2")
$aTabButtons[2] = GUICtrlCreateButton("Button 2", 20, 50, 50, 20)
$hInput_2 = GUICtrlCreateInput("", 20, 80, 150, 20)
GUICtrlCreateButton("Dummy", 100, 50, 50, 20)

GUISetState()

$iCurrIndex = 0

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $aTabButtons[0]
            _Pressed(0)
        Case $aTabButtons[1]
            _Pressed(1)
        Case $aTabButtons[2]
            _Pressed(2)
    EndSwitch

    $iIndex = _GUICtrlTab_GetCurFocus($tabhandle)
    If $iIndex <> $iCurrIndex Then
        $iCurrIndex = $iIndex
        GUICtrlSetState($aTabButtons[$iIndex], $GUI_FOCUS)
    EndIf

    If _IsPressed("0D", $dll) Then _Pressed($iCurrIndex)

WEnd

Func _Pressed($iIndex)
    ConsoleWrite("Hit" & @CRLF)
    MsgBox(0, "", "Button " & $iIndex & " pressed")
EndFunc

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

I would do this:

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


$hGUI = GUICreate("Test", 500, 500)

$_DEFPUSHBUTTON = GUICtrlCreateButton("", -100, -100, 1,1, $BS_DEFPUSHBUTTON)

$tab = GUICtrlCreateTab(10, 10, 200, 100)
$tabhandle = GUICtrlGetHandle($tab)

$tab0 = GUICtrlCreateTabItem("tab 0")
$iTabButton0 = GUICtrlCreateButton("Button 0", 20, 50, 50, 20)
$hInput_0 = GUICtrlCreateInput("", 20, 80, 150, 20)
GUICtrlCreateButton("Dummy", 100, 50, 50, 20)

$tab1 = GUICtrlCreateTabItem("tab 1")
$iTabButton1 = GUICtrlCreateButton("Button 1", 20, 50, 50, 20)
$hInput_1 = GUICtrlCreateInput("", 50, 80, 150, 20)
GUICtrlCreateButton("Dummy", 100, 50, 50, 20)

$tab2 = GUICtrlCreateTabItem("tab 2")
$iTabButton2 = GUICtrlCreateButton("Button 2", 20, 50, 50, 20)
$hInput_2 = GUICtrlCreateInput("", 20, 80, 150, 20)
GUICtrlCreateButton("Dummy", 100, 50, 50, 20)

GUISetState()

$iCurrIndex = 0

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $iTabButton0, $iTabButton1, $iTabButton2
            _Pressed($nMsg)
        Case $_DEFPUSHBUTTON
            Switch GUICtrlRead($tab, 1)
                Case $tab0
                    _Pressed($iTabButton0)
                Case $tab1
                    _Pressed($iTabButton1)
                Case $tab2
                    _Pressed($iTabButton2)
            EndSwitch
    EndSwitch

WEnd

Func _Pressed($iButton)
    ConsoleWrite("Hit" & @CRLF)
    MsgBox(0, "", "Button '" & GUICtrlRead($iButton) & "' pressed")
EndFunc

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

I would do this:

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


$hGUI = GUICreate("Test", 500, 500)

$_DEFPUSHBUTTON = GUICtrlCreateButton("", -100, -100, 1,1, $BS_DEFPUSHBUTTON)

$tab = GUICtrlCreateTab(10, 10, 200, 100)
$tabhandle = GUICtrlGetHandle($tab)

$tab0 = GUICtrlCreateTabItem("tab 0")
$iTabButton0 = GUICtrlCreateButton("Button 0", 20, 50, 50, 20)
$hInput_0 = GUICtrlCreateInput("", 20, 80, 150, 20)
GUICtrlCreateButton("Dummy", 100, 50, 50, 20)

$tab1 = GUICtrlCreateTabItem("tab 1")
$iTabButton1 = GUICtrlCreateButton("Button 1", 20, 50, 50, 20)
$hInput_1 = GUICtrlCreateInput("", 50, 80, 150, 20)
GUICtrlCreateButton("Dummy", 100, 50, 50, 20)

$tab2 = GUICtrlCreateTabItem("tab 2")
$iTabButton2 = GUICtrlCreateButton("Button 2", 20, 50, 50, 20)
$hInput_2 = GUICtrlCreateInput("", 20, 80, 150, 20)
GUICtrlCreateButton("Dummy", 100, 50, 50, 20)

GUISetState()

$iCurrIndex = 0

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $iTabButton0, $iTabButton1, $iTabButton2
            _Pressed($nMsg)
        Case $_DEFPUSHBUTTON
            Switch GUICtrlRead($tab, 1)
                Case $tab0
                    _Pressed($iTabButton0)
                Case $tab1
                    _Pressed($iTabButton1)
                Case $tab2
                    _Pressed($iTabButton2)
            EndSwitch
    EndSwitch

WEnd

Func _Pressed($iButton)
    ConsoleWrite("Hit" & @CRLF)
    MsgBox(0, "", "Button '" & GUICtrlRead($iButton) & "' pressed")
EndFunc

that worked perfectly thank you

Link to comment
Share on other sites

Alright that was working perfectly but then i tried to set the colors and it's causing the issue

i'm useing this to set the colors of the whole gui

GUICtrlSetDefColor($fcolor)

GUISetBkColor($mcolor)

GUICtrlSetDefBkColor($mcolor)

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <GUITab.au3>
$fcolor = 0xffffff
$color = 0x000000

$hGUI = GUICreate("Test", 500, 500)
GUICtrlSetDefColor($fcolor)
GUISetBkColor($color)
GUICtrlSetDefBkColor($color)
$_DEFPUSHBUTTON = GUICtrlCreateButton("", -100, -100, 1,1, $BS_DEFPUSHBUTTON)

$tab = GUICtrlCreateTab(10, 10, 200, 100)
_GUICtrlTab_SetBkColor($hGUI, $tab, $color)
$tabhandle = GUICtrlGetHandle($tab)

$tab0 = GUICtrlCreateTabItem("tab 0")
$iTabButton0 = GUICtrlCreateButton("Button 0", 20, 50, 50, 20)
$hInput_0 = GUICtrlCreateInput("", 20, 80, 150, 20)
$bdummy1 = GUICtrlCreateButton("Dummy1", 100, 50, 50, 20)

$tab1 = GUICtrlCreateTabItem("tab 1")
$iTabButton1 = GUICtrlCreateButton("Button 1", 20, 50, 50, 20)
$hInput_1 = GUICtrlCreateInput("", 50, 80, 150, 20)
$bdummy2 = GUICtrlCreateButton("Dummy2", 100, 50, 50, 20)

$tab2 = GUICtrlCreateTabItem("tab 2")
$iTabButton2 = GUICtrlCreateButton("Button 2", 20, 50, 50, 20)
$hInput_2 = GUICtrlCreateInput("", 20, 80, 150, 20)
$bdummy3 = GUICtrlCreateButton("Dummy3", 100, 50, 50, 20)

GUISetState()

$iCurrIndex = 0

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $iTabButton0, $iTabButton1, $iTabButton2
            _Pressed($nMsg)
        Case $_DEFPUSHBUTTON
            Switch GUICtrlRead($tab, 1)
                Case $tab0
                    _Pressed($iTabButton0)
                Case $tab1
                    _Pressed($iTabButton1)
                Case $tab2
                    _Pressed($iTabButton2)
            EndSwitch
        Case $bdummy1
            _Dummy($bdummy1)
        Case $bdummy2
            _Dummy($bdummy1)
        Case $bdummy3
            _Dummy($bdummy1)
    EndSwitch

WEnd

Func _Pressed($iButton)
    ConsoleWrite("Hit" & @CRLF)
    MsgBox(0, "", "Button '" & GUICtrlRead($iButton) & "' pressed")
EndFunc

Func _Dummy($ibutton)
    ConsoleWrite("Dummy" & @CRLF)
    MsgBox(0, "", "Dummy Button '" & GUICtrlRead($iButton) & "' pressed")
EndFunc

Func _GUICtrlTab_SetBkColor($hWnd, $hSysTab32, $sBkColor)
    Local $aTabPos = ControlGetPos($hWnd, "", $hSysTab32)

    Local $aTab_Rect = _GUICtrlTab_GetItemRect($hSysTab32, -1)

    GUICtrlCreateLabel("", $aTabPos[0], $aTabPos[1]+$aTab_Rect[3]+4, $aTabPos[2], $aTabPos[3]-$aTab_Rect[3] -4)
    GUICtrlSetBkColor(-1, $sBkColor)
    GUICtrlSetState(-1, $GUI_DISABLE)
EndFunc

if you click on one of the dummy buttons it'll always be that button when you hit enter unless you click another button or switch tabs

i know i'm probably makeing this more complicated then it should be but thank you all for your help

Link to comment
Share on other sites

Give focus back to the default button and you will be fine.

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <GUITab.au3>
$fcolor = 0xffffff
$color = 0x000000

$hGUI = GUICreate("Test", 500, 500)
GUICtrlSetDefColor($fcolor)
GUISetBkColor($color)
GUICtrlSetDefBkColor($color)
$_DEFPUSHBUTTON = GUICtrlCreateButton("", -100, -100, 1,1, $BS_DEFPUSHBUTTON)

$tab = GUICtrlCreateTab(10, 10, 200, 100)
_GUICtrlTab_SetBkColor($hGUI, $tab, $color)
$tabhandle = GUICtrlGetHandle($tab)

$tab0 = GUICtrlCreateTabItem("tab 0")
$iTabButton0 = GUICtrlCreateButton("Button 0", 20, 50, 50, 20)
$hInput_0 = GUICtrlCreateInput("", 20, 80, 150, 20)
$bdummy1 = GUICtrlCreateButton("Dummy1", 100, 50, 50, 20)

$tab1 = GUICtrlCreateTabItem("tab 1")
$iTabButton1 = GUICtrlCreateButton("Button 1", 20, 50, 50, 20)
$hInput_1 = GUICtrlCreateInput("", 50, 80, 150, 20)
$bdummy2 = GUICtrlCreateButton("Dummy2", 100, 50, 50, 20)

$tab2 = GUICtrlCreateTabItem("tab 2")
$iTabButton2 = GUICtrlCreateButton("Button 2", 20, 50, 50, 20)
$hInput_2 = GUICtrlCreateInput("", 20, 80, 150, 20)
$bdummy3 = GUICtrlCreateButton("Dummy3", 100, 50, 50, 20)

GUISetState()

$iCurrIndex = 0

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $iTabButton0, $iTabButton1, $iTabButton2
            _Pressed($nMsg)
        Case $_DEFPUSHBUTTON
            Switch GUICtrlRead($tab, 1)
                Case $tab0
                    _Pressed($iTabButton0)
                Case $tab1
                    _Pressed($iTabButton1)
                Case $tab2
                    _Pressed($iTabButton2)
            EndSwitch
        Case $bdummy1
            _Dummy($bdummy1)
            GUICtrlSetState($_DEFPUSHBUTTON,$GUI_FOCUS)
        Case $bdummy2
            _Dummy($bdummy1)
            GUICtrlSetState($_DEFPUSHBUTTON,$GUI_FOCUS)
        Case $bdummy3
            _Dummy($bdummy1)
            GUICtrlSetState($_DEFPUSHBUTTON,$GUI_FOCUS)
    EndSwitch

WEnd

Func _Pressed($iButton)
    ConsoleWrite("Hit" & @CRLF)
    MsgBox(0, "", "Button '" & GUICtrlRead($iButton) & "' pressed")
EndFunc

Func _Dummy($ibutton)
    ConsoleWrite("Dummy" & @CRLF)
    MsgBox(0, "", "Dummy Button '" & GUICtrlRead($iButton) & "' pressed")
EndFunc

Func _GUICtrlTab_SetBkColor($hWnd, $hSysTab32, $sBkColor)
    Local $aTabPos = ControlGetPos($hWnd, "", $hSysTab32)

    Local $aTab_Rect = _GUICtrlTab_GetItemRect($hSysTab32, -1)

    GUICtrlCreateLabel("", $aTabPos[0], $aTabPos[1]+$aTab_Rect[3]+4, $aTabPos[2], $aTabPos[3]-$aTab_Rect[3] -4)
    GUICtrlSetBkColor(-1, $sBkColor)
    GUICtrlSetState(-1, $GUI_DISABLE)
EndFunc
Link to comment
Share on other sites

Give focus back to the default button and you will be fine.

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <GUITab.au3>
$fcolor = 0xffffff
$color = 0x000000

$hGUI = GUICreate("Test", 500, 500)
GUICtrlSetDefColor($fcolor)
GUISetBkColor($color)
GUICtrlSetDefBkColor($color)
$_DEFPUSHBUTTON = GUICtrlCreateButton("", -100, -100, 1,1, $BS_DEFPUSHBUTTON)

$tab = GUICtrlCreateTab(10, 10, 200, 100)
_GUICtrlTab_SetBkColor($hGUI, $tab, $color)
$tabhandle = GUICtrlGetHandle($tab)

$tab0 = GUICtrlCreateTabItem("tab 0")
$iTabButton0 = GUICtrlCreateButton("Button 0", 20, 50, 50, 20)
$hInput_0 = GUICtrlCreateInput("", 20, 80, 150, 20)
$bdummy1 = GUICtrlCreateButton("Dummy1", 100, 50, 50, 20)

$tab1 = GUICtrlCreateTabItem("tab 1")
$iTabButton1 = GUICtrlCreateButton("Button 1", 20, 50, 50, 20)
$hInput_1 = GUICtrlCreateInput("", 50, 80, 150, 20)
$bdummy2 = GUICtrlCreateButton("Dummy2", 100, 50, 50, 20)

$tab2 = GUICtrlCreateTabItem("tab 2")
$iTabButton2 = GUICtrlCreateButton("Button 2", 20, 50, 50, 20)
$hInput_2 = GUICtrlCreateInput("", 20, 80, 150, 20)
$bdummy3 = GUICtrlCreateButton("Dummy3", 100, 50, 50, 20)

GUISetState()

$iCurrIndex = 0

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $iTabButton0, $iTabButton1, $iTabButton2
            _Pressed($nMsg)
        Case $_DEFPUSHBUTTON
            Switch GUICtrlRead($tab, 1)
                Case $tab0
                    _Pressed($iTabButton0)
                Case $tab1
                    _Pressed($iTabButton1)
                Case $tab2
                    _Pressed($iTabButton2)
            EndSwitch
        Case $bdummy1
            _Dummy($bdummy1)
            GUICtrlSetState($_DEFPUSHBUTTON,$GUI_FOCUS)
        Case $bdummy2
            _Dummy($bdummy1)
            GUICtrlSetState($_DEFPUSHBUTTON,$GUI_FOCUS)
        Case $bdummy3
            _Dummy($bdummy1)
            GUICtrlSetState($_DEFPUSHBUTTON,$GUI_FOCUS)
    EndSwitch

WEnd

Func _Pressed($iButton)
    ConsoleWrite("Hit" & @CRLF)
    MsgBox(0, "", "Button '" & GUICtrlRead($iButton) & "' pressed")
EndFunc

Func _Dummy($ibutton)
    ConsoleWrite("Dummy" & @CRLF)
    MsgBox(0, "", "Dummy Button '" & GUICtrlRead($iButton) & "' pressed")
EndFunc

Func _GUICtrlTab_SetBkColor($hWnd, $hSysTab32, $sBkColor)
    Local $aTabPos = ControlGetPos($hWnd, "", $hSysTab32)

    Local $aTab_Rect = _GUICtrlTab_GetItemRect($hSysTab32, -1)

    GUICtrlCreateLabel("", $aTabPos[0], $aTabPos[1]+$aTab_Rect[3]+4, $aTabPos[2], $aTabPos[3]-$aTab_Rect[3] -4)
    GUICtrlSetBkColor(-1, $sBkColor)
    GUICtrlSetState(-1, $GUI_DISABLE)
EndFunc

the only problem with that is that my gui currently has about 70 buttons would i have to add that to every button?

Edit: alright i tried it on a few of the buttons and although it worked in the small script for some reason it's not working in my larger one unfortuanatly because of it's content i cant release the source

it's composed of about 6 personaly written includes most the buttons run fuctions from these includes but its all pretty simple stuff

Edited by tlman12
Link to comment
Share on other sites

  • Moderators

timan12,

There is known bug in Autoit which means that coloured buttons wiil always trap the 'Enter' key regardless of the DEFPUSHBUTTON setting. So I am afraid it is normal buttons or picea892's idea. :)

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

timan12,

There is known bug in Autoit which means that coloured buttons wiil always trap the 'Enter' key regardless of the DEFPUSHBUTTON setting. So I am afraid it is normal buttons or picea892's idea. :)

M23

dam lol.. the same reason i couldn't color my tabs lol

you think this'll ever be fixed?

Link to comment
Share on other sites

  • Moderators

timan12,

According to this, never.

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

timan12,

According to this, never.

M23

i think i may have figured out a possible solution (atleas it works for me)

If WinActive("Test") Then
        If _IsPressed("0D") Then
            Sleep(250)
            $nMsg = GUIGetMsg()
            If $nMsg = $_DEFPUSHBUTTON Then
                $p = 1
            Else
                $nMsg = $_DEFPUSHBUTTON
                $p = 1
            EndIf
        Else
            $nMsg = GUIGetMsg()
            $p = 1
        EndIf
    EndIf

it's got a couple of kinks, it runs whatever the default function is twice the first time you push enter, on smaller gui's if you hit enter on a mesage box it returns back to the top of the loop faster then you can take your finger off the enter so it keeps looping but this isn't an issue for me cause my main loop is pretty large i put $p = # to control when it gets to go into the loop but it's not a surefire thing

Full Example

Dim $fcolor = 0xffffff
Dim $color = 0x000000
Dim $p = 1

$hGUI = GUICreate("Test", 500, 500)
GUICtrlSetDefColor($fcolor)
GUISetBkColor($color)
GUICtrlSetDefBkColor($color)
$_DEFPUSHBUTTON = GUICtrlCreateButton("", -100, -100, 1, 1, $BS_DEFPUSHBUTTON)
$tab = GUICtrlCreateTab(10, 10, 200, 100)
_GUICtrlTab_SetBkColor($hGUI, $tab, $color)
$tabhandle = GUICtrlGetHandle($tab)
$tab0 = GUICtrlCreateTabItem("tab 0")
$iTabButton0 = GUICtrlCreateButton("Button 0", 20, 50, 50, 20)
$hInput_0 = GUICtrlCreateInput("", 20, 80, 150, 20)
$bdummy1 = GUICtrlCreateButton("Dummy1", 100, 50, 50, 20)
$tab1 = GUICtrlCreateTabItem("tab 1")
$iTabButton1 = GUICtrlCreateButton("Button 1", 20, 50, 50, 20)
$hInput_1 = GUICtrlCreateInput("", 50, 80, 150, 20)
$bdummy2 = GUICtrlCreateButton("Dummy2", 100, 50, 50, 20)
$tab2 = GUICtrlCreateTabItem("tab 2")
$iTabButton2 = GUICtrlCreateButton("Button 2", 20, 50, 50, 20)
$hInput_2 = GUICtrlCreateInput("", 20, 80, 150, 20)
$bdummy3 = GUICtrlCreateButton("Dummy3", 100, 50, 50, 20)
GUISetState()
$iCurrIndex = 0


While 1

    If WinActive("Test") Then
        If _IsPressed("0D") Then
            Sleep(250)
            $nMsg = GUIGetMsg()
            If $nMsg = $_DEFPUSHBUTTON Then
                $p = 1
            Else
                $nMsg = $_DEFPUSHBUTTON
                $p = 1
            EndIf
        Else
            $nMsg = GUIGetMsg()
            $p = 1
        EndIf
    EndIf


If $p = 1 Then
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $iTabButton0, $iTabButton1, $iTabButton2
            _Pressed($nMsg)
        Case $_DEFPUSHBUTTON

                Switch GUICtrlRead($tab, 1)
                    Case $tab0
                        _Pressed($iTabButton0)
                    Case $tab1
                        _Pressed($iTabButton1)
                    Case $tab2
                        _Pressed($iTabButton2)
                EndSwitch
        Case $bdummy1
            _Dummy($bdummy1)
        Case $bdummy2
            _Dummy($bdummy1)
        Case $bdummy3
            _Dummy($bdummy1)
    EndSwitch
    $p = 0
EndIf
WEnd


Func _Pressed($iButton)
    ConsoleWrite("Hit" & @CRLF)
    MsgBox(0, "", "Button '" & GUICtrlRead($iButton) & "' pressed")
EndFunc   ;==>_Pressed
Func _Dummy($iButton)
    ConsoleWrite("Dummy" & @CRLF)
    MsgBox(0, "", "Dummy Button '" & GUICtrlRead($iButton) & "' pressed")
EndFunc   ;==>_Dummy
Func _GUICtrlTab_SetBkColor($hWnd, $hSysTab32, $sBkColor)
    Local $aTabPos = ControlGetPos($hWnd, "", $hSysTab32)
    Local $aTab_Rect = _GUICtrlTab_GetItemRect($hSysTab32, -1)
    GUICtrlCreateLabel("", $aTabPos[0], $aTabPos[1] + $aTab_Rect[3] + 4, $aTabPos[2], $aTabPos[3] - $aTab_Rect[3] - 4)
    GUICtrlSetBkColor(-1, $sBkColor)
    GUICtrlSetState(-1, $GUI_DISABLE)
EndFunc   ;==>_GUICtrlTab_SetBkColor

idk if this will help anyone else but it worked for me so i thought i'd post it

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