Article ID: 193967
Article Last Modified on 12/23/2005
Option Explicit
Private Declare Function FindWindowEx Lib "user32" _
Alias "FindWindowExA" _
(ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
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 CB_GETCURSEL = &H147
Private Const CB_GETLBTEXT = &H148
Private calendarHwnd As Long
Private cboMonthHwnd As Long
Private cboYearHwnd As Long
Private Sub Form_Load()
calendarHwnd = FindWindowEx(Me.hwnd, 0&, "CalendarWndClass", _
vbNullString)
cboMonthHwnd = FindWindowEx(calendarHwnd, 0&, "ComboBox", _
vbNullString)
cboYearHwnd = FindWindowEx(calendarHwnd, cboMonthHwnd, "ComboBox", _
vbNullString)
End Sub
Private Sub Calendar1_NewMonth()
Dim monthIndex As Long, temp As Long
Dim ret As String * 255
ret = Space(255)
' Find 0-based index of the selected item:
monthIndex = SendMessage(cboMonthHwnd, CB_GETCURSEL, 0&, 0&)
' Put month name in ret and length of month name in temp:
temp = SendMessage(cboMonthHwnd, CB_GETLBTEXT, monthIndex, _
ByVal ret)
' uncomment the line below to see if the ComboBox was used:
'If Calendar1.Month = 0 Then Debug.Print "ComboBox used to
'select";
Debug.Print Left(ret, temp) 'Displays Month Name
End Sub
Private Sub Calendar1_NewYear()
Dim yearIndex As Long, temp As Long
Dim ret As String * 255
ret = Space(255)
' Find 0-based index of the selected item:
yearIndex = SendMessage(cboYearHwnd, CB_GETCURSEL, 0&, 0&)
' Put year value in ret and length of year value in temp:
temp = SendMessage(cboYearHwnd, CB_GETLBTEXT, yearIndex, _
ByVal ret)
' uncomment the line below to see if the ComboBox was used:
'If Calendar1.Year = 0 Then Debug.Print "ComboBox used to
'select ";
Debug.Print Left(ret, temp) 'Displays Year
End Sub
Additional query words: kbVBp kbVBp500 kbVBp600 kbCtrl kbdsd kbDSupport
Keywords: kbhowto KB193967