void GetSelectedDate(HWND hwndMonthCal, HWND hwndLabel)
{
SYSTEMTIME time;
TCHAR date[50];
ZeroMemory(&time, sizeof(SYSTEMTIME));
SendMessage(hwndMonthCal, MCM_GETCURSEL, 0, (LPARAM) &time);
_stprintf(date, _T("%d/%d/%d"), time.wMonth, time.wDay, time.wYear);
SetWindowText(hwndLabel, date);
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
static HWND hwndMonthCal;
static HWND hwndLabel;
switch(msg)
{
case WM_CREATE: {
INITCOMMONCONTROLSEX icex;
hwndLabel = CreateWindow(TEXT("STATIC"), TEXT(""),
WS_CHILD | WS_VISIBLE,
80, 240, 80, 30,
hwnd, (HMENU)1, NULL, NULL);
icex.dwSize = sizeof(icex);
icex.dwICC = ICC_DATE_CLASSES;
InitCommonControlsEx(&icex);
hwndMonthCal = CreateWindowEx(0, MONTHCAL_CLASS, TEXT(""),
WS_BORDER | WS_CHILD | WS_VISIBLE | MCS_DAYSTATE,
20, 20, 200, 200, hwnd, (HMENU)2, NULL, NULL);
GetSelectedDate(hwndMonthCal, hwndLabel);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_NOTIFY: {
LPNMHDR lpNmHdr;
lpNmHdr = (LPNMHDR) lParam;
if (lpNmHdr->code==MCN_SELECT) {
GetSelectedDate(hwndMonthCal, hwndLabel);
}
}
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}