Jump to content

$BS_DEFPUSHBUTTON not working correctly


Zest
 Share

Recommended Posts

Hello...again

I've almost finished the first version of my database script for our book library. One annoying thing I can't get to work is the $BS_DEFPUSHBUTTON.

I have a GUI with a listview, an inputbox to enter a text to search for, a search button and some other buttons. I want the search button to be "pressed" when I press <ENTER> in the inputbox, so I have set the search button to be the default push button. When I open the listview GUI window the inputbox is active and the search button is pressed when I press <ENTER>. So far so good. But after the first search, when I press <ENTER> in the inputbox, instead of "pressing" the search button, the characters in the listbox are selected except for the first one!?

I just can't find what's wrong. BTW I have the search automatically select the found titles in the listview, the listview might have something to do with it.

Since most likely anyone wanting to help out will need my source code I'll attach it for you. You must have Excel and W2K/XP (or Vista?) for the script to work and also the ExcelCOM UDF 1.4.

Run the script and press the 'Listenansicht' button to get to the listview GUI with the inputbox and search button.

The inputbox and button are $SearchInput and $SearchButton. I'm sorry I can't be more specific, because this time I don't have a clue where to look anymore...

Many thanks in advance for any help!

Database_TEST_zest.ZIP

Link to comment
Share on other sites

@-Ultima-

Thank you for your suggestion, but unforatunately that didn't solve the problem.

I'll try if I can 'catch pressing the <ENTER> key when the listview has focus and redirect it to the search button to see if that does the trick...

Link to comment
Share on other sites

Hello...again

I've almost finished the first version of my database script for our book library. One annoying thing I can't get to work is the $BS_DEFPUSHBUTTON.

I have a GUI with a listview, an inputbox to enter a text to search for, a search button and some other buttons. I want the search button to be "pressed" when I press <ENTER> in the inputbox, so I have set the search button to be the default push button. When I open the listview GUI window the inputbox is active and the search button is pressed when I press <ENTER>. So far so good. But after the first search, when I press <ENTER> in the inputbox, instead of "pressing" the search button, the characters in the listbox are selected except for the first one!?

I just can't find what's wrong. BTW I have the search automatically select the found titles in the listview, the listview might have something to do with it.

Since most likely anyone wanting to help out will need my source code I'll attach it for you. You must have Excel and W2K/XP (or Vista?) for the script to work and also the ExcelCOM UDF 1.4.

Run the script and press the 'Listenansicht' button to get to the listview GUI with the inputbox and search button.

The inputbox and button are $SearchInput and $SearchButton. I'm sorry I can't be more specific, because this time I don't have a clue where to look anymore...

Many thanks in advance for any help!

Maybe if you use ControlFocus to set the focus back to the button after the first search it will work because, presumably, the focus has been set to the listbox.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Maybe if you use ControlFocus to set the focus back to the button after the first search it will work because, presumably, the focus has been set to the listbox.

This solution is correct one, but we should use it even on the creation stage...

#include <GuiConstants.au3>

$GUI = GUICreate("Test Script", 300, 200)

$Button1 = GUICtrlCreateButton("Button1", 20, 160, 60, 20)

$Button2 = GUICtrlCreateButton("Button2", 90, 160, 60, 20)
GUICtrlSetState(-1, $GUI_DEFBUTTON+$GUI_FOCUS)

GUISetState(@SW_SHOW, $GUI)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button2
            ConsoleWrite("test")
    EndSwitch
WEnd

But in fact we do not have to set the $GUI_DEFBUTTON style, $GUI_FOCUS is anouth in this case.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Hello,

I still couldn't get it to work with $GUI_DEFBUTTON and $GUI_FOCUS, but I added a check to the GUI loop if the inputbox was active or not. When it is active it sets a hotkey to "catch" the <ENTER> and when it's inactive it unsets the hotkey. Kind of stupid to have it in the loop, but I noticed no delays in the handling of GUI input and at least it works...

Thank you all for your help!

Link to comment
Share on other sites

This solution is correct one, but we should use it even on the creation stage...

#include <GuiConstants.au3>

$GUI = GUICreate("Test Script", 300, 200)

$Button1 = GUICtrlCreateButton("Button1", 20, 160, 60, 20)

$Button2 = GUICtrlCreateButton("Button2", 90, 160, 60, 20)
GUICtrlSetState(-1, $GUI_DEFBUTTON+$GUI_FOCUS)

GUISetState(@SW_SHOW, $GUI)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button2
            ConsoleWrite("test")
    EndSwitch
WEnd

But in fact we do not have to set the $GUI_DEFBUTTON style, $GUI_FOCUS is anouth in this case.

Completely off topic.

The word you were looking for is 'enough' and I have no idea why it's spelled that way. Since I guess you speak at least 3 languages and I have difficulty with one, please take this as a humble offering.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Completely off topic.

The word you were looking for is 'enough' and I have no idea why it's spelled that way. Since I guess you speak at least 3 languages and I have difficulty with one, please take this as a humble offering.

Thanks for the correction, i was in a rush and didn't check spelling as i do usually.

