Jump to content
Sign in to follow this  
Aktonius

Detecting changes of inputbox with 2 guis

Recommended Posts

Aktonius

Normally by following example inputbox change can be detected

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3> ; used for Lo/Hi word
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 442, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 224, 168, 121, 21)
$Input2 = GUICtrlCreateInput("Input2", 224, 208, 121, 21)
$hInput1 = GUICtrlGetHandle($Input1)
$hInput2 = GUICtrlGetHandle($Input2)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
WEnd
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg
Local $hWndFrom, $iIDFrom, $iCode
$hWndFrom = $ilParam
$iIDFrom = _WinAPI_LoWord($iwParam)
$iCode = _WinAPI_HiWord($iwParam)
Switch $hWndFrom
  Case $hInput2, $hInput1
   Switch $iCode
    Case $EN_CHANGE ; Sent when the user has taken an action that may have altered text in an edit control
     $Input1txt = GUICtrlRead($Input1)
     $Input2txt = GUICtrlRead($Input2)
     If $Input1txt = $Input2txt Then
      GUICtrlSetBkColor($Input2, 0x00ff00)
     Else
      GUICtrlSetBkColor($Input2, 0xFF0000)
     EndIf
   EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

The problem comes for me when i create inputbox in another gui for which i use following loop

Switch $nMsg[1]
Case $gui1
  Switch $nMsg[0]
   Case $GUI_EVENT_CLOSE
  EndSwitch
Case $gui2
  Switch $nMsg[0]
   Case $GUI_EVENT_CLOSE
    GUIDelete($logform)
  EndSwitch
EndSwitch

Should something else be in wm_command in this case?

Share this post


Link to post
Share on other sites
Melba23

Aktonius,

I woudl just change the order of the Switch structures in the handler like this:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3> ; used for Lo/Hi word

$Form1 = GUICreate("Form1", 300, 100, 100, 100)
$Input1 = GUICtrlCreateInput("Input1", 10, 10, 200, 20)
$Input2 = GUICtrlCreateInput("Input2", 10, 50, 200, 20)
$hInput1 = GUICtrlGetHandle($Input1)
$hInput2 = GUICtrlGetHandle($Input2)
GUISetState(@SW_SHOW)

$Form2 = GUICreate("Form1", 300, 100, 100, 300)
$Input3 = GUICtrlCreateInput("Input3", 10, 10, 200, 20)
$hInput3 = GUICtrlGetHandle($Input3)
$cLabel = GUICtrlCreateLabel("", 10, 50, 200, 20)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $Form1
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    Exit
            EndSwitch
        Case $Form2
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($Form2)
            EndSwitch
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode
    $hWndFrom = $ilParam
    $iIDFrom = _WinAPI_LoWord($iwParam)
    $iCode = _WinAPI_HiWord($iwParam)
    Switch $iCode
        Case $EN_CHANGE ; Sent when the user has taken an action that may have altered text in an edit control
            Switch $hWndFrom
                Case $hInput2, $hInput1
                    $Input1txt = GUICtrlRead($Input1)
                    $Input2txt = GUICtrlRead($Input2)
                    If $Input1txt = $Input2txt Then
                        GUICtrlSetBkColor($Input2, 0x00ff00)
                    Else
                        GUICtrlSetBkColor($Input2, 0xFF0000)
                    EndIf
                Case $hInput3
                    If GUICtrlRead($Input3) = "" Then
                        GUICtrlSetData($cLabel, "Empty")
                    Else
                        GUICtrlSetData($cLabel, "Content exists")
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

All clear? :oops:

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

 

Share this post


Link to post
Share on other sites
acidman

I found it's much more simple to use Guioneventmode, when it comes to functions like the ones you have...


[u]My dream is to have a dream...[/u]

Share this post


Link to post
Share on other sites
acidman

in lots of cases when it comes to if statements a newbie coder would practise if statements a lot to understand the execution flow better of the if statement and others, with loop mode there's a lot of code that slows down one's script like Guigetmsg(); Like when having Multiple Gui's you could simply hide the child Gui and show it later with guioneventmode in most cases makes the script easier to code, it's easier and faster and you do not necessarily have to figure out all sorts of statements, in loop mode you have to spend a considerable amount of time figuring out how to close or hide Child Gui's and most examples on the forums only caters for 2 Guis, go ahead try it...


[u]My dream is to have a dream...[/u]

Share this post


Link to post
Share on other sites
acidman

here's a script you can try

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Parent", 197, 35, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "_1Close")
$Input1 = GUICtrlCreateInput("Input1", 16, 8, 121, 21)
GUISetState(@SW_SHOW)
$Form2 = GUICreate("Child", 197, 35, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "_2Close")
$Input2 = GUICtrlCreateInput("Input1", 16, 8, 121, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $s1
Func _1Close()
Exit ; exit the script if close button on parent dialog has
; been clicked
EndFunc
Func  _2Close()
GUISetState(@sw_hide, $Form2)
; hide child gui if the close button on the child gui has been clicked
EndFunc
While 1
do
$s1 = GUICtrlRead($input1, 0) ; Read input 1 until the text has been set in input 2; because it's in a while loop the process will be executed until the script has exited
  until GUICtrlSetData($input2, $s1)
WEnd


[u]My dream is to have a dream...[/u]

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  

×