Jump to content
Sign in to follow this  
lolipop

Reading GUI date control instantly

Recommended Posts

lolipop

Hi,

Anyone can show me thru the example below how can I enable real time reading of the value of the date? What I want is to check the date value as soon as the user click on the next date entry instead of waiting for him to click on the submit button. Any help is appreciated.

Click on date1, when user leave the date1 gui control, read value of date1

Click on date 2, when user leave the date2 gui control, read value of date2

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $date, $msg

    GUICreate("My GUI get date", 200, 200, 800, 200)
    $date1 = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20)
    $date2 = GUICtrlCreateDate("1953/04/25", 10, 50, 185, 20)
    $button1 = GUICtrlCreateButton("Submit", 10, 100, 50, 50, -1, -1)

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd

    GUIDelete()
EndFunc   ;==>Example

Share this post


Link to post
Share on other sites
FireFox

Hi,

...
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $date1
                MsgBox(0, "", "date changed !")
        EndSwitch
...

Br, FireFox


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
mLipok

@FireFox

I think about this but this is not what he need (I think so)

In your example you must change date, but i think, OP want to check date after changing focus

Maybe this:

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

Example()

Func Example()
    Local $date, $msg
    Local $date, $msg

    Local $hGui = GUICreate("My GUI get date", 200, 200, 800, 200)
    Local $idDate1 = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20)
    Local $idDate2 = GUICtrlCreateDate("1953/04/25", 10, 50, 185, 20)
    Local $button1 = GUICtrlCreateButton("Submit", 10, 100, 50, 50, -1, -1)
    GUISetState(@SW_SHOW)

    Local $idLastFocus = 0
    ; Local $idNewFocus = 0
    ; Loop until the user exits.
    $idLastFocus = ControlGetFocus($hGui)
    While 1
        ; ConsoleWrite('ControlGetFocus($hGui) = ' & ControlGetFocus($hGui) & @CRLF)
        If $idLastFocus <> ControlGetFocus($hGui) Then
            If $idLastFocus = 'SysDateTimePick321' Then
                ConsoleWrite('Date1 = ' & GUICtrlRead($idDate1) & @CRLF)
            EndIf
            If $idLastFocus = 'SysDateTimePick322' Then
                ConsoleWrite('Date2 = ' & GUICtrlRead($idDate2) & @CRLF)
            EndIf
            $idLastFocus = ControlGetFocus($hGui)
        EndIf
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idDate1
                ConsoleWrite(GUICtrlRead($idDate1) & @CRLF)

            Case $idDate2
                ConsoleWrite(GUICtrlRead($idDate2) & @CRLF)

            Case $button1


        EndSwitch
    WEnd
    GUIDelete()
EndFunc   ;==>Example

EDIT:

commented  Local $idNewFocus = 0

because not needed

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library
 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-10-15

Share this post


Link to post
Share on other sites
FireFox

Instead of keep checking the focus, use WM_COMMAND. You will surely find a $ ..._KILLFOCUS.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
mLipok
For the past hour I studied WM_KILLFOCUS message on MSDN 
 
And I was wondering how to use WM_KILLFOCUS for control, I thought that this message applies only to the entire window, not a single element of this window.
 
If I'm wrong, please give me some tips.
 
 
EDIT:
I found some further example
 
But still looking for the way to understanding how it works. 
Probably a little more time passed and the magic dissipate, and in its place will be knowledge ;)
Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library
 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-10-15

Share this post


Link to post
Share on other sites
Melba23

lolipop,

 

how can I enable real time reading of the value of the date?

This allows you to detect changes to the date control instantly:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <DateTimeConstants.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("Test", 200, 200, 800, 200)
$cDate1 = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20)
$cDate2 = GUICtrlCreateDate("1953/04/25", 10, 50, 185, 20)
$cButton = GUICtrlCreateButton("Submit", 10, 100, 50, 50, -1, -1)

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch
WEnd

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

    Switch _WinAPI_LoWord($wParam) ; ControlID of the control
        Case $cDate1, $cDate2
            Local $tStruct = DllStructCreate($tagNMHDR, $lParam)
            If DllStructGetData($tStruct, "Code") = $DTN_DATETIMECHANGE Then
                ConsoleWrite("1: " & GUICtrlRead($cDate1) & " - 2: " & GUICtrlRead($cDate2) & @CRLF)
            EndIf
    EndSwitch

EndFunc
Any use? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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
lolipop

lolipop,

 

This allows you to detect changes to the date control instantly:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <DateTimeConstants.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("Test", 200, 200, 800, 200)
$cDate1 = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20)
$cDate2 = GUICtrlCreateDate("1953/04/25", 10, 50, 185, 20)
$cButton = GUICtrlCreateButton("Submit", 10, 100, 50, 50, -1, -1)

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch
WEnd

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

    Switch _WinAPI_LoWord($wParam) ; ControlID of the control
        Case $cDate1, $cDate2
            Local $tStruct = DllStructCreate($tagNMHDR, $lParam)
            If DllStructGetData($tStruct, "Code") = $DTN_DATETIMECHANGE Then
                ConsoleWrite("1: " & GUICtrlRead($cDate1) & " - 2: " & GUICtrlRead($cDate2) & @CRLF)
            EndIf
    EndSwitch

EndFunc
Any use? :)

M23

 

Hi Melba,

Sorry for the late reply. Thanks for the solution. It works perfectly.

