Quantcast
Channel: Active questions tagged utf-8 - Stack Overflow
Viewing all articles
Browse latest Browse all 1039

keyboard writes windows-1252 text to an edit control using UTF-8 [closed]

$
0
0

I was writing a text editor following theForger's Win32 API tutorial. I didn't have much trouble following it and making it work.

However, since the macros defaulted to -A functions, the text was being written and displayed in my system's codepage (Windows-1252). Since I had the UTF-8 checkbox enabled on my computer, I tried making my program work with that encoding so I could write any character, and while the text it showed was UTF-8 encoded, the text I wrote into it was in Windows-1252.

Here's the code that creates the edit control:

switch (message)    {        case WM_CREATE:        {            HFONT default_font;            HWND editor_hdl;            editor_hdl = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",                                WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL                                | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,                                0, 0, 100, 100, hwnd,                                reinterpret_cast<HMENU>(ctrls::IDC_MAIN_EDIT),                                GetModuleHandle(nullptr), nullptr);            // Error handling            if(!editor_hdl){                MessageBox(hwnd, "There was an error while creating your paper sheet, program will now close.","Oh no", MB_OK | MB_ICONERROR);                SendMessage(hwnd, WM_CLOSE, 0, 0);            }            default_font = reinterpret_cast<HFONT>(GetStockObject(SYSTEM_FONT));            SendMessage(editor_hdl, WM_SETFONT,                        reinterpret_cast<WPARAM>(default_font), MAKELPARAM(FALSE, 0));    //...        }        break;    //...    }            

If I write an international character in this panel with my keyboard, like:

ñ

this appears

I then saved the text and opened it with Notepad++ using Windows-1252 as the encoding and the ñ displayed correctly.

The function dedicated to loading seems to work fine, as it's able to load UTF-8 encoded text files into the edit panel with no problem.

I used MinGW as my compiler, and Code::Blocks as my IDE. I added -fexec-charset=UTF-8 and -finput-charset=UTF-8 as compiler flags. However, I don't think they made my project work with UTF-8, as it was still UTF-8 after recompiling without those flags. Honestly, I don't know what would've enabled UTF-8 into my application.


Viewing all articles
Browse latest Browse all 1039

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>