#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)
{
MessageBox(NULL, "This program", "Important windows message", MB_OK);
return(0);
}
it's so simple...
It compiles ok if I exclude the messagebox function, but with it, it doesn't pass the compiler, and I get this error message
1>c:\main2\programming\lean\demo.cpp(9) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [13]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
the book said that the function is expecting a parameter, two strings, and a parameter to change the window's buttons. I don't see what I doing wrong, but then again, this book is from 1999, and I'm running MVC++ 2008 on vista 64 bit, so it could be out of date.
Change it to MessageBoxA, not MessageBox. Unicode is supported by default, which causes it to be replaced with MessageBoxW, which requests a string using wide characters. So, you can either replace it with MessageBoxA, or you can put an L to the left of each of your strings:
A: MessageBoxA(NULL, "This program", "Important windows message", MB_OK);
or B: MessageBox(NULL, "This program"L, "Important windows message"L, MB_OK);
You're the first person to tell me that, but I've seen things all over the internet telling me to just use "MessageBox" without 'L's, and had the same problem every time. The MessageBoxA trick worked perfectly.
Is this a MVC++ only feature, or is this just something that's been accepted recently?
what's a wide character, by the way? I thought a character was just one symbol, like 'a' or '1'.
Does anyone know of any good books to learn windows programming? I only have a gaming book, and I think I'd like to do more than that.
Unicode is a character set the encompasses more than just basic latin characters. It's important for internationalization.
IMO, you should always try to support Unicode unless it's impractical (in widgetry programs, it's almost never impractical since it's so widely supported -- so try to do it)
Here's an article I whipped up a while back regarding Unicode in Win32. It explains what the deal with the 'L' is, what TCHARs are, what LPSTRs are, what the deal with MessageBoxA is., and other stuff you should know that most tutorials don't cover (and/or are oblivious to):
Just wondering, why don't you guys have windows C++ documentation? Just never got around to it?
Because platform specifics are beyond the scope of a C++ reference, what with them, you know, not being part of the language and all.
Besides, the MSDN already is an extensive reference of the Windows API and its cousins.