2

Is it possible to change the Day of the Week that the DTPicker control uses for the first day of the week 'on the fly'?

I know that it uses the system first day of the week (as defined in control panel) for this setting but can it be changed to use another day without changing the control panel setting?

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143

1 Answers1

4

Try this, from a post on the old VB6 newsgroup by MikeD

You can do it with a DTPicker using the Win32 API. The DTPicker uses an actual MonthView control. You can send this control a MCM_SETFIRSTDAYOFWEEK message to change the first day of the week. Note that you must (and can only) do this in the DropDown event because prior to that, the MonthView control doesn't exist. The MonthView gets destroyed after the CloseUp event. Oh...the value for the first day of week is the lParam of SendMessage (the wParam is always 0)

Option Explicit 
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" 
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As 
Any) As Long 
Private Const MCM_FIRST                 As Long = &H1000& 
Private Const MCM_SETFIRSTDAYOFWEEK     As Long = (MCM_FIRST + 15) 
Private Const DTM_FIRST                 As Long = &H1000& 
Private Const DTM_GETMONTHCAL           As Long = (DTM_FIRST + 8) 
Private Sub DTPicker1_DropDown() 
    Dim hMonthview As Long 
    'Get hwnd of MonthView control 
    hMonthview = SendMessage(DTPicker1.hwnd, DTM_GETMONTHCAL, 0&, ByVal 0&) 
    'Set first day of week for MonthView, according to the following: 
    '   Value      Day of Week 
    '   0          Monday 
    '   1          Tuesday 
    '   2          Wednesday 
    '   3          Thursday 
    '   4          Friday 
    '   5          Saturday 
    '   6          Sunday 
    Call SendMessage(hMonthview, MCM_SETFIRSTDAYOFWEEK, 0&, ByVal 6&) 'first 
day of week = Sunday
End Sub 
Patrick McDonald
  • 64,141
  • 14
  • 108
  • 120
MarkJ
  • 30,070
  • 5
  • 68
  • 111