Jump to content

Setting flag to true issue using wm_notify ($DTN_DATETIMECHANGE)


Recommended Posts

Issue: If either date picker controls receive focus, then use arrow keys to change date in edit portion, flags do not set to True until mouse move or mouse click.

I have used this exact method in the past & it works perfectly. I just can't figure out what I am doing wrong here. The only thing different I can think of is I just updated my Autoit version to ;Autoit v3.3.14.0 & if it matters system I am using is running Win7 Pro x86.

#include <WindowsConstants.au3>
#include <GuiRichEdit.au3>
#include <Date.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
;If either date picker controls recieve focus, then use arrow keys to change date
; in edit portion, flags do not set to True until mouse move or mouse click.
;Flags set fine when drop down is closed
Global $fdpLogChange = False, $fdpMainChange = False
Global $hDailyLogGUI, $g_id_dpDailyLog
Global $hMainGui = GUICreate("GardenBuddy", @DesktopWidth / 1.5, @DesktopHeight / 1.4, -1, -1)
Global $g_id_dpMain = GUICtrlCreateDate(_NowDate(), 8, 20, 181, 25)
Global $mView = GUICtrlCreateMenu("&View")
Global $mPlantChart = GUICtrlCreateMenuItem("Plant Chart", $mView, 0)
GUICtrlCreateMenuItem("", $mView, 1)
Global $mDailyLog = GUICtrlCreateMenuItem("Daily Log", $mView, 2)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
    $Msg = GUIGetMsg(1)
    Switch $Msg[1]
        Case $hMainGui
            Switch $Msg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hMainGui)
                    Exit
                Case $mDailyLog
                    __CreateDailyLog()
                Case Else
                    If $fdpMainChange = True Then __DateChangeMain()
            EndSwitch
        Case $hDailyLogGUI
            Switch $Msg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hDailyLogGUI)
                Case Else
                    If $fdpLogChange = True Then __DateChangeDL()
            EndSwitch
    EndSwitch
WEnd

Func __CreateDailyLog()
    Local $iW = @DesktopWidth / 2, $iH = @DesktopHeight / 2
    $hDailyLogGUI = GUICreate("Daily Log", $iW, $iH, -1, -1, $WS_OVERLAPPEDWINDOW)
    $g_reDailyLog = _GUICtrlRichEdit_Create($hDailyLogGUI, "", 0, 60, $iW, $iH - 110, _
            BitOR($WS_VSCROLL, $ES_WANTRETURN, $ES_AUTOVSCROLL, $ES_MULTILINE))
    _GUICtrlRichEdit_SetFont($g_reDailyLog, 12)
    $g_id_dpDailyLog = GUICtrlCreateDate(_NowDate(), 8, 20, 181, 25)
    GUISetState()
EndFunc   ;==>__CreateDailyLog

Func __DateChangeDL();Would like to be instantly notified if user changes the date through any means.
    $fdpLogChange = False
    ConsoleWrite("Log Changed" & @CRLF)
EndFunc   ;==>__DateChangeDL

Func __DateChangeMain()
    $fdpMainChange = False
    ConsoleWrite("Main Changed" & @CRLF)
EndFunc   ;==>__DateChangeMain

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo, $hWndDateDailyLog, $hWndDateMain
    $hWndDateDailyLog = GUICtrlGetHandle($g_id_dpDailyLog)
    $hWndDateMain = GUICtrlGetHandle($g_id_dpMain)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndDateDailyLog, $hWndDateMain
            Switch $iCode
                Case $DTN_DATETIMECHANGE
                    If $iIDFrom = $g_id_dpDailyLog Then $fdpLogChange = True
                    If $iIDFrom = $g_id_dpMain Then $fdpMainChange = True
                    Return 0
                Case $DTN_CLOSEUP
                    ;no return value
                Case $DTN_USERSTRING
                    Return 0
                Case $DTN_WMKEYDOWN
                    Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Link to comment
Share on other sites

Because changing the date does not generate a control event (but it is the case when clicking on the control)
Move the two lines If $fdpMainChange = True and If $fdpLogChange = True outside the Switch/Case, it should work

Edited by jguinch
Link to comment
Share on other sites

Because changing the date does not generate a control event (but it is the case when clicking on the control)
Move the two lines If $fdpMainChange = True and If $fdpLogChange = True outside the Switch/Case, it should work

Thanks jguinch, Works fine now!

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

×
×
  • Create New...