Was ist der Unterschied zwischen...



  • Hallo an alle,

    kann mir bitte jemand sagen was der Unterschied ist zwischen folgenden Ausdrücken:

    CString EinString;
    
    EinString = "HALLO";
    EinString = _T("HALLO");
    EinString.Format("HALLO");
    EinString.Format(_T("HALLO"));
    

    Danke im voraus



  • Alles mit _T("") ist UNICODE.

    Aber ich lasse das lieber Herrn Prosise erklären, der fette Absatz ist der meiner Meinung nach interessanteste.

    Microsoft Windows 98 and Microsoft Windows NT use two different character sets to form characters and strings. Windows 98 and its predecessors use the 8-bit ANSI character set, which is similar to the ASCII character set familiar to many programmers. Windows NT and Windows 2000 use the 16-bit Unicode character set, which is a superset of the ANSI character set. Unicode is ideal for applications sold in international markets because it contains a rich assortment of characters from non-U.S. alphabets. Programs compiled with ANSI characters will run on Windows NT and Windows 2000, but Unicode programs run slightly faster because Windows NT and Windows 2000 don't have to perform an ANSI-to-Unicode conversion on every character. Unicode applications won't run on Windows 98, period, unless you convert every character string passed to Windows from Unicode to ANSI format.

    When an application is compiled, it is compiled to use either ANSI or Unicode characters. If your application will be deployed on both Windows 98 and Windows 2000, it may behoove you to make strings character set neutral. Then, by making a simple change to the project's build settings or adding a #define to a header file, you can tell the compiler whether to produce an ANSI build or a Unicode build. If you encode a string literal like this:

    "Hello"
    

    the compiler forms the string from ANSI characters. If you declare the string like this:

    L"Hello"
    

    the compiler uses Unicode characters. But if you use MFC's _T macro, like this:

    _T ("Hello")
    

    the compiler will emit Unicode characters if the preprocessor symbol _UNICODE is defined, and ANSI characters if it is not. If all your string literals are declared with _T macros, you can produce a special Windows NT_only build of your application by defining _UNICODE. Defining this symbol implicitly defines a related symbol named UNICODE (no underscore), which selects the Unicode versions of the numerous Windows API functions that come in both ANSI and Unicode versions. Of course, if you'd like the same executable to run on either platform and you're not concerned about the performance hit an ANSI application incurs under Windows NT, you can forget about the _T macro. I'll use _T throughout this book to make the sample code character set neutral.

    Das ist aus: Programming Windows with MFC

    Das Kapitel geht noch ein Stück weiter, aber ich hoffe, der Ausschnitt hat gereicht.

    PS: Hat hier jemand die deutsche Übersetzung von diesem Buch? Oder weiß jemand wo ich die herkriegen kann? Nix gegen Englisch, aber manchmal ist es echt anstrengend. Oder kennt jemand ein gleichwertiges Buch?


Anmelden zum Antworten