将CDateTimeCtrl,CMonthCalCtrl,SysDateTimePick32本地化为巴西葡萄牙语语言环境。 [英] Localize the CDateTimeCtrl, CMonthCalCtrl, SysDateTimePick32 to the Brazilian Portuguese locale.

查看:172
本文介绍了将CDateTimeCtrl,CMonthCalCtrl,SysDateTimePick32本地化为巴西葡萄牙语语言环境。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对使用CDateTimeCtrl,CMonthCalCtrl和SysDateTimePick32的应用程序进行增强。



新要求是将CDateTimeCtrl,CMonthCalCtrl,SysDateTimePick32本地化为巴西葡萄牙语语言环境,这些控件应显示巴西葡萄牙语的日期和月份名称。



我无法更改操作系统的语言环境。



我尝试使用SetThreadLocale(0416),但它没有用。



这个应用程序的几个模块是使用WPF构建,改变线程文化帮助我实现了我的要求。但是,我坚持使用这些控件。



这些控件可能无法在线程级别进行本地化但我不确定。



由于我的时间不多,所以对此有任何帮助。

I am doing an enhancement on an application that uses a CDateTimeCtrl, CMonthCalCtrl and SysDateTimePick32.

The new requirement is to localize the CDateTimeCtrl, CMonthCalCtrl, SysDateTimePick32 to the Brazilian Portuguese locale such that these controls should show the day and month names in Brazilian Portuguese language.

I can not change the locale of the Operating System.

I tried using the SetThreadLocale(0416), but it did not work.

The few modules of this application is built using WPF and there altering the thread culture helped me to achieve my requirement. But, I am stuck with these controls.

These controls might not localization on thread level but I am not sure.

Any help on this is much appreciated as I am running out of time.

推荐答案

至少对于较旧的Windows版本,这是不可能的(总是使用Windows用户区域设置)。来自 DTM_SETFORMAT [ ^ ]表示在未使用用户定义的格式时可以使用Vista及以后:

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:

DTP控件在使用默认格式字符串时跟踪区域设置更改。如果您设置自定义格式字符串,则不会更新它以响应区域设置更改。

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.

但这也可能仅适用于用户区域设置。



对于CDateTimeCtrl,您可以派生自己的类来执行日期/时间字符串的格式化(未经测试):

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)
{
	// Must set the value before the format.
	// The format callback handlers need a valid date/time!
	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'); // 64 character buffer
	// Create string here passing the locale, the format, and 
	//  m_dt.GetAsSystemTime() to GetDateFormat(Ex) or GetTimeFormat(Ex) resp. 
	// The format string can be hard coded or retrieved using GetLocaleInfo(Ex).
	*pResult = 0;
}

void CMyDateTimeCtrl::OnDtnFormatQuery(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMDATETIMEFORMATQUERY pDTFmtQuery = reinterpret_cast<LPNMDATETIMEFORMATQUERY>(pNMHDR);

	// Set pDTFmtQuery->szMax.cx and pDTFmtQuery->szMax.cy here
	
	// Dynamic calculation (LPCTSTR lpszMaxText is max. length text):
	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;
}}


这篇关于将CDateTimeCtrl,CMonthCalCtrl,SysDateTimePick32本地化为巴西葡萄牙语语言环境。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