Jump to content
Sign in to follow this  
jdicerch

Trying to tweak an input box with dates.

Recommended Posts

jdicerch

The date picker didn't seem to do too much for me, so I am trying to tweak it to suit my needs.  Currently when you use the date picker and choose to type in the date, you must type in "MM" (press right-arrow), "DD" (press right-arrow), "YYYY".  I want the user to just be able to fluidly type in the date and as you type it automatically inserts the slashes.  So after I type in, for example, 08 it will automatically show the slash and will automatically move to the next item (the day).  Is this possible?  Suggestions on how to do this?

If I am not clear as to what I am asking please let me know, I really appreciate any help.

 

Share this post


Link to post
Share on other sites
Melba23

jdicerch,

You could do it like this: :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Test", 200, 200, 800, 200)
$cDate = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20)
GUISetState()

$DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW
GUICtrlSendMsg($cDate, $DTM_SETFORMAT_, 0, "dd/MM/yyyy")

GUIRegisterMsg($WM_NOTIFY, "_WM_Notify")

Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE


Func _WM_Notify($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    Local Const $DTN_FIRST = -760
    Local Const $DTN_DATETIMECHANGE = $DTN_FIRST + 1

    Local $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return

    If DllStructGetData($tagNMHDR, 3) = $DTN_DATETIMECHANGE Then
        ControlSend($hGUI, "", $cDate, "{RIGHT}")
    EndIf

EndFunc   ;==>_WM_Notify
But I less than convinced that what you are trying to do is a good idea. It works fine if the date is correctly entered, but can lead to all sorts of problems if not. I would suggest to leave it well alone - the "right-arrow to move on" event was no doubt put there for a reason. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
jdicerch

HA THAT IS PERFECT.  Thank you very much :)  and I ask the user to confirm the date before I continue with anything!  Thanks again, that is great.

Share this post


Link to post
Share on other sites
jdicerch

Now the default of the date is the current date, is there anyway to default the text to MM/DD/YYYY (so they actually see it as that)

Share this post


Link to post
Share on other sites
Melba23

jdicerch,

This line sets the displayed date format:

GUICtrlSendMsg($cDate, $DTM_SETFORMAT_, 0, "dd/MM/yyyy")
Just adjust the string to "MM/dd/yyyy" - if you really must use that awful format. :(

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
jdicerch

You are just helping me out all over the place today :)

And I wasn't very clear.  I have that line in, but on the actual GUI itself I want to actually see the letters MM/DD/YYYY in the date picker.  Not a date.  Can I set strings in there or is this not very feasible.

Share this post


Link to post
Share on other sites
FireFox

@Melba23

Nice example, I didn't know that :)


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
BrewManNH

jdicerch,

This line sets the displayed date format:

GUICtrlSendMsg($cDate, $DTM_SETFORMAT_, 0, "dd/MM/yyyy")
Just adjust the string to "MM/dd/yyyy" - if you really must use that awful format. :(

M23

 

You know, it wasn't all that long ago that the UK used the same format for dates. ;)


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Melba23

BrewManNH,

Just as well we changed then! :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
jdicerch

So that's a no then on showing MM/DD/YYYY as default :D  If I can't do that, after they press the add button how can I reset the date picker to the current date with your WM_NOTIFY.  Will this work or no?

GUICtrlSetData($date, @MON & "/" & @MDAY & "/" & @YEAR)

Share this post


Link to post
Share on other sites
Melba23

jdicerch,

 

So that's a no then on showing MM/DD/YYYY as default

Not at all - just how fast do you think we work? :huh:

I am not at all sure that it can be done - but as I have been busy modifying my ExtMsgBox to respond to yet another of your many threads, I have not really had time to look at it properly. Be patient, my good man - even miracles take a little time! ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Melba23

jdicerch,

This is the best I can do. You need to click on the mask to activate the Date control, which always shows the current date - pressing "Add" replaces the mask:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Date.au3>

$hGUI = GUICreate("Test", 200, 200, 800, 200)
$cDate = GUICtrlCreateDate(_NowCalc(), 10, 10, 185, 20)
GUICtrlSetState($cDate, $GUI_HIDE)

$cEdge = GUICtrlCreateLabel("", 10, 10, 185, 20)
GUICtrlSetState($cEdge, $GUI_DISABLE)
GUICtrlSetBkColor($cEdge, 0)
$cMask = GUICtrlCreateLabel("MM/DD/YYYY", 11, 11, 183, 18, $SS_CENTERIMAGE)

$cAdd = GUICtrlCreateButton("Add", 10, 100, 80, 30)
GUICtrlSetState($cAdd, $GUI_FOCUS)

GUISetState()

$DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW
GUICtrlSendMsg($cDate, $DTM_SETFORMAT_, 0, "MM/dd/yyyy")

GUIRegisterMsg($WM_NOTIFY, "_WM_Notify")

GUICtrlSetState($cDate, $GUI_FOCUS)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cAdd
            GUICtrlSetState($cDate, $GUI_HIDE)
            GUICtrlSetState($cMask, $GUI_SHOW)
            GUICtrlSetState($cEdge, $GUI_SHOW)
            GUICtrlSetData($cDate, _NowCalc())
        Case $cMask
            GUICtrlSetState($cEdge, $GUI_HIDE)
            GUICtrlSetState($cMask, $GUI_HIDE)
            GUICtrlSetState($cDate, BitOr($GUI_SHOW, $GUI_FOCUS))
    EndSwitch
WEnd

Func _WM_Notify($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    Local Const $DTN_FIRST = -760
    Local Const $DTN_DATETIMECHANGE = $DTN_FIRST + 1

    Local $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return

    Switch DllStructGetData($tagNMHDR, 3)
        Case $DTN_DATETIMECHANGE
            ControlSend($hGUI, "", $cDate, "{RIGHT}")
    EndSwitch

EndFunc   ;==>_WM_Notify

How does that suit? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
jdicerch

haha very interesting way to go about it! Thanks for your input (thumbs-up)

Share this post


Link to post
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
Sign in to follow this  

×