Control Focus inside DateGadget Text Field

Just starting out? Need help? Post your questions and find answers here.
Randy Walker
Enthusiast
Enthusiast
Posts: 478
Joined: Sun Jul 25, 2004 4:21 pm
Location: US

Control Focus inside DateGadget Text Field

Post by Randy Walker »

Windows DateGadget Super Guru needed here I think...

The text box of the DateGadget appears to be split into separate fields for each component used in the date format, so in this sample code there are 3 fields where I am using the format as mm/dd/yy

Code: Select all

If OpenWindow(0, 0, 0,  120, 50, "DateGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  DateGadget(0, 10, 5, 80, 25, "%mm/%dd/%yy", Date(), #PB_Date_UpDown)
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
If you run the code and click the up or down control arrows in the DateGadget box you will see the focus defaults to the first field, rotating values in the month field.
I want the 2nd field (in this case, the day field) to take focus as the default, or if not the default then force focus onto the 2nd field immediately after executing the program code.

Obviously I could swap the format to be dd/mm/yy but thats not our native format so I much prefer to keep the mm/dd/yy format. If there is any hope of manipulating focus in that text box I expect it would involve a Windows API, which is fine. I hunted through MS resources and found mountains of documentation on the "Date and Time Picker Controls", but as usual highly esoteric and waaay over my head.
- - - - - - - - - - - - - - - -
Randy
IF (PureBasic > PowerBasic) AND (PowerBasic > Visual_Basic) THEN PureBasic RULES!!!!
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Control Focus inside DateGadget Text Field

Post by Dude »

This gives it the focus, then does a right keypress to select the second item:

Code: Select all

If OpenWindow(0, 0, 0,  120, 50, "DateGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  DateGadget(0, 10, 5, 80, 25, "%mm/%dd/%yy", Date(), #PB_Date_UpDown)
  SetActiveGadget(0)
  keybd_event_(#VK_RIGHT,0,0,0)
  keybd_event_(#VK_RIGHT,0,#KEYEVENTF_KEYUP,0)
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Randy Walker
Enthusiast
Enthusiast
Posts: 478
Joined: Sun Jul 25, 2004 4:21 pm
Location: US

Re: Control Focus inside DateGadget Text Field

Post by Randy Walker »

Haha, wow! Thanks Dude! I tried something similar using postmessage but no joy:

Code: Select all

  PostMessage_(CallBox1,#WM_KEYDOWN,#VK_RIGHT,$00000000)
  PostMessage_(CallBox1,#WM_KEYUP,#VK_RIGHT,$80000000) 
Your solution works perfectly. Been away too long and forgot all about keybd_event

Lots of new faces here in the forum. Good to see some familiar faces still here too.
Also good to see Super Gurus can still swoop in and save the day.
Thanks again Dude!! :)
- - - - - - - - - - - - - - - -
Randy
IF (PureBasic > PowerBasic) AND (PowerBasic > Visual_Basic) THEN PureBasic RULES!!!!
User avatar
blueb
Addict
Addict
Posts: 1041
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Control Focus inside DateGadget Text Field

Post by blueb »

This may be of some use, and uses a Windows Callback:

Code: Select all

;==================================================================
;
; Author:     Shardik    
; Date:       January  15, 2016
; Explain:
;           
; Typical Usage:    Indicates if Calendar (DateGadget) is dropped down or collapsed.      
;==================================================================

Procedure WindowCallback(WindowHandle.I, Message.I, WParam.I, LParam.I)
  Protected *Notify.NMDATETIMECHANGE 

  If Message = #WM_NOTIFY
    *Notify = LParam

    Select *Notify\nmhdr\code
      Case #DTN_DROPDOWN
        Debug "Calendar is dropped down"
      Case #DTN_CLOSEUP
        Debug "Calendar is closed"
    EndSelect
  EndIf

  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

OpenWindow(0, 100, 100, 200, 200, "DateGadget")
SetWindowCallback(@WindowCallback())
DateGadget(0, 10, 10, 180, 25, "Date: %mm/%dd/%yyyy")

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
- It was too lonely at the top.

System : PB 6.10 Beta 9 (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
Post Reply