Jump to content

Use a calendar control on a input field [SOLVED]


Recommended Posts

Is it possible to use a input control with a button next to it and when the button is clicked it opens the same calendar as the the GUICtrlCreateDate control (just like a popup).
I want to select the date on the calendar and put the date by something like Guictrlsetdata to the input control.
I don’t want to use GUICtrlCreateDate because I want to have a possibility to have a empty input field.

I don’t have a clue how to make this, I made a small example code where I want this to work.

 

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


GUICreate("", 320, 120)
Local $idFile = GUICtrlCreateInput("", 10, 5, 230, 20)
Local $idBtn = GUICtrlCreateButton("Calendar", 250, 5, 60, 20)

GUISetState(@SW_SHOW)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $idBtn
            ; opens the popup calendar
    EndSwitch
WEnd

 

Edited by nend
Link to comment
Share on other sites

@nend
You could use something like this:

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

Global $hdlGUI = GUICreate("", 320, 120)
Global $idDateTimePicker = _GUICtrlDTP_Create($hdlGUI, 10, 5, 230, 20) ; GUICtrlCreateDate("", 10, 5, 230, 20, $DTS_SHOWNONE)
_GUICtrlDTP_SetFormat($idDateTimePicker, " ")
Global $idBtn = GUICtrlCreateButton("Calendar", 250, 5, 60, 20)

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _GUICtrlDTP_Destroy($idDateTimePicker)
            ExitLoop
        Case $idBtn
            MsgBox($MB_ICONINFORMATION, "", GUICtrlRead($idDateTimePicker))
    EndSwitch
WEnd

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

    Local $tNMHDR, _
          $hdlWindowFrom, _
          $intControlID_From, _
          $intMessageCode


    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    If @error Then Return

    $hdlWindowFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $intMessageCode = DllStructGetData($tNMHDR, "Code")

    Switch $hdlWindowFrom
        Case $idDateTimePicker
            Switch $intMessageCode
                Case $DTN_CLOSEUP
                    If GUICtrlRead($idDateTimePicker) <> 0 Then _GUICtrlDTP_SetFormat($idDateTimePicker, "dd/MM/yyyy HH:mm")
            EndSwitch
    EndSwitch

    $tNMHDR = 0

    Return $GUI_RUNDEFMSG

EndFunc

In few words, using the control create by _GUICtrlDTP_Create() function, you can set the format of the date to " ", in order to display no date (How to set a blank date to a DateTimePicker control).
When you open the DateTimePicker control, and set a date, a format is set, so a date is set in the format you want.
If you leave the DateTimePicker blank, the format is not set.
In this way, you can have a blank (set to 0) DateTimePicker control :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

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...