Skip to main content
GameDev.net gamedev.net
🔒 Locked

WinAPI - CreateWindow

Started by rafek May 18, 2008 at 2:46 AM 10 replies 1.3k views
Original Post
rafek
rafek
Hi! I have a problem with creating window using WinAPI (I'm a winapi beginner). When I write this: if(!(hwnd = CreateWindowExA(NULL, WINDOW_CLASS_NAME, "Your Basic Window", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 400, 400, NULL,NULL, hInstance, NULL))) [where WINDOW_CLASS_NAME is #define WINDOW_CLASS_NAME "WINCLASS1"] I get a window but on a title bar there is: "Your Basi" Why this string is cut? :(
Promethium
Promethium
Are you compiling with or without Unicode support? Try changing to
CreateWindowEx(NULL, WINDOW_CLASS_NAME, TEXT("Your Basic Window"), WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 400, 400, NULL,NULL, hInstance, NULL)
or disable unicode support (in the project properties in Visual Studio).

Edit: In general, avoid using the xA or xW versions, just use the function without ending, and the compiler will choose the right version for you.
rafek
rafek
Thank's a lot :)
hkBattousai
hkBattousai
Why do we use TEXT() macro?

I always write
"Your Basic Window"
instead of
TEXT("Your Basic Window")
and it works without any problem.
Headkaze
Headkaze
Quote:
Original post by Battousai
Why do we use TEXT() macro?

I always write
"Your Basic Window"
instead of
TEXT("Your Basic Window")
and it works without any problem.


Depends on if your compiling for UNICODE support or not. If you have UNICODE/_UNICODE set in your preprocessor definitions then it will use the WCHAR version of the functions which is a wide character. Using the TEXT() macro ensures the correct char size is used for text.

CreateWindowA() <-- 8-bit ANSI char
CreateWindowW() <-- 16-bit UNICODE WCHAR

But as Promethium said don't use the *A or *W versions just let the compiler choose depending on if you have the UNICODE/_UNICODE variables set.
Firecore
Firecore
Are there any performance gains in using unicode?
Promethium
Promethium
No, unicode is a way of representing text that allows you to do things you can't do with ANSI/ASCII text, for instance print asian glyphs: Wikipedia entry for Unicode. It has nothing to do with performance.
rafek
rafek
Again me.. I put some string resource to my resource file and I try do this:
char window_name[80];
if(!LoadString(hInstance, ID_STRING_WINDOW_NAME, window_name, 80))
return 0;

and then I get: rror C2664: 'LoadStringW' : cannot convert parameter 3 from 'char [80]' to 'LPWSTR' [..]

and error C2664: 'CreateWindowExW' : cannot convert parameter 3 from 'char [80]' to 'LPCWSTR' becouse I want to use window_name as lpWindowName in CreateWindow..
Help! :) And thanks in advance..

Screenshot: http://rafek.winweb.pl/shot01220.jpg

[Edited by - rafek on May 18, 2008 6:54:47 AM]
Headkaze
Headkaze
I thought we just explained this? Change char to WCHAR since your obviously compiling for UNICODE support. Also if you need to convert a char to WCHAR use MultiByteToWideChar()
rafek
rafek
Thanks. I'm a little confused about this UNICODE stuff. Thanks anyway. :)
Colin Jeanne
Colin Jeanne
Quote:
Original post by Firecore
Are there any performance gains in using unicode?


If you're running on a Windows NT-flavored OS (NT, 2000, XP, Vista) then there will be a performance gain. The A versions of the Win32 API functions will convert their string arguments from narrow-characters into wide-characters and then call the W versions of the same functions.

If you're running on a 9x-flavored OS (95, 98, ME) then the opposite is true.
Headkaze
Headkaze
Quote:
Original post by Colin Jeanne
If you're running on a Windows NT-flavored OS (NT, 2000, XP, Vista) then there will be a performance gain. The A versions of the Win32 API functions will convert their string arguments from narrow-characters into wide-characters and then call the W versions of the same functions.

If you're running on a 9x-flavored OS (95, 98, ME) then the opposite is true.


Very interesting never knew this!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.