在DTPicker上更改星期开始日期

时间:2012-01-20 09:37:09

标签: vb6 calendar locale datetimepicker dayofweek

是否可以更改DTPicker控件在一周的第一天“动态”使用的星期几?

我知道它使用系统的第一天(在控制面板中定义)进行此设置但是可以更改为使用另一天而不更改控制面板设置吗?

1 个答案:

答案 0 :(得分:4)

从迈克的post on the old VB6 newsgroup

中试试这个
  

您可以使用Win32 API使用DTPicker执行此操作。 DTPicker使用   一个实际的MonthView控件。您可以将此控件发送MCM_SETFIRSTDAYOFWEEK message以更改一周的第一天。请注意,您必须(并且只能)执行此操作   在DropDown事件中,因为在此之前,MonthView控件   不存在。在CloseUp事件之后,MonthView被销毁。   哦......一周的第一天的值是SendMessage的lParam   (wParam始终为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