我用Visual c++ 2005
请问我在MFC application中用MessageBox("abc"),有错误
error C2664: 'CWnd::MessageBoxW' : cannot convert parameter 1 from 'const char [4]' to 'LPCTSTR',
这是为什么?MessageBox()的后两参数不是缺省的吗?

解决方案 »

  1.   

    一共有两个 MessageBox ,一个是全局的,一个是 CWnd 的成员函数。
    你说的后两个参数省略的 MessageBox,是CWnd::MessageBox,有3个参数,其中两个有缺省参数
    int MessageBox( LPCTSTR lpszText, LPCTSTR lpszCaption = NULL, UINT nType = MB_OK );而全局的 MessageBox,有4个参数,而且没有缺省参数。
    int MessageBox(
      HWND hWnd,          // handle of owner window
      LPCTSTR lpText,     // address of text in message box
      LPCTSTR lpCaption,  // address of title of message box
      UINT uType          // style of message box
    );
      

  2.   

    我用的是VC6,不知道和你的VC2005有什么区别。不过道理应该是一样的。另外好像还有一个 CWindow::MessageBox ,不过我从来没用过。
      

  3.   

    很感谢palmax(南宫煌)的帖子,可是为什么一定要加_T()呢?另外同样非常感谢sungengyu(快乐机器)等人!怎么给你们加分?
      

  4.   

    _T 是个宏,上网搜一下就知道了。或者查看《Windows程序设计》