And yes, i speak/know 3 languages.. or it is 4? :) ... Yep, with AutoIt it is 4! :party: ...

1) Russian (Native).

2) Hebrew (in perfection).

3) English (still learning as you can see (thanks to you)).

4) AutoIt (still learning as you can see (thanks to you to) :) ).

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

But in fact we do not have to set the $GUI_DEFBUTTON style

Indeed. I had a brainfart.

@Zest: What I meant was that you should use GUICtrlSetState([CONTROL ID], $GUI_FOCUS) on the input control every time after you perform the actions you need to. That way, every time you press Enter, even if the listview steals the focus, the input control gets the focus back. I'm not sure if you'd also need to set $BS_DEFPUSHBUTTON on the button every time too, but if the DEFPUSHBUTTON look/behavior isn't returned after you press Enter, then you probably do need to do that as well.

Edited by -Ultima-

[ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]

Link to comment
Share on other sites

@Ultima:

That would be quite complicated to program, because I want to be able to click any button I wish, but only when I press ENTER in the inputbox it should do the search (which is done by pressing the search button).

Setting the focus back to the button after every other action in that GUI seems unnecessarily complicated...

I have it like this:

; FUNCTION: Create a list GUI with the currently opened database
Func CreateListview()
; Create the listview GUI
    CreateListViewGUI()
; GUI loop, active while Listview GUI is shown
    While 1
    ; Exit through close button on GUI
        If $msg2[0] = $CloseListView Then
            GUIDelete($GUIListview)
            GUICtrlSetState($DatabaseMenu,$GUI_ENABLE)
            GUICtrlSetState($filemenu,$GUI_ENABLE)
        ;WinMove($HandleMain,"",$HandleMainCurrent[0],$HandleMainCurrent[1]) 
            ExitLoop
        EndIf
    ; Pressed search button
        If $msg2[0] = $SearchButton Then
            GUICtrlSetState($SearchButton,$GUI_DISABLE)
            GUICtrlSetState($SearchButtonDown,$GUI_DISABLE)
            GUICtrlSetState($SearchButtonUp,$GUI_DISABLE)
        ; Clear all checkboxes
            For $r = 0 to $RowNumber-1
                _GUICtrlListView_SetItemChecked($ListView,$r,0)
            Next
        ; Store the searchtext to remember the last entered searchtext if the listview has been closed and a new one opened
            $SearchText = GUICtrlRead($SearchInput)
        ; Clear all selected cells
            removeListViewIndexes($Listview)
        ; Perform the search
            SearchFunction($SearchText,1)
        ; Set book counter on main GUI and update it, but only if the search has a result
            If $FirstSearchResult <> -1 Then
                GUICtrlSetData($BookCounter,$FirstSearchResult+1)
                Update()
                GUICtrlSetState($SearchButtonDown,$GUI_ENABLE)
                GUICtrlSetState($SearchButtonUp,$GUI_ENABLE)
            EndIf
            GUICtrlSetState($SearchButton,$GUI_ENABLE)
        EndIf
; 
; lines removed to keep it short
;

    ; Check if $SearchInput has focus and set Hotkey if so
        If ControlGetFocus($ListviewTitle) = "Edit1" Then
            HotKeySet("{Enter}", "CaptureEnter")
        Else
            HotKeySet("{Enter}")
        EndIf
    Wend
EndFunc

The "CaptureEnter" function simply performs the search, just like pressing the search button.

Link to comment
Share on other sites

"Perform the actions you need to" was in reference to the bits of code required to set up and perform the search, display the results, cleanup, and whatnot...

; Pressed search button
        If $msg2[0] = $SearchButton Then
            GUICtrlSetState($SearchButton,$GUI_DISABLE)
            GUICtrlSetState($SearchButtonDown,$GUI_DISABLE)
            GUICtrlSetState($SearchButtonUp,$GUI_DISABLE)
        ; Clear all checkboxes
            For $r = 0 to $RowNumber-1
                _GUICtrlListView_SetItemChecked($ListView,$r,0)
            Next
        ; Store the searchtext to remember the last entered searchtext if the listview has been closed and a new one opened
            $SearchText = GUICtrlRead($SearchInput)
        ; Clear all selected cells
            removeListViewIndexes($Listview)
        ; Perform the search
            SearchFunction($SearchText,1)
        ; Set book counter on main GUI and update it, but only if the search has a result
            If $FirstSearchResult <> -1 Then
                GUICtrlSetData($BookCounter,$FirstSearchResult+1)
                Update()
                GUICtrlSetState($SearchButtonDown,$GUI_ENABLE)
                GUICtrlSetState($SearchButtonUp,$GUI_ENABLE)
            EndIf
            GUICtrlSetState($SearchButton,$GUI_ENABLE + $BS_DEFPUSHBUTTON) ; assuming the button doesn't get re-marked as default
            GUICtrlSetState($SearchInput,$GUI_FOCUS) ; this is what I'm referring to
        EndIf

Not that much more complicated, and wouldn't require the use of a hotkey (whose use is, IMHO, more unnecessarily complicated than a simple GUICtrlSetState() for something like this). Or maybe I'm still misunderstanding?

Edited by -Ultima-

[ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]

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