Jump to content

argumentum
 Share

Recommended Posts

I really want to have this, so, it's a head start ( and example ) of coloring this control ( or part of it so far )
So don't be shy and pitch in :D

 DateTimePickerTest.pngDateTimePickerTest_W10dark.png

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiDateTimePicker.au3>
#include <WindowsConstants.au3>
#include <WinAPITheme.au3>
#include <GuiMonthCal.au3>

Global $g_hDTP1, $g_hDTP2, $g_idMemo

Example()

Func Example()
    Local $hGUI

    ; Create GUI
    $hGUI = GUICreate("DateTimePick coloring test", 500, 300)

    $g_idMemo = GUICtrlCreateEdit("", 2, 62, 496, 266, BitOR($GUI_SS_DEFAULT_EDIT,$ES_READONLY))
    GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
    GUICtrlSetData($g_idMemo, "MonthCal child handle will be created each time it pops up." & @CRLF & @CRLF, 1)

    $g_hDTP1 = GUICtrlGetHandle(GUICtrlCreateDate("", 2, 6,  185, 20))
    $g_hDTP2 = _GUICtrlDTP_Create($hGUI, 2, 32, 240)

    GUICtrlCreateLabel("<-- now we need to find how to color", 195, 5, 500, 20)
    GUICtrlSetFont(-1, 9, 400, 0, "Courier New")
    GUICtrlSetState(-1, $GUI_FOCUS)
    GUICtrlCreateLabel("this part of the control", 280, 30, 500, 20)
    GUICtrlSetFont(-1, 9, 400, 0, "Courier New")
    GUICtrlSetState(-1, $GUI_FOCUS)

    GUISetState(@SW_SHOW)

    ; Set the display format
    _GUICtrlDTP_SetFormat($g_hDTP1, "ddd MMM dd, yyyy hh:mm ttt")
    _GUICtrlDTP_SetFormat($g_hDTP2, "ddd MMM dd, yyyy hh:mm ttt")

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    WinActivate("DateTimePick coloring test")
    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo, $tBuffer, $tBuffer2, $iCtrl

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $g_hDTP1, $g_hDTP2
            Switch $iCode
                Case $NM_SETFOCUS
                    _WinAPI_SetThemeAppProperties(0)
                    _DebugPrint("$NM_SETFOCUS" & @CRLF & "-->hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)

                Case $NM_KILLFOCUS
                    _WinAPI_SetThemeAppProperties(3)
                    _DebugPrint("$NM_KILLFOCUS" & @CRLF & "-->hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)

                Case $DTN_DROPDOWN ; Sent by a date and time picker (DTP) control when the user activates the drop-down month calendar
                    _DebugPrint("$DTN_DROPDOWN" & @CRLF & "-->hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; The return value for this notification is not used

                    ; Get month control child handle
                    $iCtrl = _GUICtrlDTP_GetMonthCal($hWndFrom)

;~                  _WinAPI_SetWindowTheme($iCtrl, "", "") ; setting this here, does not change the size of the original canvas
;~                                                         ; instead, for my simplicity, use _WinAPI_SetThemeAppProperties() OnFocus

                    GUICtrlSetData($g_idMemo, "MonthCal child Handle: " & "0x" & Hex($iCtrl) & @CRLF, 1)
                    _GUICtrlMonthCal_SetColor($iCtrl, $MCSC_TEXT, 0x8BD4DF)
                    _GUICtrlMonthCal_SetColor($iCtrl, $MCSC_TITLEBK, 0xA9D7E4)
                    _GUICtrlMonthCal_SetColor($iCtrl, $MCSC_TITLETEXT, 0x005894)
                    _GUICtrlMonthCal_SetColor($iCtrl, $MCSC_MONTHBK, 0x3F3F3F)
                    _GUICtrlMonthCal_SetColor($iCtrl, $MCSC_TRAILINGTEXT, 0xB2C2A9)

                Case $DTN_CLOSEUP ; Sent by a date and time picker (DTP) control when the user closes the drop-down month calendar
                    _DebugPrint("$DTN_CLOSEUP" & @CRLF & "-->hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; The return value for this notification is not used

                Case $DTN_DATETIMECHANGE ; Sent by a date and time picker (DTP) control whenever a change occurs
                    $tInfo = DllStructCreate($tagNMDATETIMECHANGE, $lParam)
                    _DebugPrint("$DTN_DATETIMECHANGE" & @CRLF & "-->hWndFrom:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @CRLF & _
                            "-->IDFrom:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @CRLF & _
                            "-->Code:" & @TAB & DllStructGetData($tInfo, "Code") & @CRLF & _
                            "-->Flag:" & @TAB & DllStructGetData($tInfo, "Flag") & @CRLF & _
                            "-->Year:" & @TAB & DllStructGetData($tInfo, "Year") & @CRLF & _
                            "-->Month:" & @TAB & DllStructGetData($tInfo, "Month") & @CRLF & _
                            "-->DOW:" & @TAB & DllStructGetData($tInfo, "DOW") & @CRLF & _
                            "-->Day:" & @TAB & DllStructGetData($tInfo, "Day") & @CRLF & _
                            "-->Hour:" & @TAB & DllStructGetData($tInfo, "Hour") & @CRLF & _
                            "-->Minute:" & @TAB & DllStructGetData($tInfo, "Minute") & @CRLF & _
                            "-->Second:" & @TAB & DllStructGetData($tInfo, "Second") & @CRLF & _
                            "-->MSecond:" & @TAB & DllStructGetData($tInfo, "MSecond"))
                    Return 0

                Case $DTN_FORMAT ; Sent by a date and time picker (DTP) control to request text to be displayed in a callback field
                    $tInfo = DllStructCreate($tagNMDATETIMEFORMAT, $lParam)
                    $tBuffer = DllStructCreate("char Format[128]", DllStructGetData($tInfo, "Format"))
                    $tBuffer2 = DllStructCreate("char Display[64]", DllStructGetData($tInfo, "pDisplay"))
                    _DebugPrint("$DTN_FORMAT" & @CRLF & "-->hWndFrom:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @CRLF & _
                            "-->IDFrom:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @CRLF & _
                            "-->Code:" & @TAB & DllStructGetData($tInfo, "Code") & @CRLF & _
                            "-->Format:" & @TAB & DllStructGetData($tBuffer, "Format") & @CRLF & _
                            "-->Year:" & @TAB & DllStructGetData($tInfo, "Year") & @CRLF & _
                            "-->Month:" & @TAB & DllStructGetData($tInfo, "Month") & @CRLF & _
                            "-->DOW:" & @TAB & DllStructGetData($tInfo, "DOW") & @CRLF & _
                            "-->Day:" & @TAB & DllStructGetData($tInfo, "Day") & @CRLF & _
                            "-->Hour:" & @TAB & DllStructGetData($tInfo, "Hour") & @CRLF & _
                            "-->Minute:" & @TAB & DllStructGetData($tInfo, "Minute") & @CRLF & _
                            "-->Second:" & @TAB & DllStructGetData($tInfo, "Second") & @CRLF & _
                            "-->MSecond:" & @TAB & DllStructGetData($tInfo, "MSecond") & @CRLF & _
                            "-->Display:" & @TAB & DllStructGetData($tBuffer2, "Display"))
                    Return 0

                Case $DTN_FORMATQUERY ; Sent by a date and time picker (DTP) control to retrieve the maximum allowable size of the string that will be displayed in a callback field
                    $tInfo = DllStructCreate($tagNMDATETIMEFORMATQUERY, $lParam)
                    $tBuffer = DllStructCreate("char Format[128]", DllStructGetData($tInfo, "Format"))
                    _DebugPrint("$DTN_FORMATQUERY" & @CRLF & "-->hWndFrom:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @CRLF & _
                            "-->IDFrom:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @CRLF & _
                            "-->Code:" & @TAB & DllStructGetData($tInfo, "Code") & @CRLF & _
                            "-->Format:" & @TAB & DllStructGetData($tBuffer, "Format") & @CRLF & _
                            "-->SizeX:" & @TAB & DllStructGetData($tInfo, "SizeX") & @CRLF & _
                            "-->SizeY:" & @TAB & DllStructGetData($tBuffer2, "SizeY"))
                    DllStructSetData($tInfo, "SizeX", 64)
                    DllStructSetData($tInfo, "SizeY", 10)
                    Return 0

                Case $DTN_USERSTRING ; Sent by a date and time picker (DTP) control when a user finishes editing a string in the control
                    $tInfo = DllStructCreate($tagNMDATETIMESTRING, $lParam)
                    $tBuffer = DllStructCreate("char UserString[128]", DllStructGetData($tInfo, "UserString"))
                    _DebugPrint("$DTN_USERSTRING" & @CRLF & "-->hWndFrom:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @CRLF & _
                            "-->IDFrom:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @CRLF & _
                            "-->Code:" & @TAB & DllStructGetData($tInfo, "Code") & @CRLF & _
                            "-->UserString:" & @TAB & DllStructGetData($tBuffer, "UserString") & @CRLF & _
                            "-->Year:" & @TAB & DllStructGetData($tInfo, "Year") & @CRLF & _
                            "-->Month:" & @TAB & DllStructGetData($tInfo, "Month") & @CRLF & _
                            "-->DOW:" & @TAB & DllStructGetData($tInfo, "DOW") & @CRLF & _
                            "-->Day:" & @TAB & DllStructGetData($tInfo, "Day") & @CRLF & _
                            "-->Hour:" & @TAB & DllStructGetData($tInfo, "Hour") & @CRLF & _
                            "-->Minute:" & @TAB & DllStructGetData($tInfo, "Minute") & @CRLF & _
                            "-->Second:" & @TAB & DllStructGetData($tInfo, "Second") & @CRLF & _
                            "-->MSecond:" & @TAB & DllStructGetData($tInfo, "MSecond") & @CRLF & _
                            "-->Flags:" & @TAB & DllStructGetData($tInfo, "Flags"))
                    Return 0

                Case $DTN_WMKEYDOWN ; Sent by a date and time picker (DTP) control when the user types in a callback field
                    $tInfo = DllStructCreate($tagNMDATETIMEFORMATQUERY, $lParam)
                    $tBuffer = DllStructCreate("char Format[128]", DllStructGetData($tInfo, "Format"))
                    _DebugPrint("$DTN_WMKEYDOWN" & @CRLF & "-->hWndFrom:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @CRLF & _
                            "-->IDFrom:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @CRLF & _
                            "-->Code:" & @TAB & DllStructGetData($tInfo, "Code") & @CRLF & _
                            "-->VirtKey:" & @TAB & DllStructGetData($tInfo, "VirtKey") & @CRLF & _
                            "-->Format:" & @TAB & DllStructGetData($tBuffer, "Format") & @CRLF & _
                            "-->Year:" & @TAB & DllStructGetData($tInfo, "Year") & @CRLF & _
                            "-->Month:" & @TAB & DllStructGetData($tInfo, "Month") & @CRLF & _
                            "-->DOW:" & @TAB & DllStructGetData($tInfo, "DOW") & @CRLF & _
                            "-->Day:" & @TAB & DllStructGetData($tInfo, "Day") & @CRLF & _
                            "-->Hour:" & @TAB & DllStructGetData($tInfo, "Hour") & @CRLF & _
                            "-->Minute:" & @TAB & DllStructGetData($tInfo, "Minute") & @CRLF & _
                            "-->Second:" & @TAB & DllStructGetData($tInfo, "Second") & @CRLF & _
                            "-->MSecond:" & @TAB & DllStructGetData($tInfo, "MSecond"))
                    Return 0

                Case Else
                    _DebugPrint("$DTN_?????" & @CRLF & "-->hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @CRLF & _
            "+======================================================" & @CRLF & _
            "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
            "+======================================================" & @CRLF)
EndFunc   ;==>_DebugPrint

Hopefully it'll turn into a UDF :) 

Edited by argumentum
bettering the code

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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