Montfrooij Posted July 8, 2011 Share Posted July 8, 2011 Hello, I am using a small script to generate a gui with a calendar, using GUICtrlCreateMonthCal . It is working fine, but I would like to add the option of a double click action on a given day that closes the gui and returns the selected date. #include <DateTimeConstants.au3> #include <GuiConstantsEx.au3> #include <Constants.au3> $guiCal = GUICreate("Kalender",201,201,-1,-1) $Calendar = GUICtrlCreateMonthCal(@YDAY & "-" & @MON & "-" & @YEAR,1,1,200,200,$MCS_WEEKNUMBERS) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE $Output = GUICtrlRead($Calendar) $Output = StringRight($Output,2) & "-" & StringMid($Output,6,2) & "-" & StringLeft($Output,4) ExitLoop EndSwitch WEnd GUIDelete($guiCal) MsgBox(0,"Selected date", $Output) So just double clicking on a date should return (in this case) a message box with the $Output variable. In the 'real' script I will be using this as a function where it will have a Return $Output, but that should not matter for the solution. Thanks in advance, Montfrooij Link to comment Share on other sites More sharing options...
rover Posted July 8, 2011 Share Posted July 8, 2011 (edited) Hello, I am using a small script to generate a gui with a calendar, using GUICtrlCreateMonthCal . It is working fine, but I would like to add the option of a double click action on a given day that closes the gui and returns the selected date. So just double clicking on a date should return (in this case) a message box with the $Output variable. In the 'real' script I will be using this as a function where it will have a Return $Output, but that should not matter for the solution. Thanks in advance, Montfrooij There isn't a double click notification for the calendar control, so you have to make one using the mouse released notification NM_RELEASEDCAPTURE and the selected calendar item changing notification MCN_SELCHANGE EDIT: The code box did not post the first time, must be because I'm using IE in Vista... EDIT 2: Forgot HitTest so double clicks on other areas of the calendar don't register expandcollapse popup#include <DateTimeConstants.au3> #include <GuiConstantsEx.au3> #include <Constants.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <GuiMonthCal.au3> Global $iTimer, $sOutput, $sBuffer $guiCal = GUICreate("Kalender", 201, 201, -1, -1) Global $cDummy = GUICtrlCreateDummy() Global $Calendar = GUICtrlCreateMonthCal(@YDAY & "-" & @MON & "-" & @YEAR, 1, 1, 200, 200, $MCS_WEEKNUMBERS) GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $cDummy ;not needed when retrieving date from MCN_SELCHANGE notification in WM_NOTIFY message handle ;$sOutput = GUICtrlRead($Calendar) ;$sOutput = StringRight($sOutput, 2) & "-" & StringMid($sOutput, 6, 2) & "-" & StringLeft($sOutput, 4) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sOutput = ' & $sOutput & @CRLF & @CRLF) ;MsgBox(0, "Selected date", $sOutput) ;ExitLoop Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($guiCal) Exit ;subclassed Calendar control window procedure Func _WM_NOTIFY($hWnd, $msg, $wParam, $lParam) #forceref $hWnd, $Msg, $wParam, $lParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iIDFrom Case $Calendar Switch $iCode Case $NM_RELEASEDCAPTURE ;hitTest - so double clicks on other elements and areas of the calendar do not register Local $tHit = _GUICtrlMonthCal_HitTest($iIDFrom, _WinAPI_GetMousePosX(True, $hWnd), _WinAPI_GetMousePosY(True, $hWnd)) If BitAND(DllStructGetData($tHit, "Hit"), $MCHT_CALENDARDATE) <> 0 Then $sOutput = StringFormat("%02d-%02d-%04d", DllStructGetData($tHit, "Day"), DllStructGetData($tHit, "Month"), DllStructGetData($tHit, "Year")) If TimerDiff($iTimer) <= 300 Then ;milliseconds between mouse clicks If $sBuffer == $sOutput Then ;buffer date from 1st mouse click release to compare with 2nd mouse click release GUICtrlSendToDummy($cDummy) Else $sBuffer = "" EndIf Else $iTimer = TimerInit() $sBuffer = $sOutput EndIf EndIf ;not needed ;~ Case $MCN_SELCHANGE ; Sent by a month calendar control when the currently selected date or range of dates changes ;~ Local $tInfo = DllStructCreate($tagNMSELCHANGE, $lParam) ;~ $sOutput = DllStructGetData($tInfo, "BegDay") & "-" & DllStructGetData($tInfo, "BegMonth") & "-" & DllStructGetData($tInfo, "BegYear") EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY Edited July 8, 2011 by rover I see fascists... Link to comment Share on other sites More sharing options...
Malkey Posted July 8, 2011 Share Posted July 8, 2011 And another example.Local $sDate = _GetDate() If $sDate <> "" Then MsgBox(0, "Selected date", $sDate, 2) Else MsgBox(0, "Selected date", "Date not selection", 2) EndIf Func _GetDate() Local $guiCal, $Calendar, $msg, $begin, $DblClk = 0, $Output = "" $guiCal = GUICreate("Kalender", 201, 201, -1, -1) $Calendar = GUICtrlCreateMonthCal(@YDAY & "-" & @MON & "-" & @YEAR, 1, 1, 200, 200, 0x0004) ; $MCS_WEEKNUMBERS) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case -3 ; $GUI_EVENT_CLOSE ExitLoop Case $Calendar ; Check for double click $begin = TimerInit() While 1 $msg = GUIGetMsg() If $msg = $Calendar Then $DblClk = 1 If TimerDiff($begin) > 500 Then ExitLoop WEnd If $DblClk = 1 Then $Output = GUICtrlRead($Calendar) $Output = StringRight($Output, 2) & "-" & StringMid($Output, 6, 2) & "-" & StringLeft($Output, 4) ExitLoop EndIf EndSwitch WEnd GUIDelete($guiCal) Return $Output EndFunc ;==>_GetDate Link to comment Share on other sites More sharing options...
JoHanatCent Posted July 8, 2011 Share Posted July 8, 2011 ... And another! expandcollapse popup#include <DateTimeConstants.au3> #include <GuiConstantsEx.au3> #include <Constants.au3> #include <Misc.au3> #include <GuiConstants.au3> #include <EditConstants.au3> $Dubbel = False $dll = DllOpen('user32.dll') $guiCal = GUICreate('Kalender', 201, 201, -1, -1) $Calendar = GUICtrlCreateMonthCal(@YDAY & '-' & @MON & '-' & @YEAR, 1, 1, 200, 200, $MCS_WEEKNUMBERS) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exiting() EndSwitch If _IsPressed('01', $dll) Then While _IsPressed('01', $dll) Sleep(10) WEnd $Dubbel = False $Starty = TimerInit() While TimerDiff($Starty) < 300 If _IsPressed('01', $dll) Then $Dubbel = True While _IsPressed('01', $dll) Sleep(10) WEnd EndIf WEnd If $Dubbel = False Then ConsoleWrite('No Double pressed' & @CRLF) EndIf If $Dubbel = True Then Exiting() ExitLoop EndIf WEnd Func Exiting() $Output = GUICtrlRead($Calendar) $Output = StringRight($Output, 2) & '-' & StringMid($Output, 6, 2) & '-' & StringLeft($Output, 4) GUIDelete($guiCal) MsgBox(0, 'Selected date', $Output) EndFunc ;==>Exiting MsgBox(0, '', 'Cheers!', .3) Link to comment Share on other sites More sharing options...
Montfrooij Posted July 8, 2011 Author Share Posted July 8, 2011 (edited) Thanks, that did the trick. Edit: Both did the trick Edited July 8, 2011 by Montfrooij Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now