A new way to create a window?
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
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", ...);
Or turn off unicode by going to "Project->Properties->Configuration Properties->General->Character Set = Not Set"
jfl.
jfl.
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.
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.
#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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement