Sign in to follow this  
Culgan

A small problem with CreateWindow()

Recommended Posts

Hi folks, I am just getting started with DirectX programming and have encountered a small problem regarding CreateWindow(). It's not a major issue, as the code compiles, and a blank window is created as expected - however my niggle is this: In the title bar of the window, instead of the specified title that I would like it to have, I am being shown a number of odd characters (mainly squares) followed by the final letter of the string that I am passing to parameter 2 of the CreateWindow(). I have done a bit of googling and can find no solutions to the problem. I shall paste the small amount of code that I think is causing the problem (I won't bother you with the rest of it, it's pretty boring :P)
bool initWindow( HINSTANCE hInstance )
{
	WNDCLASSEX wcex;

	wcex.cbSize			= sizeof(WNDCLASSEX);
	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc		= (WNDPROC)WndProc;
	wcex.cbClsExtra			= 0;
	wcex.cbWndExtra			= 0;
	wcex.hInstance			= hInstance;
	wcex.hIcon			= 0;
	wcex.hCursor			= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground		= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName		= NULL;
	wcex.lpszClassName		= (LPCWSTR)"Foo";
	wcex.hIconSm			= 0;
	RegisterClassEx(&wcex);


	LPCWSTR appName = (LPCWSTR)"Foo";
	LPCWSTR titlebarText = (LPCWSTR)"Bar";

	wndHandle = CreateWindow(
				appName,
				titlebarText,
				WS_OVERLAPPEDWINDOW,
				CW_USEDEFAULT,
				CW_USEDEFAULT,
				640,
				480,
				NULL,
				NULL,
				hInstance,
				NULL);


I will endeavour on while I accumulate some replies (which would be appreciated), but don't feel you need to rush to my aid, as it's such a minor issue. Much love! Culgan

Share this post


Link to post
Share on other sites
What happens if you change
(LPCWSTR)"Foo"


to
TEXT("Foo")


?

I personally have never encountered any problems when using that macro.
More information about TEXT(str) can be found here.

Share this post


Link to post
Share on other sites
Thank you both for the speedy replies.

The problem was rectified after reading the first article you posted Evil Steve.

About the second one:

I'll be honest, I'm learning DirectX from a collection of books that I have purchased.
When I saw that it was casting the WndProc function pointer, it brought back some scary memories from when I first started programming C++, and a number of instances when casting function pointers has been used by people I work with - which let's say did not have the desired effect.

So, I was wary of the fact that the book I am learning from seems to recommend using this method, I shall proceed with due care.

Thank you again for your help.

Culgan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this