   Basic API Question
  Okay, I've been runnin through the first couple chapters of Programming Windows this afternoon; now I'm a little curious.  At the end of Chap 2, the author gives a program made to list your screen size.(Note, now would be a good time to say I'm already noticing the "chaotic mess" another member compared the Win32 API to...)Well, program given was roughly 35-40 lines long, and demonstrated "formatted texting" in a message box.  I shortened it down to this:_____________________________________________________________________#include <stdio.h> //for sprintf#include <Windows.h>#include <tchar.h> //Will explain this one...#define __UNICODE //And this one...int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){   int xScreenSize, yScreenSize;   char screenSizeMsg[1024];   xScreenSize = GetSystemMetrics(SM_CXSCREEN);   yScreenSize = GetSystemMetrics(SM_CYSCREEN);   sprintf(screenSizeMsg, "Your screen is %i pixels in width, and %pixels in height.\nYour resolution is %i x %i, xScreenSize, yScreenSize, xScreenSize, yScreenSize);   MessageBoxA(NULL, screenSizeMsg, "Screen Resolution", MB_OK | MB_ICONHAND);   return 0;}___________________________________________________While this successfully cut the program in half, it left me wonderin a few things...1) Just as a matter of personal curiosity, would this be just as easy with wide characters (wchar_t or TCHAR)? I have the tchar.h header included and was experimenting, but if I tried to use a wide character, it wasn't allowed as a buffer in sprintf().  But, if I use standard 8-bit char datatypes like this, I'm stuck using MessageBoxA() instead of MessageBox() itself, which I'd rather do just as a matter of principal.  Obviously, I'm new at the API, but is there something overly obvious that I'm missing which would link the TCHAR datatype (which is apparently prefered in Win32API), the sprintf() and standard MessageBox() function? Essentially, I'm trying to see if formatting wide character strings in printf() style could be done with less than the 35-40 lines used in the Windows Programming example.2) Is definiting __UNICODE still necessary in the newer Windows API? Removing it didn't seem to change a thing for my earlier experiments.Thanks for the help to all of you who take the time!   
  1. Windows offers special implementations of printf for unicode called wprintf. However, if you're using C++ you should consider using wstringstream for this purpose, as it avoids many pitfalls of printf.Unless you're aiming to support Win9x based platforms, feel free to ignore the non-Unicode case completely for your applications.2. If you're using Visual Studio, you can most likely configure whether you want Unicode or not in the Project Properties, which will automatically take care of the respective preprocessor flags. If you're compiling manually via the command line though, you will still need to define the flag yourself.   