How to customize date format in DTPicker created through CreateWindowEx
-
I have a DTPicker which I created through CreateWindowEx. I want to show the date format in my DTPicker as date (space) time. For example, "4/22/2009 13:00:00" I used DTM_SETFORMAT but either it doesn't work, or I was doing something wrong. :confused: There are no compile/run-time errors. It's just that garbage characters are displayed on the DTPicker. Hope you could help me out. Thanks in advance!
Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long
Private Declare Function GetLocaleInfo Lib "kernel32" _
Alias "GetLocaleInfoA" _
(ByVal Locale As Long, _
ByVal LCType As Long, _
ByVal lpLCData As String, _
ByVal cchData As Long) As LongPrivate mlnghwndDate As Long
Private Const LOCALE_STIMEFORMAT As Long = &H1003 'time format string
Private Const LOCALE_SSHORTDATE As Long = &H1F 'short date format stringPrivate Const DTM_SETFORMAT = &H1032
Private Const WS_CHILD = &H40000000
Private Const WS_VISIBLE = &H10000000Private Sub CreateDTPicker
' assuming that lnghWnd\_Sub and lnghInstance were previously set mlnghwndDate = CreateWindowEx(0, "SysDateTimePick32", vbNullString, \_ WS\_CHILD + WS\_VISIBLE, 0, 0, 85, 20, lnghWnd\_Sub, 0, lnghInstance, Null) Dim lcid As Long lcid = GetSystemDefaultLCID() Dim sFormat As String Dim sTemp As String Dim bufLen As Long bufLen = 256 sTemp = String(bufLen, vbNullChar) bufLen = GetLocaleInfo(lcid, LOCALE\_SSHORTDATE, sTemp, bufLen) sFormat = Left(sTemp, bufLen - 1) bufLen = 256 sTemp = String(bufLen, vbNullChar) bufLen = GetLocaleInfo(lcid, LOCALE\_STIMEFORMAT, sTemp, bufLen) sFormat = sFormat & " " & Left(sTemp, bufLen - 1) If SendMessageSTRING(mlnghwndDate, DTM\_SETFORMAT, 0, sFormat) <> 1 Then 'Display Error Message End If
End Sub
-
I have a DTPicker which I created through CreateWindowEx. I want to show the date format in my DTPicker as date (space) time. For example, "4/22/2009 13:00:00" I used DTM_SETFORMAT but either it doesn't work, or I was doing something wrong. :confused: There are no compile/run-time errors. It's just that garbage characters are displayed on the DTPicker. Hope you could help me out. Thanks in advance!
Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long
Private Declare Function GetLocaleInfo Lib "kernel32" _
Alias "GetLocaleInfoA" _
(ByVal Locale As Long, _
ByVal LCType As Long, _
ByVal lpLCData As String, _
ByVal cchData As Long) As LongPrivate mlnghwndDate As Long
Private Const LOCALE_STIMEFORMAT As Long = &H1003 'time format string
Private Const LOCALE_SSHORTDATE As Long = &H1F 'short date format stringPrivate Const DTM_SETFORMAT = &H1032
Private Const WS_CHILD = &H40000000
Private Const WS_VISIBLE = &H10000000Private Sub CreateDTPicker
' assuming that lnghWnd\_Sub and lnghInstance were previously set mlnghwndDate = CreateWindowEx(0, "SysDateTimePick32", vbNullString, \_ WS\_CHILD + WS\_VISIBLE, 0, 0, 85, 20, lnghWnd\_Sub, 0, lnghInstance, Null) Dim lcid As Long lcid = GetSystemDefaultLCID() Dim sFormat As String Dim sTemp As String Dim bufLen As Long bufLen = 256 sTemp = String(bufLen, vbNullChar) bufLen = GetLocaleInfo(lcid, LOCALE\_SSHORTDATE, sTemp, bufLen) sFormat = Left(sTemp, bufLen - 1) bufLen = 256 sTemp = String(bufLen, vbNullChar) bufLen = GetLocaleInfo(lcid, LOCALE\_STIMEFORMAT, sTemp, bufLen) sFormat = sFormat & " " & Left(sTemp, bufLen - 1) If SendMessageSTRING(mlnghwndDate, DTM\_SETFORMAT, 0, sFormat) <> 1 Then 'Display Error Message End If
End Sub
genie13 wrote:
I used DTM_SETFORMAT but either it doesn't work, or I was doing something wrong.
I do not know exactly what you are using. The easiest way do get ur desired format in date picker is use of custom format. Select the date picker format property and opt for custom. Go to custom format and define your desired format You can use "MM/dd/yyy HH:mm:ss" in the custom format string Good luck Nishkarsh
-
genie13 wrote:
I used DTM_SETFORMAT but either it doesn't work, or I was doing something wrong.
I do not know exactly what you are using. The easiest way do get ur desired format in date picker is use of custom format. Select the date picker format property and opt for custom. Go to custom format and define your desired format You can use "MM/dd/yyy HH:mm:ss" in the custom format string Good luck Nishkarsh
-
The Date Picker control was hard coded using CreateWindowEx(), using the class SysDateTimePick32 and I can only set its properties using SendMessageSTRING(). So I cannot perform your suggestion.
Have you tried nishkars suggestion in combination with
Private Const DTM_SETFORMAT = &H1032
In other words, have you experimented with assigning some other value than "&H1032" ? What happens when you enter a string like "dd/MM/yyyy", or something similar ?My advice is free, and you may get what you paid for.
-
Have you tried nishkars suggestion in combination with
Private Const DTM_SETFORMAT = &H1032
In other words, have you experimented with assigning some other value than "&H1032" ? What happens when you enter a string like "dd/MM/yyyy", or something similar ?My advice is free, and you may get what you paid for.