I have try intergating your solution with a sample code I find in the forum (I have a listview and I wish to use this sample code to custom draw my listview item)  but I can't seem to made it work. The sample code is basically meant to do a custom draw for the listview item color. With my limited knowledge, I can't make it work. You think you can help? Sample below.

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
   Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    ; Local $tBuffer
   $hWndListView = $Timelog_form_Listview
   If Not IsHWnd($hWndListView) Then $hWndListView = GUICtrlGetHandle($Timelog_form_Listview)

   $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
   $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
   $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
   $iCode = DllStructGetData($tNMHDR, "Code")

   Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
               Case $NM_CUSTOMDRAW
                  If Not _GUICtrlListView_GetViewDetails($hWndFrom) Then Return $GUI_RUNDEFMSG ; Not in details mode

                     Local $tCustDraw, $iDrawStage, $iItem, $iSubitem, $hDC, $tRect, $iColor1, $iColor2, $iColor3

                     $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
                     $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage')

                     Switch $iDrawStage
                        Case $CDDS_PREPAINT
                           Return $CDRF_NOTIFYITEMDRAW
                        Case $CDDS_ITEMPREPAINT
                           Return $CDRF_NOTIFYSUBITEMDRAW
                        Case $CDDS_ITEMPOSTPAINT
                           ; Not handled
                        Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
                           $iItem = DllStructGetData($tCustDraw, 'dwItemSpec')
                           $iSubitem = DllStructGetData($tCustDraw, 'iSubItem')

                           If _GUICtrlListView_GetItemSelected($hWndFrom, $iItem) Then ; Item to draw is selected
                              $hDC = _WinAPI_GetDC($hWndFrom)
                              $tRect = DllStructCreate($tagRECT)

                              ; We draw the background when we draw the first item.
                              If $iSubitem = 0 Then
                                 ; We must send the message as we want to use the struct. _GUICtrlListView_GetSubItemRect returns an array.
                                 _SendMessage($hWndFrom, $LVM_GETSUBITEMRECT, $iItem, DllStructGetPtr($tRect))

                                 DllStructSetData($tRect, "Left", 2)
                                 _WinAPI_FillRect($hDC, DllStructGetPtr($tRect), _WinAPI_GetStockObject($GRAY_BRUSH)) ; Change the bush here. You can use GDI+ to make your own.
                              EndIf

                              DllStructSetData($tRect, "Left", 2)
                              DllStructSetData($tRect, "Top", $iSubitem)
                              _SendMessage($hWndFrom, $LVM_GETSUBITEMRECT, $iItem, DllStructGetPtr($tRect))

                              Local $sText = _GUICtrlListView_GetItemText($hWndFrom, $iItem, $iSubitem)
                              _WinAPI_SetBkMode($hDC, $TRANSPARENT) ; It uses the background drawn for the first item.

                              ; Select the font we want to use
                              _WinAPI_SelectObject($hDC, _SendMessage($hWndFrom, $WM_GETFONT))

                              If $iSubitem = 0 Then
                                 DllStructSetData($tRect, "Left", DllStructGetData($tRect, "Left") + 2)
                              Else
                                 DllStructSetData($tRect, "Left", DllStructGetData($tRect, "Left") + 6)
                              EndIf
                              _WinAPI_DrawText($hDC, $sText, $tRect, BitOR($DT_VCENTER, $DT_END_ELLIPSIS, $DT_SINGLELINE))

                              _WinAPI_ReleaseDC($hWndFrom, $hDC)

                              Return $CDRF_SKIPDEFAULT ; Don't do default processing
                           EndIf

                            Return $CDRF_NEWFONT ; Let the system do the drawing for non-selected items
                        Case BitOR($CDDS_ITEMPOSTPAINT, $CDDS_SUBITEM)
                            ; Not handled
                      EndSwitch
                  Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                  Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                  Local $iItem = DllStructGetData($tInfo, "Item")
                  Global $vValidTimeIn = _GUICtrlListView_GetItemText($TimeListview, $iItem, 1)
                  Global $vSelectedUsername = _GUICtrlListView_GetItemText($Time_Listview, $iItem, 0)
                  If $vValidTimeIn == "" Then
                     GUICtrlSetState($Time_button1, $GUI_HIDE)
                     GUICtrlSetState($Time_button2, $GUI_SHOW)
                     GUICtrlSetState($Time_input1,$GUI_FOCUS)
                  Else
                     GUICtrlSetState($Time_button1, $GUI_SHOW)
                     GUICtrlSetState($Time_button2, $GUI_HIDE)
                     GUICtrlSetState($Time_input1,$GUI_FOCUS)
                  EndIf
            EndSwitch
   EndSwitch
   Return $GUI_RUNDEFMSG
EndFunc

Func RGB2BGR($iColor)
   Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc

Btw, thank you Firefox and mLipok for their solution too. :)

Edited by lolipop

Share this post


Link to post
Share on other sites
Melba23

lolipop,

You just need to have both sets of code inside the handler: :)

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

    ; Start by looking for the Date control
    Switch _WinAPI_LoWord($wParam) ; ControlID of the control
        Case $cDate1, $cDate2
            Local $tStruct = DllStructCreate($tagNMHDR, $lParam)
            If DllStructGetData($tStruct, "Code") = $DTN_DATETIMECHANGE Then
                ConsoleWrite("1: " & GUICtrlRead($cDate1) & " - 2: " & GUICtrlRead($cDate2) & @CRLF)
            EndIf
    EndSwitch

    ; And then see if the ListView needs attention
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    ; Local $tBuffer
    $hWndListView = $Timelog_form_Listview
    If Not IsHWnd($hWndListView) Then $hWndListView = GUICtrlGetHandle($Timelog_form_Listview)
    ; etc, etc
M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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
lolipop

I did try combine them up before but it doesn't work. Hmm... Let me try them again. Thanks. Melba

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  

×