Jump to content

$defpushbutton in child window not working


 Share

Go to solution Solved by Melba23,

Recommended Posts

Hello  :D

can someone help me please with this problem?

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

$ParentForm = GUICreate("Example", 460, 260)

Global $ChildForm1 = GUICreate("", 460, 260,0,0,$WS_CHILD,-1,$ParentForm)
Global $GoTo_ChildForm2 = GUICtrlCreateButton("Next Page", 320, 20, 120, 40)
GUISetState(@SW_SHOW)

Global $ChildForm2 = GUICreate("", 460, 260,0,0,$WS_CHILD,-1,$ParentForm)
Global $THIS_MUST_REACT_TO_ENTER_KEY = GUICtrlCreateButton("THIS BUTTON IS THE DEFAULT ONE, PRESS ENTER TO SEE IF IT WORKS...", 20, 200, 421, 41, $BS_DEFPUSHBUTTON);<- $BS_DEFPUSHBUTTON not pushed when I press the ENTER key.
Global $Label = GUICtrlCreateLabel("TEXT CHANGES WHEN BUTTON IS PRESSED", 20, 80, 414, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
GUISwitch($ParentForm)
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GoTo_ChildForm2
            GUISetState(@SW_HIDE,$ChildForm1)
            GUISetState(@SW_SHOW,$ChildForm2)
        Case $THIS_MUST_REACT_TO_ENTER_KEY
            GUICtrlSetData($Label,'IF YOU PRESSED ENTER IT WORKS!')
    EndSwitch
WEnd

In a normal form pressing enter is the same as pushing the button if the button is the "$BS_DEFPUSHBUTTON"

I tried to do it with HotKeySet('{ENTER}','function') but then you have to code it so that if the form is out of focus, the hot-key must be disabled  :(

and I think that is not the best solution to...

Thanks in advance!  :)

Edited by TheAutomator
Link to comment
Share on other sites

  • Moderators
  • Solution

TheAutomator,

Child GUIs are funny beasts in AutoIt and quite often do not behave as you expect. :wacko:

I would add the $WS_EX_CONTROLPARENT extended style to the second child and then use an accelerator key like this:

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

$ParentForm = GUICreate("Example", 460, 260)
GUISetState(@SW_SHOW)

Global $ChildForm1 = GUICreate("", 460, 260, 0, 0, $WS_CHILD, Default, $ParentForm)
Global $GoTo_ChildForm2 = GUICtrlCreateButton("Next Page", 320, 20, 120, 40)
GUISetState(@SW_SHOW)

Global $ChildForm2 = GUICreate("", 460, 260, 0, 0, $WS_CHILD, $WS_EX_CONTROLPARENT, $ParentForm)
Global $THIS_MUST_REACT_TO_ENTER_KEY = GUICtrlCreateButton("THIS BUTTON IS THE DEFAULT ONE, PRESS ENTER TO SEE IF IT WORKS...", 20, 200, 421, 41);<- $BS_DEFPUSHBUTTON not pushed when I press the ENTER key.
Global $Label = GUICtrlCreateLabel("TEXT CHANGES WHEN BUTTON IS PRESSED", 20, 80, 414, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
GUISetState(@SW_HIDE)

Global $aAccelKeys[1][2] = [["{ENTER}", $THIS_MUST_REACT_TO_ENTER_KEY]]
GUISetAccelerators($aAccelKeys, $ParentForm)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GoTo_ChildForm2
            GUISetState(@SW_HIDE, $ChildForm1)
            GUISetState(@SW_SHOW, $ChildForm2)
        Case $THIS_MUST_REACT_TO_ENTER_KEY
            GUICtrlSetData($Label, 'IF YOU PRESSED ENTER IT WORKS!')
    EndSwitch
WEnd
Please ask if you have any questions - although I cannot explain why the original script did not work. ;)

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

  • Moderators

TheAutomator,

If you were to use a more conventional way of passing from one GUI to another rather than using that complicated "child" mode then you would not need any workarounds:

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

$Form1 = GUICreate("Example", 460, 260)

Global $GoTo_Form2 = GUICtrlCreateButton("Next Page", 320, 20, 120, 40)

GUISetState(@SW_SHOW)

Global $Form2 = GUICreate("", 460, 260)
Global $THIS_MUST_REACT_TO_ENTER_KEY = GUICtrlCreateButton("THIS BUTTON IS THE DEFAULT ONE, PRESS ENTER TO SEE IF IT WORKS...", 20, 200, 421, 41, $BS_DEFPUSHBUTTON)
Global $Label = GUICtrlCreateLabel("TEXT CHANGES WHEN BUTTON IS PRESSED", 20, 80, 414, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
GUISetState(@SW_HIDE)


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GoTo_Form2
            GUISetState(@SW_HIDE, $Form1)
            GUISetState(@SW_SHOW, $Form2)
        Case $THIS_MUST_REACT_TO_ENTER_KEY
            GUICtrlSetData($Label, 'IF YOU PRESSED ENTER IT WORKS!')
    EndSwitch
WEnd
Simple really. ;)

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

Melba23,

I know your solution is good if the form stays on the same place

but I want the form(s) to stay at the same place if I drag them around and switch between them.

That's why I use that "child" mode.  :) 

Apparently using child mode does not require GUISwitch($ParentForm) or am I wrong?

The help-file uses it in an example, that's why I ask..

TheAutomator

Edited by TheAutomator
Link to comment
Share on other sites

  • Moderators

TheAutomator,

 

I want the form(s) to stay at the same place if I drag them around and switch between them

That is easy to do:

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

$Form1 = GUICreate("Example", 460, 260)
Global $GoTo_Form2 = GUICtrlCreateButton("Next Page", 320, 20, 120, 40)
GUISetState(@SW_SHOW)

Global $Form2 = GUICreate("", 460, 260)
Global $THIS_MUST_REACT_TO_ENTER_KEY = GUICtrlCreateButton("THIS BUTTON IS THE DEFAULT ONE, PRESS ENTER TO SEE IF IT WORKS...", 20, 200, 421, 41, $BS_DEFPUSHBUTTON)
Global $Label = GUICtrlCreateLabel("TEXT CHANGES WHEN BUTTON IS PRESSED", 20, 80, 414, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
GUISetState(@SW_HIDE)

GUIRegisterMsg($WM_MOVE, "_WM_MOVE") ; Register the move message

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GoTo_Form2
            GUISetState(@SW_HIDE, $Form1)
            GUISetState(@SW_SHOW, $Form2)
        Case $THIS_MUST_REACT_TO_ENTER_KEY
            GUICtrlSetData($Label, 'IF YOU PRESSED ENTER IT WORKS!')
    EndSwitch
WEnd

Func _WM_MOVE($hWnd, $iMsg, $wParam, $lParam)

    #forceref $iMsg, $wParam, $lParam

    Switch $hWnd
        Case $Form1
            $aPos = WinGetPos($Form1)                ; Wherever $Formi is
            WinMove($Form2, "", $aPos[0], $aPos[1])  ; Move $Form2 there
        Case $Form2
            $aPos = WinGetPos($Form2)                ; And vice versa
            WinMove($Form1, "", $aPos[0], $aPos[1])
    EndSwitch

EndFunc
All clear? ;)

You only need to use GUISwitch if you are creating additional controls in a GUI when more than one have been created - otherwise AutoIt defaults to the last one referenced. :)

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