This crashes:
string s = "h:mm tt";
SendMessage(p_DTPicker->m_hwnd, DTM_SETFORMAT, 0, s);
That is the code used by the compiler.
Someone on the net said we need a pointer to a string so I tried this and it works:
string s = "h:mm tt";
SendMessage(p_DTPicker->m_hwnd, DTM_SETFORMAT, 0, &s);
I think it is because SendMessage expects a pointer as the last arg.
Quote from: Rock Ridge Farm (Larry) on April 17, 2007, 05:48:45 PM
I think it is because SendMessage expects a pointer as the last arg.
I think that's right.
But, looking at the source code (always the bargain), CDTPicker::SetFormat sends the string.
Another peculiarity with the date-time picker has to do with setting just the time. I have the style of the control set to just display the time of day. When you send the message to set the time, the SYSTEMTIME structure has to be initialized with a date, even if we don't care about a date, or the API call fails.
SYSTEMTIME tm;
...
m_dlgItem.AddControl(CTDTPicker,"",142, 74, 90,20,ADTS_TIMEFORMAT, 0x200,ID_DTP_TIME);
...
tm.wHour = StrToNum(StrLeft(sTime,StrFind(sTime,":")-1));
tm.wMinute = StrToNum(StrMid(sTime,StrFind(sTime,":")+1,2));
if((StrRight(sTime,2) == "PM") AND (tm.wHour < 12))
tm.wHour += 12;
// need *some* value for date to get control to accept time
tm.wMonth = 1;
tm.wDay = 1;
tm.wYear = 2007;
SendMessage(p_dtpTime->m_hwnd, DTM_SETSYSTEMTIME , 0, &tm);
If it fails, the control sets to the local time.
I try to addcontrol this but nothing appears, I also tried to create it with cdtpicker.create but it doesn't work
Bruce, you need to specify GDT_VALID in wParam:
SendMessage(p_dtpTime->m_hwnd, DTM_SETSYSTEMTIME, GDT_VALID, &tm);
Quote from: ludovico on August 27, 2008, 04:40:18 AM
I try to addcontrol this but nothing appears, I also tried to create it with cdtpicker.create but it doesn't work
Show your code and someone will try to help you.
Larry
I think that it is cause that I try to add this into a MDIChild window
No problem, MonthCal works ;D