I am trying to change the style and date format of the
DateTimePicker
control on combobox'
CBS_SELCHANGE
notification.
When user selects one option, datetime picker should have spin control and show only year. If user selects other options, style should be reset to short date style and date format should show date as
dd.mm.yyyy
.
Here is the code I have so far:
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_COMBO5:
{
if (HIWORD(wParam) == CBN_SELENDOK)
{
int iSelected = ComboBox_GetCurSel((HWND)lParam);
switch (i)
{
case 1:
{
DWORD_PTR dwStyle =
GetWindowLongPtr(GetDlgItem(hDlg,
IDC_DATETIMEPICKER1), GWL_STYLE);
dwStyle &= ~DTS_SHORTDATEFORMAT;
dwStyle |= DTS_UPDOWN;
SetWindowLongPtr(GetDlgItem(hDlg,
IDC_DATETIMEPICKER1), GWL_STYLE, dwStyle);
DateTime_SetFormat(GetDlgItem(hDlg,
IDC_DATETIMEPICKER1), L"yyyy");
}
break;
case -1:
case 0:
case 2:
default:
{
DWORD_PTR dwStyle =
GetWindowLongPtr(GetDlgItem(hDlg,
IDC_DATETIMEPICKER1), GWL_STYLE);
dwStyle &= ~DTS_UPDOWN;
dwStyle |= DTS_SHORTDATEFORMAT;
SetWindowLongPtr(GetDlgItem(hDlg,
IDC_DATETIMEPICKER1), GWL_STYLE, dwStyle);
DateTime_SetFormat(GetDlgItem(hDlg,
IDC_DATETIMEPICKER1), L"dd'|'MM'|'yyyy");
}
break;
}
}
}
break;
Format gets changed properly, but spin control doesn't get added at all.
Running through debugger, I can see that it goes through my code and throws no exceptions -> I went to
Debug->Exceptions
and checked everything under
Thrown
.
I work on Windows 7 x86, using Visual Studio 2013.
I am targeting XP onward.
Can you help me to fix my code so I can achieve desired behavior?