Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the defos_set_window_title() #127

Merged
merged 1 commit into from
Jan 31, 2022
Merged

Fixing the defos_set_window_title() #127

merged 1 commit into from
Jan 31, 2022

Conversation

e1e5en-gd
Copy link
Contributor

Changing parameter encoding when window title changes. Fix #126

Changing parameter encoding when window title changes
@subsoap
Copy link
Owner

subsoap commented Jan 31, 2022

2022-01-31 12_06_29-______

What I see when testing, but it is different from before (which was garbled characters) so I'll assume it does work and just requires Russian / Chinese / etc. to be enabled in the OS for chars to properly display? I don't know enough about this to say.

Thank you for the patch!

@subsoap subsoap merged commit e362b70 into subsoap:master Jan 31, 2022
@britzl
Copy link
Collaborator

britzl commented Jan 31, 2022

What I see when testing, but it is different from before (which was garbled characters) so I'll assume it does work and just requires Russian / Chinese / etc. to be enabled in the OS for chars to properly display?

I don't think that's the case. When I tested the change in the engine itself I got it to show a Russian title on my Win 10.

@e1e5en-gd what did you test with?

@e1e5en-gd
Copy link
Contributor Author

@britzl, I tested on Windows 11.
image

If I'm not mistaken, then:
• if the characters are displayed incorrectly, then this is a problem in the encoding;
• if instead of characters one character is displayed (a question mark, for example), then the font does not support these characters.

@subsoap, you can ask you to try in the project settings to change the name to a string with Russian characters "Привет, мир!". If the name is displayed correctly, then the problem is in my modifications. If question marks are displayed, then the system font may not support these characters.

@britzl
Copy link
Collaborator

britzl commented Feb 1, 2022

@subsoap, you can ask you to try in the project settings to change the name to a string with Russian characters "Привет, мир!". If the name is displayed correctly, then the problem is in my modifications. If question marks are displayed, then the system font may not support these characters.

Good point. This would be a quick way of testing if it works or not!

@e1e5en-gd
Copy link
Contributor Author

Also tried on Windows 7:
image

@subsoap
Copy link
Owner

subsoap commented Feb 1, 2022

I tried again with 192 beta but it's still the same for me.

DefOSWinTitle.zip

2022-02-01 04_00_30-___ Defos _______

But then I tried just setting the window title with 192 game.project and it does display properly. So there must be something missing or done wrong somewhere.

2022-02-01 04_04_19-我使用

2022-02-01 04_05_20-Я установил этот заголовок с помощью Defos

Setting the window title after this doesn't help, still shows as ???s for me.

@subsoap
Copy link
Owner

subsoap commented Feb 1, 2022

Also

2022-02-01 04_06_56-______, ___!

vs

2022-02-01 04_08_12-Привет, мир!

@e1e5en-gd
Copy link
Contributor Author

e1e5en-gd commented Feb 1, 2022

I'll try to reproduce the error myself (I'll try to change the system language). Is it possible to somehow display values from the C++ extension to see what comes in the argument, how is the recoding done? I'm not very good at understanding how to work with the extension

@e1e5en-gd
Copy link
Contributor Author

@subsoap How does the previous version with CA2W work with Russian characters?

@e1e5en-gd
Copy link
Contributor Author

e1e5en-gd commented Feb 1, 2022

In the above working example in Defold, the code is as follows:

wchar_t unicode_title[MAX_WINDOW_TITLE_LENGTH];
int res = MultiByteToWideChar(CP_UTF8, 0, title, -1, &unicode_title, MAX_WINDOW_TITLE_LENGTH);
if (res <= 0)
{
    unicode_title[0] = 0;
}
(void) SetWindowTextW( _glfwWin.window, unicode_title );

When editing in the extension and transferring this code, I cursed at & in the MultiByteToWideChar function. As a result, the code is written like this:

wchar_t unicode_title[MAX_WINDOW_TITLE_LENGTH];
int res = MultiByteToWideChar(CP_UTF8, 0, title_lua, -1, unicode_title, MAX_WINDOW_TITLE_LENGTH);
if (res <= 0)
{
    unicode_title[0] = 0;
}
SetWindowTextW(dmGraphics::GetNativeWindowsHWND(), unicode_title);

Now I decided to check and display the results that comes to the input and we get after the conversion. To do this, I use a MessageBox and thought, suddenly converting LPCWSTR is not enough (so I added it):

MessageBox(
    NULL,
    (LPCSTR)title_lua,
    (LPCSTR)"Input",
    MB_ICONINFORMATION | MB_OK | MB_DEFBUTTON1
);
wchar_t unicode_title[MAX_WINDOW_TITLE_LENGTH];
int res = MultiByteToWideChar(CP_UTF8, 0, title_lua, -1, unicode_title, MAX_WINDOW_TITLE_LENGTH);
if (res <= 0)
{
    unicode_title[0] = 0;
}
MessageBoxW(
    NULL,
    unicode_title,
    (LPCWSTR)L"Without (LPCWSTR)",
    MB_ICONINFORMATION | MB_OK | MB_DEFBUTTON1
);
MessageBoxW(
    NULL,
    (LPCWSTR)unicode_title,
    (LPCWSTR)L"With (LPCWSTR)",
    MB_ICONINFORMATION | MB_OK | MB_DEFBUTTON1
);
SetWindowTextW(dmGraphics::GetNativeWindowsHWND(), (LPCWSTR)unicode_title);

My results are the following:
imageimageimage

Unfortunately, there is no way I can reproduce the error that occurs. So I ask you to try. I'm not very good at C++. Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changing the window title
3 participants