Unicode Menu and Title bar

Hi everyone,

I try to display unicode text in the title bar of a window, but as a result only the starting letter is shown, while the rest is clipped.
At the same time i try to load a menu including unicode letters from a .rc file. the result here is that it shows ansi letters properly but shows boxes for the unicode letters.

my .rc file:
1
2
3
4
5
6
7
8
9
10
11
#include "resources.h"

IDR_MENU MENU
BEGIN
    POPUP L"Datei"
    BEGIN
        MENUITEM L"Lektion auswählen",  ID_FILE_OPEN
        MENUITEM L"Beenden",            ID_FILE_EXIT
    END
    MENUITEM L"Über",                   ID_ABOUT
END


resources.h:
1
2
3
#define IDR_MENU                       101
#define ID_FILE_EXIT                   40003
#define ID_ABOUT                       65535 


main.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
WNDCLASSW klass = {
CS_DBLCLKS,
WindowProcedure,
0,
0,
NULL,
LoadIconW(GetModuleHandle(NULL),MAKEINTRESOURCEW(ID_ICON)), //the icon is defined in the resource file as well
LoadCursor(NULL, IDC_ARROW),
(HBRUSH)GetStockObject(WHITE_BRUSH),
MAKEINTRESOURCEW(IDR_MENU),
L"classname"
};


RegisterClassW(&klass);

HWND handle = CreateWindowW(
L"classname",
L"UnicodeText",
WS_OVERLAPPEDWINDOW,
0,
0,
800,
200,
HWND_DESKTOP,
NULL,
NULL,
NULL);

ShowWindow (handle, SW_SHOW);




any solutions?
I'm not particularly familiar with this subject, but are you using a font that can display Unicode and is the resource file saved as Unicode?
I try to display unicode text in the title bar of a window, but as a result only the starting letter is shown, while the rest is clipped.


This tells me it doesn't think it should be displaying wide strings.

Look in your project settings -- somewhere in there it has a drop list that lets you select the character encoding to use. I think the 3 options you have are:

- Not Set
- Use Wide Character Set
- Use Multi-byte Character Set

(but I'm doing this from memory -- so it might not be exactly that).

My guess is you have it set to "Not Set" which might be the default setting. Try each of the other ones out and see if that makes a difference.
i found out that it at least shows the title bar if i dont use unicode versions for the class registering process:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
WNDCLASS klass = {
CS_DBLCLKS,
WindowProcedure,
0,
0,
NULL,
LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(ID_ICON)), //the icon is defined in the resource file as well
LoadCursor(NULL, IDC_ARROW),
(HBRUSH)GetStockObject(WHITE_BRUSH),
MAKEINTRESOURCE(IDR_MENU),
"classname"
};


RegisterClass(&klass);

HWND handle = CreateWindowW(
L"classname",
L"UnicodeText",
WS_OVERLAPPEDWINDOW,
0,
0,
800,
200,
HWND_DESKTOP,
NULL,
NULL,
NULL);

ShowWindow (handle, SW_SHOW);


this will properly display "UnicodeText" on the title bar


I'm not particularly familiar with this subject, but are you using a font that can display Unicode and is the resource file saved as Unicode?


i think the fact that it works with the above fix shows that the font can display unicode...the resource file is saved as UTF-8 like all my project files


Look in your project settings -- somewhere in there it has a drop list that lets you select the character encoding to use. I think the 3 options you have are...


i couldnt find any character encoding options...im using Code::Blocks IDE


any more ideas?
You could just #define UNICODE and avoid having to choose, say CreateWindowW() instead of CreateWindow().
Last edited on
i couldnt find any character encoding options...im using Code::Blocks IDE


Ack. Sorry. I just assumed you were using VS because I saw ".rc" files. I didn't know C::B also used rc files.

I'm out of ideas then. AFAIK, using the W version of WinAPI functions should be making this work. I don't know why it wouldn't be working here. =(
You could just #define UNICODE and avoid having to choose, say CreateWindowW() instead of CreateWindow().


i added it to my header file but it didnt fix my problem...could you give some more detail about how to use it


Ack. Sorry. I just assumed you were using VS because I saw ".rc" files. I didn't know C::B also used rc files.

I'm out of ideas then. AFAIK, using the W version of WinAPI functions should be making this work. I don't know why it wouldn't be working here. =(



well it has no real .rc editor so the support is kinda lousy...i already considered whether that may be the reason why it doesnt work properly...but it doesnt seem very probable to me


im clueless....


EDIT: i fixed the title bar problem
1
2
3
4
5
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
        default:
            return DefWindowProcW (hwnd, message, wParam, lParam);
}

i had forgotten the w after defwindowproc...
now only the menu problem is left...
Last edited on
i added it to my header file but it didnt fix my problem...could you give some more detail about how to use it


It has to be defined BEFORE you include Windows.h

If you're defining it afterwards, it does absolutely nothing.

1
2
3
4
5
#define UNICODE
#define _UNICODE
#include <Windows.h>

// ... the rest of your includes, etc here 
It has to be defined BEFORE you include Windows.h

Ah thats why i never got it working...i defined both UNICODE and _UNICODE now
but the menu still doesnt show unicode characters...
I'm out of ideas =(

Sorry
It could possibly be done the long way.
create the unicode srtings for the menus as string resoutces in the resource file.
Create the menu at runtime - possibly during the WM_CREATE message - loading the appropriate unicode string from the string resouces for the menu text.

I'll try this sometime and see if it works.



On the other hand - this being windows - you can go to control panel
and add the appropriate keyboard for the particular language.
Then when editing the resouce menu text - just switch to the appropriate
keyboard...


Mind you, I'm thinking about foreign language entry, and may be off the mark
Last edited on
Hmm so i tried to create the menu at run time now.

resource.rc:
1
2
3
4
STRINGTABLE
BEGIN
        ID_MENU_ABOUT,      L"Über"
END


resource.h:
#define ID_MENU_ABOUT 6

main.cpp:
1
2
3
4
5
HMENU menu = GetMenu(document.handle);
wchar_t string[200];
LoadStringW(GetModuleHandle(NULL),ID_MENU_ABOUT,string,sizeof(string));
AppendMenuW(menu,MF_ENABLED,(UINT)CreateMenu(),string);
DrawMenuBar(document.handle);


this gives me the same output...normal letters are fine...unicode letters are just random symbols



this works though:
1
2
3
HMENU menu = GetMenu(document.handle);
AppendMenuW(menu,MF_ENABLED,(UINT)CreateMenu(),L"Über");
DrawMenuBar(document.handle);




it seems there is a general problem loading unicode resources...
if nobody has an idea about how to solve this ill just stop using resources and define all the wchar_t strings in another header or something...
Topic archived. No new replies allowed.