'MessageBox' : function does not take 3 arguments

          问题描述:今天在一个非MFC类的成员函数中调用MessageBox()函数的时候提示: 'MessageBox' : function does not take 3 arguments


错误的含义很明显,就是说“Messagebox 这个函数不是三个参数,而你在调用的时候却传递了三个参数”;

首先,看看关于它的的定义:

#ifdef UNICODE
#define MessageBox  MessageBoxW
#else
#define MessageBox  MessageBoxA
#endif // !UNICODE

WINUSERAPI
int
WINAPI
MessageBoxExA(
    __in_opt HWND hWnd,
    __in_opt LPCSTR lpText,
    __in_opt LPCSTR lpCaption,
    __in UINT uType,
    __in WORD wLanguageId);
WINUSERAPI
int
WINAPI
MessageBoxExW(
    __in_opt HWND hWnd,
    __in_opt LPCWSTR lpText,
    __in_opt LPCWSTR lpCaption,
    __in UINT uType,
    __in WORD wLanguageId);


从定义中就可以看出,我们在调用的时候需要指定窗口句柄,因为这不是在MFC环境下;我们可以这样在Win32 Console程序中将hWnd指定为NULL,例如:

::MessageBox(NULL,"测试消息框","测试",MB_OK);


大家都知道我们在MFC框架下,使用MessageBox()的时候只需要传递三个函数,这是由于它会自动获取程序窗口的句柄,所以在MFC环境下使用MessageBox的时候就可以不必给出窗口句柄了.

猜你喜欢

转载自blog.csdn.net/u010260855/article/details/21716061