unicode producing wrong language

Hi,

I am taking my first steps in learning to use winAPI and am following a tutorial. I have run into problems because my strings are coming out as Chinese rather than English. (Note I am currently located in China, though my location as specified in the regional and language options in the windows XP control panel is Australia.) For example, "The title of my window" comes out in Chinese.

I can change the language of the message boxes to English by simply using MessageBoxA. I have been trying to do something similar with CreateWindowExA and RegisterClassExA but to no avail. And even if I could succeed this would seem to only be treating the symptom! If I get to creative and start type changing, my compiler (Visual C++, 2008 Express Edition) complains that it cannot convert g_szClassName to the required type when it is referenced in the registration of the window class.

Can someone explain how to use unicode but get English (and preferably explain why I am not getting English!).

Or as a second best - could someone explain how to use CreateWindowExA etc to avoid the problem and let me continue learning without being frustrated by my text coming out in Chinese...

Code included below.

Thanks!

---------------------------------------

#include <windows.h>

const char g_szClassName[] = "myWindowClass";

// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;

//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}

// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"The title of my window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);

if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}

ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);

// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}

Use code tags: http://cplusplus.com/articles/firedraco1/

Can someone explain how to use unicode but get English (and preferably explain why I am not getting English!).


Well for starters you'd have to use Unicode. It doesn't look like you are here.

My guess is you have a weird locale setting and your lack of Unicode is causing it to pick a code page, and it's picking the wrong one.

I wrote an article on being Unicode friendly in WinAPI. I'd recommend you give it a skim:

http://cplusplus.com/forum/articles/16820/

A few general notes:

- put string literals in the _T() macro. _T("my string litera")
- use TCHAR instead of char or wchar_t
Last edited on
Thanks a lot Disch - I read your artlice and using TCHAR and _T solved the problem.

(Also - I had assumed that win32 projects used unicode by default. I guess not...)
Topic archived. No new replies allowed.