#include <Windows.h>
#include <stdio.h>
LRESULT CALLBACK WinSunProc(
HWND hwnd,      // handle to window
UINT uMsg,      // message identifier
WPARAM wParam,  // first message parameter
LPARAM lParam   // second message parameter
);int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow )
{
WNDCLASS abc;
abc.cbClsExtra=0;
abc.cbWndExtra=0;
abc.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
abc.hCursor=LoadCursor(NULL,IDC_CROSS);
abc.hIcon=LoadIcon(NULL,IDI_ERROR);
abc.hInstance=hInstance;
abc.lpfnWndProc=WinSunProc;
abc.lpszClassName="fb2009";
abc.lpszMenuName=NULL;
abc.style=CS_HREDRAW|CS_VREDRAW;
RegisterClass(&abc);
HWND hwnd;
hwnd=CreateWindow("fb2009","fb2009",WS_OVERLAPPEDWINDOW,0,0,200,100,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinSunProc(
HWND hwnd,      // handle to window
UINT uMsg,      // message identifier
WPARAM wParam,  // first message parameter
LPARAM lParam  // second message parameter
)
{ switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"fb",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","fb",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"计算机编程语言培训",strlen("计算机编程语言培训"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,"维新培训",strlen("维新培训"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的结束?","fb",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;}没绝的有什么错,但是错误提示
>------ 已启动生成: 项目: fb11, 配置: Debug Win32 ------
1>正在编译...
1>main.cpp
1>c:\users\asus\documents\visual studio 2008\projects\fb11\fb11\main.cpp(20) : error C2440: “=”: 无法从“const char [7]”转换为“LPCWSTR”
1>        与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>c:\users\asus\documents\visual studio 2008\projects\fb11\fb11\main.cpp(25) : error C2664: “CreateWindowExW”: 不能将参数 2 从“const char [7]”转换为“LPCWSTR”
1>        与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>c:\users\asus\documents\visual studio 2008\projects\fb11\fb11\main.cpp(49) : error C2664: “MessageBoxW”: 不能将参数 2 从“char [20]”转换为“LPCWSTR”
1>        与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>c:\users\asus\documents\visual studio 2008\projects\fb11\fb11\main.cpp(52) : error C2664: “MessageBoxW”: 不能将参数 2 从“const char [14]”转换为“LPCWSTR”
1>        与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>c:\users\asus\documents\visual studio 2008\projects\fb11\fb11\main.cpp(55) : error C2664: “TextOutW”: 不能将参数 4 从“const char [19]”转换为“LPCWSTR”
1>        与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>c:\users\asus\documents\visual studio 2008\projects\fb11\fb11\main.cpp(62) : error C2664: “TextOutW”: 不能将参数 4 从“const char [9]”转换为“LPCWSTR”
1>        与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>c:\users\asus\documents\visual studio 2008\projects\fb11\fb11\main.cpp(66) : error C2664: “MessageBoxW”: 不能将参数 2 从“const char [15]”转换为“LPCWSTR”
1>        与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>生成日志保存在“file://c:\Users\asus\Documents\Visual Studio 2008\Projects\fb11\fb11\Debug\BuildLog.htm”
1>fb11 - 7 个错误,0 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
请高手指教一下什么原因,,,如何解决

解决方案 »

  1.   

    你用vs2008?我在vc 6.0下调试,一点问题也没有。
      

  2.   

    unicode的问题,把所有字符串都转换成TEXT("")或者 _T("")
    例如,abc.lpszClassName="fb2009";  应该改为abc.lpszClassName=_T("fb2009");改成这样,还需要包含TCHAR.h头文件。
     
      

  3.   

    你的工程使用了UNICODE字符集,把你的 "字符串" 包含的字符串修改为_T("字符串")或者不使用UNICODE字符集即可
      

  4.   

    哎~~ 
    最基本的类型转换。
    UNICODE的代码。
    在所有的常量字符前都加上 _T()或L例
    TextOut(hDC,0,0,_T("维新培训"),strlen("维新培训")); 
    另外strlen必须使用_tcslen
      

  5.   

    如何不使用UNICODE字符集,,呢??,,,该怎么改呢?
      

  6.   

    配置属性   ->   C/C++   ->   预处理器   ->   预处理器定义  
      看看有没有   UNICODE/_UNICODE,   有的话就去掉,   再看看程序中有没有   define   这些东西. 
      

  7.   

    多字节字符集和UNICODE字符集有什么区别呢,,哪个好用点呢
      

  8.   

    所有的都改了后还有一个错误,一个警告
    #include <Windows.h>
    #include <stdio.h>
    #include <TCHAR.h>
    //#define _T
    LRESULT CALLBACK WinSunProc(
    HWND hwnd,      // handle to window
    UINT uMsg,      // message identifier
    WPARAM wParam,  // first message parameter
    LPARAM lParam   // second message parameter
    );int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow )
    {
    WNDCLASS abc;
    abc.cbClsExtra=0;
    abc.cbWndExtra=0;
    abc.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
    abc.hCursor=LoadCursor(NULL,IDC_CROSS);
    abc.hIcon=LoadIcon(NULL,IDI_ERROR);
    abc.hInstance=hInstance;
    abc.lpfnWndProc=WinSunProc;
    abc.lpszClassName=_T("fb2009");
    abc.lpszMenuName=NULL;
    abc.style=CS_HREDRAW|CS_VREDRAW;
    RegisterClass(&abc);
    HWND hwnd;
    hwnd=CreateWindow(_T("fb2009"),_T("fb2009"),WS_OVERLAPPEDWINDOW,0,0,200,100,NULL,NULL,hInstance,NULL);
    ShowWindow(hwnd,SW_SHOWNORMAL);
    UpdateWindow(hwnd);
    MSG msg;
    while (GetMessage(&msg,NULL,0,0))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    return 0;
    }
    LRESULT CALLBACK WinSunProc(
    HWND hwnd,      // handle to window
    UINT uMsg,      // message identifier
    WPARAM wParam,  // first message parameter
    LPARAM lParam  // second message parameter
    )
    { switch(uMsg)
    {
    case WM_CHAR:
    char szChar[20];
    警告   -> sprintf(szChar,"char is %d",wParam);
    错误   -> MessageBox(hwnd,szChar,_T("fb"),0);
    break;
    case WM_LBUTTONDOWN:
    MessageBox(hwnd,_T("mouse clicked"),_T("fb"),0);
    HDC hdc;
    hdc=GetDC(hwnd);
    TextOut(hdc,0,50,_T("计算机编程语言培训"),strlen("计算机编程语言培训"));
    ReleaseDC(hwnd,hdc);
    break;
    case WM_PAINT:
    HDC hDC;
    PAINTSTRUCT ps;
    hDC=BeginPaint(hwnd,&ps);
    TextOut(hDC,0,0,_T("维新培训"),strlen("维新培训"));
    EndPaint(hwnd,&ps);
    break;
    case WM_CLOSE:
    if(IDYES==MessageBox(hwnd,_T("是否真的结束?"),_T("fb"),MB_YESNO))
    {
    DestroyWindow(hwnd);
    }
    break;
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:
    return DefWindowProc(hwnd,uMsg,wParam,lParam);
    }
    return 0;}
    1>------ 已启动生成: 项目: test, 配置: Debug Win32 ------
    1>正在编译...
    1>test1.cpp
    1>c:\users\asus\documents\visual studio 2008\projects\test\test\test1.cpp(50) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
    1>        c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(366) : 参见“sprintf”的声明
    1>c:\users\asus\documents\visual studio 2008\projects\test\test\test1.cpp(51) : error C2664: “MessageBoxW”: 不能将参数 2 从“char [20]”转换为“LPCWSTR”
    1>        与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
    1>生成日志保存在“file://c:\Users\asus\Documents\Visual Studio 2008\Projects\test\test\Debug\BuildLog.htm”
    1>test - 1 个错误,1 个警告
    ========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
      

  9.   

    #include <Windows.h> 
    #include <stdio.h> 
    #include <tchar.h>LRESULT CALLBACK WinSunProc( 
    HWND hwnd,      // handle to window 
    UINT uMsg,      // message identifier 
    WPARAM wParam,  // first message parameter 
    LPARAM lParam  // second message parameter 
    ); int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow ) 

    WNDCLASS abc; 
    abc.cbClsExtra=0; 
    abc.cbWndExtra=0; 
    abc.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH); 
    abc.hCursor=LoadCursor(NULL,IDC_CROSS); 
    abc.hIcon=LoadIcon(NULL,IDI_ERROR); 
    abc.hInstance=hInstance; 
    abc.lpfnWndProc=WinSunProc; 
    abc.lpszClassName=TEXT("fb2009"); 
    abc.lpszMenuName=NULL; 
    abc.style=CS_HREDRAW|CS_VREDRAW; 
    RegisterClass(&abc); 
    HWND hwnd; 
    hwnd=CreateWindow(TEXT("fb2009"),TEXT("fb2009"),WS_OVERLAPPEDWINDOW,0,0,200,100,NULL,NULL,hInstance,NULL); 
    ShowWindow(hwnd,SW_SHOWNORMAL); 
    UpdateWindow(hwnd); 
    MSG msg; 
    while (GetMessage(&msg,NULL,0,0)) 

    TranslateMessage(&msg); 
    DispatchMessage(&msg); 

    return 0; 

    LRESULT CALLBACK WinSunProc( 
    HWND hwnd,      // handle to window 
    UINT uMsg,      // message identifier 
    WPARAM wParam,  // first message parameter 
    LPARAM lParam  // second message parameter 

    {  switch(uMsg) 

    case WM_CHAR: 
    char szChar[20]; 
    sprintf_s(szChar,"char is %d",wParam); 
    MessageBox(hwnd,L"szChar",TEXT("fb"),0); 
    break; 
    case WM_LBUTTONDOWN: 
    MessageBox(hwnd,L"mouse clicked",TEXT("fb"),0); 
    HDC hdc; 
    hdc=GetDC(hwnd); 
    TextOut(hdc,0,50,L"计算机编程语言培训",strlen("计算机编程语言培训")); 
    ReleaseDC(hwnd,hdc); 
    break; 
    case WM_PAINT: 
    HDC hDC; 
    PAINTSTRUCT ps; 
    hDC=BeginPaint(hwnd,&ps); 
    TextOut(hDC,0,0,L"维新培训",strlen("维新培训")); 
    EndPaint(hwnd,&ps); 
    break; 
    case WM_CLOSE: 
    if(IDYES==MessageBox(hwnd,L"是否真的结束?",L"fb",MB_YESNO)) 

    DestroyWindow(hwnd); 

    break; 
    case WM_DESTROY: 
    PostQuitMessage(0); 
    break; 
    default: 
    return DefWindowProc(hwnd,uMsg,wParam,lParam); 

    return 0; } 
      

  10.   

    改成TEXT(""),好像无需包含TCHAR.h头文件也能运行
      

  11.   

    UNICODE问题,项目菜单->最后的属性->配置属性->常规->项目默认值->unicode改为未设置
      

  12.   

    UNICODE问题,项目菜单->最后的属性->配置属性->常规->项目默认值->unicode中的字符值改为未设置
      

  13.   

    这个问题,可以这样解决(VS 2008中),项目->属性—>配置属性->C/C++->预处理器—>预处理器定义->单击浏览按钮,去掉从父级和项目设置继承
      

  14.   

    程序会自动关闭!!!!
    程序“[7176] L1.exe: 本机”已退出,返回值为 0 (0x0)。是什么问题