Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to customize date format in DTPicker created through CreateWindowEx

How to customize date format in DTPicker created through CreateWindowEx

Scheduled Pinned Locked Moved Visual Basic
helptutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    genie13
    wrote on last edited by
    #1

    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 Long

    Private mlnghwndDate As Long

    Private Const LOCALE_STIMEFORMAT As Long = &H1003 'time format string
    Private Const LOCALE_SSHORTDATE As Long = &H1F 'short date format string

    Private Const DTM_SETFORMAT = &H1032

    Private Const WS_CHILD = &H40000000
    Private Const WS_VISIBLE = &H10000000

    Private 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

    N 1 Reply Last reply
    0
    • G genie13

      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 Long

      Private mlnghwndDate As Long

      Private Const LOCALE_STIMEFORMAT As Long = &H1003 'time format string
      Private Const LOCALE_SSHORTDATE As Long = &H1F 'short date format string

      Private Const DTM_SETFORMAT = &H1032

      Private Const WS_CHILD = &H40000000
      Private Const WS_VISIBLE = &H10000000

      Private 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

      N Offline
      N Offline
      nishkarsh_k
      wrote on last edited by
      #2

      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

      G 1 Reply Last reply
      0
      • N nishkarsh_k

        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

        G Offline
        G Offline
        genie13
        wrote on last edited by
        #3

        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.

        J 1 Reply Last reply
        0
        • G genie13

          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.

          J Offline
          J Offline
          Johan Hakkesteegt
          wrote on last edited by
          #4

          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.

          G 1 Reply Last reply
          0
          • J Johan Hakkesteegt

            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.

            G Offline
            G Offline
            genie13
            wrote on last edited by
            #5

            Hi I know now where the problem was. DTM_SETFORMAT should be &H1005. I looked it up at commctrl.h. My mistake. I just copied the previous value somewhere in the internet. :laugh:

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups