At least with older Windows versions this is not possible (uses always the Windows user locale). This cite from
DTM_SETFORMAT[
^] indicates that it might be possible with Vista and later when not using user defined formats:
Quote:
A DTP control tracks locale changes when it is using the default format string. If you set a custom format string, it will not be updated in response to locale changes.
But that might apply also only to the user locale.
For the CDateTimeCtrl you can derive your own class to perform the formatting of the date/time string (untested):
class CMyDateTimeCtrl : public CDateTimeCtrl
{
DECLARE_DYNAMIC(CMyDateTimeCtrl)
public:
void Init(const COleDateTime& dt);
protected:
COleDateTime m_dt;
afx_msg void OnDtnFormat(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnDtnFormatQuery(NMHDR *pNMHDR, LRESULT *pResult);
};
BEGIN_MESSAGE_MAP(CMyDateTimeCtrl, CDateTimeCtrl)
ON_NOTIFY_REFLECT(DTN_FORMAT, OnDtnFormat)
ON_NOTIFY_REFLECT(DTN_FORMATQUERY, OnDtnFormatQuery)
END_MESSAGE_MAP()
void CMyDateTimeCtrl::Init(const COleDateTime& dt)
{
m_dt = (dt.GetStatus() == COleDateTime::valid) ? dt : COleDateTime::GetCurrentTime();
VERIFY(SetTime(m_dt));
VERIFY(SetFormat(_T("X"));
}
void CMyDateTimeCtrl::OnDtnFormat(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMDATETIMEFORMAT pDTFormat = reinterpret_cast<LPNMDATETIMEFORMAT>(pNMHDR);
pDTFormat->szDisplay[0] = _T('\0');
*pResult = 0;
}
void CMyDateTimeCtrl::OnDtnFormatQuery(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMDATETIMEFORMATQUERY pDTFmtQuery = reinterpret_cast<LPNMDATETIMEFORMATQUERY>(pNMHDR);
CDC * pDC = GetDC();
CFont * pFont = GetFont();
CFont Font;
if (!pFont)
{
VERIFY(Font.CreateStockObject(DEFAULT_GUI_FONT));
pFont = &Font;
}
CFont * pOrigFont = pDC->SelectObject(pFont);
VERIFY(::GetTextExtentPoint32(pDC->m_hDC,
lpszMaxText, _tcslen(lpszMaxText),
&pDTFmtQuery->szMax));
pDC->SelectObject(pOrigFont);
ReleaseDC(pDC);
*pResult = 0;
}}