How to set accented characters on a Button in MFC application

SG 35 Reputation points

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()

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)

The charset in my project properties is set to Unicode

Thanks for reading, I hope to find an issue.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,696 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,447 questions
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,562 questions
{count} vote

Accepted answer
  1. Viorel 112.9K Reputation points

    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.

    2 people found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. SG 35 Reputation points

    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

    0 comments No comments