# A new way to create a window?

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

## Recommended Posts

I'm transitioning to Visual Studio 2K5 and currently am trying to create a window, however I'm getting errors about the function unable to use standard char *, it requires LPCWSTR. I have no idea what these are, is there any alternative? I typecast my char * to this (the classname, and window title, and even my width and height arguments give me problems) but the window is all wierded out. The window has no pre-defined size (it shrunk to the minimum) and the title is in chinese characters. any help would be more than enjoyed!! -stealthgate

##### Share on other sites
VS 2005 uses the unicode versions of CreateWindow etc by default. You need to pass it unicode strings, rather than ASCII strings. To use these, use the type "WCHAR *" or "LPCWSTR" instead of "char *", and prefix your string literals with L, eg:
CreateWindow(..., L"Title", ...);

##### Share on other sites
thank you so much for the help!!

##### Share on other sites
Or turn off unicode by going to "Project->Properties->Configuration Properties->General->Character Set = Not Set"

jfl.

##### Share on other sites
I prefer using the _T macros because it will use wide characters where needed and regular characters where needed depending on whether UNICODE or MBCS is defined. Here's a simple example that will work the same whether UNICODE or MBCS is defined.
#include <iostream>#include <tchar.h> // definition of TCHAR and lots of good stuff// make sure we use the proper stream// depending on whether UNICODE or MBCS is defined#if defined(UNICODE)    std::wostream &out_stream = std::wcout;#else    std::ostream &out_stream = std::cout;#endifint main(int,char**){   out_stream << _T("Whaddup");   return 0;}

Also in tchar.h there are a lot of the old c-style string functions that are defined to be either the UNICODE or MBCS versions. for example ::_tcslen will be ::wcslen in UNICODE or ::strlen in MBCS. Its very useful and saves time. However, I'm not sure if tchar.h is actually a standard header. But you should be fine using any of the MSVC products at least.

1. 1
2. 2
JoeJ
20
3. 3
frob
17
4. 4
5. 5

• 10
• 10
• 12
• 13
• 9
• ### Forum Statistics

• Total Topics
632197
• Total Posts
3004729

×