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.
#include "stdafx.h"
#include <windows.h>
HINSTANCE g_hInstance = (HINSTANCE)GetModuleHandle(NULL);
HWND g_hMainWnd = NULL;
bool g_MovingMainWnd = false;
POINT g_OrigCursorPos;
POINT g_OrigWndPos;
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HFONT font = CreateFontW(
25, 0, 0, 0,
FW_DONTCARE,
FALSE,
FALSE,
FALSE,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH,
L"Terminal");
switch (uMsg)
{
case WM_CREATE:
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");
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
if (HDC dc = BeginPaint(hWnd, &ps))
{
printf("%p\n", font);
HGDIOBJ orig_font = SelectObject(dc, font);
RECT rt;
GetClientRect(hWnd, &rt);
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);
SelectObject(dc, orig_font);
EndPaint(hWnd, &ps);
}
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
}
bool CreateMainWnd()
{
static const wchar_t CLASS_NAME[] = L"MainWndClass";
WNDCLASSW wc;
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;
if (!RegisterClassW(&wc))
return false;
g_hMainWnd = CreateWindowExW(
0,
CLASS_NAME,
L"Main Window",
WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT, 300, 200,
NULL,
NULL,
g_hInstance,
NULL
);
return true;
}
int main()
{
if (!CreateMainWnd())
return -1;
ShowWindow(g_hMainWnd, SW_SHOW);
UpdateWindow(g_hMainWnd);
MSG msg;
while (GetMessageW(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
return (int)msg.wParam;
}
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.