Try to use the “Save As” command from FILE menu for the source file that contains L"Connecté", select the “Save with Encoding” from dropdown menu of Save button, select the “Unicode” or “Unicode (UTF-8 with signature)” encoding. Do not select the “Unicode (UTF-8 without signature)” encoding.
How to set accented characters on a Button in MFC application
Hi,
I'm developping a little MFC project to drive an Arduino board.
I try to change caption in a Button but accented characters (french) are displayed as garbage.
My code:
void CMFCArduinoDlg::OnBnClickedButtonConnecter()
{
btnConnecter.SetWindowTextW(L"Connecté");
}
The problem is I expected "Connecté" but it appears "Connecté"
The function SetWindowTextW expects a LPCTSTR.
I think the problem is because I give a const wchar_t (L prefix), but I didn't find any other solution to initialise a LPCTSTR.
I think the problem is here because when I design my dialog, the accented text passed to the button in the dialog editor is well displayed when I run the app. The garbage text comes when I call SetWindowTextW (idem with SetWindowText).
For information, Locale is set to French in resource file:
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA)
LANGUAGE LANG_FRENCH, SUBLANG_FRENCH
The charset in my project properties is set to Unicode
Thanks for reading, I hope to find an issue.
Visual Studio
Windows API - Win32
C++
1 additional answer
Sort by: Most helpful
-
SG 35 Reputation points
2023-10-18T11:55:38.6333333+00:00 Are your systems configured to use utf-8 for non-Unicode programs?
No, it's unchecked, it's one of the first things I looked for. I think the problem is with VC configuration