UNICODE doesn't work in fullscreen mode

Started by
13 comments, last by Wessam Bahnassi 18 years, 4 months ago
hi all I have met a problem with UNICODE when switching from window mode to fullscreen mode. In window mode, I can input characters in UNICODE (by catching message WM_CHAR), but in fullscreen mode, I can't. Some characters are replaced with squares. Here is my code:

#include <vector>
using namespace std;
#include "tiny_application.h"


class TinyGUIDemo: public TinyApplication
{
private:
	LPD3DXFONT m_pFont;
	LPD3DXSPRITE m_pSprite;
//	WCHAR text[200];
	vector<WCHAR> text;

public:
	TinyGUIDemo():TinyApplication(L"TinyGUI Demo", Resolution(800, 600),
		Resolution(800, 600), false, Color(0, 0, 0, 255)){}
	~TinyGUIDemo(){}

	bool OnInit()
	{
		m_pFont = 0;
		HRESULT hr = D3DXCreateFont(GetDevice(), 20, 10, 1, 1, false, DEFAULT_CHARSET,
			OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Courier New", &m_pFont);
		if (FAILED(hr)) return false;
		m_pSprite = 0;
		hr = D3DXCreateSprite(GetDevice(), &m_pSprite);
		if (FAILED(hr)) return false;

		WCHAR t[200] = L"Hôm nay c&#361;ng có th&#7875; coi là m&#7897;t ngày &#273;&#7865;p tr&#7901;i\n&#272;ÚNG KHÔNG ?\n";
		size_t len = 0;
		StringCchLength(t, 100, &len);
		for (int i = 0; i < len; ++i)
			text.push_back(t);

		return true;
	}

	bool OnRender()
	{
		m_pSprite->Begin(D3DXSPRITE_ALPHABLEND);
		RECT rc;
		rc.top = 20;
		rc.left = 20;
		rc.bottom = 800;
		rc.right = 600;
		m_pFont->DrawText(m_pSprite, &text[0], text.size(), &rc, DT_LEFT | DT_WORDBREAK, D3DCOLOR_ARGB(255, 255, 255, 255));
		m_pSprite->End();
		return true;
	}

	void OnDeviceLost()
	{
		m_pSprite->OnLostDevice();
	}

	void OnDeviceFound()
	{
		m_pSprite->OnResetDevice();
	}

	void OnDestroy()
	{
		SAFE_RELEASE(m_pFont);
		SAFE_RELEASE(m_pSprite);
	}

	LRESULT HandleMessage(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
	{
		switch (msg)
		{
		case WM_KEYDOWN:
			if (wparam == VK_F11)
				ToggleDisplay();
			else if (wparam == VK_ESCAPE)
				PostMessage(GetHwnd(), WM_CLOSE, 0, 0);
			break;
		case WM_CHAR:
			if ((WCHAR)wparam == VK_BACK)
				text.pop_back();
			else if ((WCHAR)wparam == VK_RETURN)
				text.push_back(L'\n');
			else
				text.push_back((WCHAR)wparam);
			break;
		default:
			return DefWindowProc(hwnd, msg, wparam, lparam);
		}
		return 0;
	}
};

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, INT)
{
	TinyGUIDemo demo;
	demo.Run();
	return 0;
}


Is there any thing wrong ?
Advertisement
anyone helps me ?

I can input UNICODE chars in windowed mode.
why can't I input correct UNICODE chars in fullscreen mode? Is there something change when I switch from windowed mode to fulscreen mode ? After switching to fullscreen mode, Windows send ANSI (not UNICODE) chars (with WM_CHAR) ?
I have set charset to UNICODE in project properties.

please help
thanks
in windowed-mode, I use function IsWindowUnicode(HWND) to test if the window is unicode, it returns true. But after switching to fullscreen mode, the function IsWindowUnicode(HWND) returns false. [headshake] [headshake] [headshake]
Quote:IsWindowUnicode documentation
The character set of a window is determined by the use of the RegisterClass function. If the window class was registered with the ANSI version of RegisterClass (RegisterClassA), the character set of the window is ANSI. If the window class was registered with the Unicode version of RegisterClass (RegisterClassW), the character set of the window is Unicode

Are you sure you're registering your window class with RegisterClassW all the time?

Quote:Original post by Muhammad Haggag
Quote:IsWindowUnicode documentation
The character set of a window is determined by the use of the RegisterClass function. If the window class was registered with the ANSI version of RegisterClass (RegisterClassA), the character set of the window is ANSI. If the window class was registered with the Unicode version of RegisterClass (RegisterClassW), the character set of the window is Unicode

Are you sure you're registering your window class with RegisterClassW all the time?

Yes, I'm sure. I have set charset to UNICODE in project properties.
IsWindowUnicode returns true in windowed-mode, but returns false in fullscreen mode although it's the same window.
Mmm. That's interesting. I've posted a pointer to this thread in a private MVP newsgroup, so hopefully someone who knows will shed a light.

This is quite error-prone. Set the character setting to Unicode in the project properties and use TCHAR everywhere. That way the compiler will scream if something is not unicode.
Every time you implement a singleton, God kills a kitten. Please, think of the kittens!
Quote:
Mmm. That's interesting. I've posted a pointer to this thread in a private MVP newsgroup, so hopefully someone who knows will shed a light.

here is my code. If you don't mind, take a look at it.
thanks for your help.

DOWNLOAD CODE
I took a look at the code, and it looks fine to me. Perhaps this is a bug with IsWindowUnicode. However, I didn't have any character display problems either in fullscreen or windowed mode. I could input Arabic text and it'd display just fine.

Give this another day. If nobody helps you, take it to DIRECTXDEV.

EDIT: Here's a suggestion from one of the MVPs.
Quote:Perhaps it's D3D's hooked window proc that's doing this? How about
subclassing the window's wndproc right after the device has gone full screen
(make sure you call the old wndproc instead of DefaultWndProc()).

Same here. I can correctly write unicode text both on windowed and full-screen mode. So it seems that only IsWindowUnicode() that's giving a bad reading.
I've checked if anything has changed in the window/class style during display changes, but everything is fine. And guess what, Spy++ still reports that your window is unicode... Really strange :|

This topic is closed to new replies.

Advertisement