Jump to content

GuiCtrlCreateDate problem


Recommended Posts

I need to set a specific date on the date control so it starts out with a certain date. I can manually change it by clicking the control, but I want it to start out with a specific date. But so far, it only shows today's date when the GUI opens.

I researched this forum, and found that I should use GuiCtrlSendMsg() to set the date. But it always shows today's date.

I also tried using GuiCtrlSetData(), with and without GuiCtrlSendMsg(), and before/after it too. But it always opens with today's date.

I must be missing something. Can anyone show me how to make the control show a specific date when I display the GUI?

I am using this code to test it.

#Include <DateTimeConstants.au3>
#Include <GuiConstantsEx.au3>

;Create GUI.
$GUI = GuiCreate("Date control", 200, 150, 50, 50)
$Date = GUICtrlCreateDate("", 20, 40, 150, 20, $DTS_SHORTDATEFORMAT)
$Cancel = GuiCtrlCreateButton("Cancel", 60, 75, 50, 20)
GUISetState(@SW_SHOW, $GUI)

;This does NOT set date to specified date. 
GUICtrlSendMsg($Date, $DTS_SHORTDATEFORMAT, "M/d/yyyy", "6/1/2010")
MsgBox(0, "test", "Date should be set to 6/1/2010")

;Loop
While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
            
        Case $Cancel
            GUIDelete($GUI)
            ExitLoop
    EndSwitch
WEnd

Dick

Link to comment
Share on other sites

  • Moderators

DickG,

Just set the requried date when you create the control as it suggests in the Help file: :blink:

#Include <DateTimeConstants.au3>
#Include <GuiConstantsEx.au3>

;Create GUI
$GUI = GuiCreate("Date control", 200, 150, 50, 50)

;This does set date to specified date of 17/03/1986.
$Date = GUICtrlCreateDate("1986/03/17", 20, 40, 150, 20, $DTS_SHORTDATEFORMAT)
$Cancel = GuiCtrlCreateButton("Cancel", 60, 75, 50, 20)
GUISetState(@SW_SHOW, $GUI)

;Loop
While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case $Cancel
            GUIDelete($GUI)
            ExitLoop
    EndSwitch
WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Aha! I knew I was missing something. I think I misinterpreted " ... when you create the control" to mean that I could set it with GuiCtrlSetData() or GuiCtrlSendMsg() right after I create the control. Now I understand what that really meant.

Thanks much for the fast reply ...

Dick

DickG,

Just set the requried date when you create the control as it suggests in the Help file: :blink:

#Include <DateTimeConstants.au3>
#Include <GuiConstantsEx.au3>

;Create GUI
$GUI = GuiCreate("Date control", 200, 150, 50, 50)

;This does set date to specified date of 17/03/1986.
$Date = GUICtrlCreateDate("1986/03/17", 20, 40, 150, 20, $DTS_SHORTDATEFORMAT)
$Cancel = GuiCtrlCreateButton("Cancel", 60, 75, 50, 20)
GUISetState(@SW_SHOW, $GUI)

;Loop
While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case $Cancel
            GUIDelete($GUI)
            ExitLoop
    EndSwitch
WEnd

M23

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...