Just tried and the code below works fine for me with any combination. Note that you might want to set the font for your edit control to some monospaced type.
HINSTANCE g_hInstance = (HINSTANCE)GetModuleHandle(NULL);
HWND g_hMainWnd = NULL;
bool g_MovingMainWnd = false;
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
static HFONT font = CreateFontW(
25, 0, 0, 0,
if (HWND hEdit = ::CreateWindowExW(0, L"Edit", L"", WS_CHILD|WS_VISIBLE|WS_BORDER, 0, 0, 150, 50, hWnd, (HMENU)1, g_hInstance, NULL))
SendMessageW(hEdit, WM_SETFONT, (WPARAM)font, 0);
SendMessageW(hEdit, WM_SETTEXT, 0, (LPARAM)L"\x07\x08\x10\x11_XYZ");
if (HDC dc = BeginPaint(hWnd, &ps))
HGDIOBJ orig_font = SelectObject(dc, font);
rt.top += 60;
static const wchar_t TXT = L"\x04\x0b\x11_XYZ";
DrawTextW(dc, TXT, wcslen(TXT), &rt, DT_LEFT|DT_TOP|DT_NOPREFIX|DT_INTERNAL);
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
static const wchar_t CLASS_NAME = L"MainWndClass";
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = g_hInstance;
wc.lpfnWndProc = &MainWndProc;
wc.lpszClassName = CLASS_NAME;
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
g_hMainWnd = CreateWindowExW(
WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT, 300, 200,
while (GetMessageW(&msg, NULL, 0, 0))
EDIT: Modified the source code. The original code was written on Win7. I tested it on my WinXP SP2 at home and it didn't work for me. My opinion is that it has something to do with the fonts (they don't contain characters below 32) because on my system the only font that worked is the Terminal, but that font has only really crappy low resolution characters. What I recommend is to get a good font that contains every characters, embed it to your program for example as a resource and then load it for your program like this: How to Use a Font Without Installing it
I checked some MS codepages on the internet and they don't contain glyphs for control characters: http://msdn.microsoft.com/en-us/library/cc195060.aspx
]. Maybe on newer operating systems they patched some of their fonts...
You should search for free IMB 437 DOS codepage or whaterver fonts on the internet. Don't forget to check out the license of the font before embedding it to your app!!!
EDIT: I havent check why did the old code work on Win7 but it can have the following reasons:
1. The default font there contained the control characters.
2. DrawText() on Win7 might used character substitution that drew the missing control characters using another font
I checked that in a Word processor I can copy paste in special characters with many fonts, but that might be the effect of font substitution. What I recommend is checking out your binary font files with a font editor program. A free multiplatform font editor program is fontforge, it works quite well but its crossplatform gui is a bit awful. Currently I don't have time for this.