Help with A_GuiControlEvent and logic flow... Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
kunkel321
Posts: 1049
Joined: 30 Nov 2015, 21:19

Help with A_GuiControlEvent and logic flow...

Post by kunkel321 » 08 Jun 2023, 15:52

This is a tricky one to explain...

It's my popup MonthCal tool. Full code here
6-9-2023 hidden code updated with fix in first reply, below.
Spoiler
I have several lines of text (rather several text commands) under the MonthCal, to display holidays from Tidbit's isHoliday() function. It's a nice effect, I think.

Before adding that feature, I had already enabled the calendar to send the date upon double-click. (also Tidbit code, but a different project, LOL). The MonthCal has +AltSubmit and gDblClick and the DblClick label (about line 104 in above code) is this:

Code: Select all

DblClick:
Gui, dp:submit, noHide

;MsgBox, A_GuiControlEvent is: %A_GuiControlEvent%

; Below several lines adapted from TidBit's 2015 Get A Date.
If (A_GuiControlEvent=1 && (A_TickCount-tics)<=DllCall("GetDoubleClickTime") ) {
	;MsgBox,  dbl click? %A_GuiControlEvent%
	gosub, dpButtonSubmit
}
Else If (A_GuiControlEvent=1) {
	tics:=A_TickCount

	;MsgBox, A_GuiControlEvent above hol() is: %A_GuiControlEvent%
	HolidayList()
	HoliArr := StrSplit(theseHolis, "`n")
	Loop, 5 {
	If (HoliArr[A_Index]) ; might not show if date+holidate is >= Len(33)
		GuiControl,, HoliTxt%A_Index%, % HoliArr[A_Index]
	else
		GuiControl,, HoliTxt%A_Index%,
	}
}
Return
When it was just this:

Code: Select all

DblClick:
Gui, dp:submit, noHide
; Below several lines adapted from TidBit's 2015 Get A Date.
If (A_GuiControlEvent=1 && (A_TickCount-tics)<=DllCall("GetDoubleClickTime") ) 
	gosub, dpButtonSubmit
Else If (A_GuiControlEvent=1) 
	tics:=A_TickCount
Return
it worked.

Then I added code to update the lines of text (the holiday names). It looked like this:

Code: Select all

DblClick:
Gui, dp:submit, noHide
; Below several lines adapted from TidBit's 2015 Get A Date.
If (A_GuiControlEvent=1 && (A_TickCount-tics)<=DllCall("GetDoubleClickTime") ) {
	;MsgBox,  dbl click? %A_GuiControlEvent%
	gosub, dpButtonSubmit
}
Else If (A_GuiControlEvent=1) 
	tics:=A_TickCount

HolidayList()
HoliArr := StrSplit(theseHolis, "`n")
Loop, 5 {
If (HoliArr[A_Index]) ; might not show if date+holidate is >= Len(33)
	GuiControl,, HoliTxt%A_Index%, % HoliArr[A_Index]
else
	GuiControl,, HoliTxt%A_Index%,
}
Return
When like the above, the text updates upon roling the mouse wheel, or using arrow keys. This is the effect I want. BUT... This causes the double-click to stop working. The way I'm reading the logic, the lower part of the section should always trigger. It would be redundant when there was a double-click, since that would close the gui... But that's okay.

With the top version (of the three smaller code boxes), The lower part of the subroutine is inside of the Else If block, and the GuiControls DO update if I click the calendar, but not if I mouse-wheel or arrow press.

So the question is: How can I make it so the double-click works, but also the holiday parts update as desired?

Also... A related interesting observation.... Tidbit's double-click code assess whether A_GuiControlEvent=1. In the docs though
https://www.autohotkey.com/docs/v1/Variables.htm#GuiControlEvent
It doesn't mention a 1 ever being returned. It suggests that either Normal or DoubleClick will be returned. I put some debugging MsgBox spots in there, though, and I did see the 1. Only upon double clicking though. Single-click, mouse-wheels, or arrows all return Normal.

EDIT: Also tried this

Code: Select all

DblClick:
Gui, dp:submit, noHide
;MsgBox, A_EventInfo is: %A_EventInfo%
;MsgBox, A_GuiControlEvent is: %A_GuiControlEvent%
; Below several lines adapted from TidBit's 2015 Get A Date.
;If (A_GuiControlEvent=1 && (A_TickCount-tics)<=DllCall("GetDoubleClickTime") ) {
If (A_GuiControlEvent=1 && (A_TickCount-tics)<=500 ) {
	;MsgBox,  dbl click? %A_GuiControlEvent%
	gosub, dpButtonSubmit
}
Else If (A_GuiControlEvent=1)
	tics:=A_TickCount
Else If (A_EventInfo=0) {
;MsgBox, A_GuiControlEvent above hol() is: %A_GuiControlEvent%
HolidayList()
HoliArr := StrSplit(theseHolis, "`n")
Loop, 5 {
If (HoliArr[A_Index]) ; might not show if date+holidate is >= Len(33)
	GuiControl,, HoliTxt%A_Index%, % HoliArr[A_Index]
else
	GuiControl,, HoliTxt%A_Index%,
}
}
Return
Mouse wheel month navigation is good, but no luck otherwise. Interesting thing though... The double-click did seem to register, but only once.
Last edited by kunkel321 on 09 Jun 2023, 08:18, edited 2 times in total.
ste(phen|ve) kunkel

User avatar
kunkel321
Posts: 1049
Joined: 30 Nov 2015, 21:19

Re: Help with A_GuiControlEvent and logic flow...  Topic is solved

Post by kunkel321 » 08 Jun 2023, 16:32

I guess it's solved...
This seems to work:

Code: Select all

DblClick:
Gui, dp:submit, noHide
; Below several lines adapted from TidBit's 2015 Get A Date.
If (A_GuiControlEvent=1 && (A_TickCount-tics)<=DllCall("GetDoubleClickTime") )
	gosub, dpButtonSubmit
Else If (A_GuiControlEvent=1)
	tics:=A_TickCount
Else If (A_GuiControlEvent="Normal") {
	HolidayList()
	HoliArr := StrSplit(theseHolis, "`n")
	Loop, 5 {
	If (HoliArr[A_Index]) ; might not show if date+holidate is >= Len(33)
		GuiControl,, HoliTxt%A_Index%, % HoliArr[A_Index]
	else
		GuiControl,, HoliTxt%A_Index%,
	}
}
Return
ste(phen|ve) kunkel

Post Reply

Return to “Ask for Help (v1)”