# A small problem with CreateWindow()

This topic is 2896 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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.hbrBackground		= (HBRUSH)(COLOR_WINDOW+1);
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 on other sites
What happens if you change
(LPCWSTR)"Foo"

to
TEXT("Foo")

?

I personally have never encountered any problems when using that macro.

##### Share on other sites
Thank you both for the speedy replies.

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

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