Page 1 of 1

Set-/GetGadgetState on DateGadget without time

Posted: Wed Nov 22, 2023 11:15 pm
by jacdelad
I ran into a minor inconvenience today: It is possible to assign dates including times (which are not shown within the gadget) to DateGadgets (at least on Windows). I didn't know this and assumed that all operations cut off the times and made the "midnight time" out of the value. So I created a workaround, maybe this is somehow useful to someone else. Just include this code before any Set-/GetGadgetState-call.

Code: Select all

Procedure __SetGadgetState(Gadget.i,State.q)
  If GadgetType(Gadget)=#PB_GadgetType_Calendar
    State=Date(Year(State),Month(State),Day(State),0,0,0)
  EndIf
  ProcedureReturn SetGadgetState(Gadget,State)
EndProcedure

Macro SetGadgetState(ThisGadget,ThisState)
  __SetGadgetState(ThisGadget,ThisState)
EndMacro

Procedure __GetGadgetState(Gadget.i)
  Protected Temp.q=GetGadgetState(Gadget)
  If GadgetType(Gadget)=#PB_GadgetType_Calendar
    Temp=Date(Year(Temp),Month(Temp),Day(Temp),0,0,0)
  EndIf
  ProcedureReturn Temp
EndProcedure

Macro GetGadgetState(ThisGadget)
  __GetGadgetState(ThisGadget)
EndMacro

Re: Set-/GetGadgetState on DateGadget without time

Posted: Thu Nov 23, 2023 9:31 am
by BarryG
jacdelad wrote: Wed Nov 22, 2023 11:15 pmIt is possible to assign dates including times (which are not shown within the gadget) to DateGadgets
Times have always been shown in the DateGadget; it just depends on the width of the gadget. Too small and they get cropped.

Re: Set-/GetGadgetState on DateGadget without time

Posted: Thu Nov 23, 2023 2:28 pm
by jacdelad
Oh really? I never tried that. I use the dialog library and it doesn't even try to show times. Good to know, thanks.

Re: Set-/GetGadgetState on DateGadget without time

Posted: Thu Nov 23, 2023 4:12 pm
by HeX0R

Code: Select all

Procedure.s GetXMLString()
	Protected XML$

	XML$ + "<?xml version='1.0' encoding='UTF-16'?>"
	XML$ + ""
	XML$ + "<dialogs><!--Created by Dialog Design0R V1.85 => get it from: https://hex0rs.coderbu.de/en/sdm_downloads/dialogdesign0r/-->"
	XML$ + "  <window flags='#PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered' name='window_1' xpos='16' ypos='157'>"
	XML$ + "    <vbox>"
	XML$ + "      <date name='date_1' text='%dd.%mm.%yyyy %hh:%ii'/>"
	XML$ + "    </vbox> "
	XML$ + "  </window>"
	XML$ + "</dialogs><!--DDesign0R Definition: PureBasic|1|1|1|_|example_with_declares|0|AddOn:3:0-->"

	ProcedureReturn XML$
EndProcedure
;Test it
a$ = GetXMLString()
ParseXML(0, a$)
CreateDialog(0)
OpenXMLDialog(0, 0, "window_1")
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend