#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 个 ==========
请高手指教一下什么原因,,,如何解决
#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 个 ==========
请高手指教一下什么原因,,,如何解决
解决方案 »
- WINDOWS.H already included. MFC apps must not #include <windows.h>
- 标题栏自绘error//
- mfc 界面问控件位置问题
- 我糊涂了,帮我看看(简单)
- 关于窗口类的文本名wndclass.lpszClassName的疑问
- 初学VC,对话框里的ListBox控件的数据为什么不能传递给视图?
- 关于CScrollView
- 用UDP协议来传递数据,在vc中怎么实现呀?
- 如何得到ListView的标题栏数目并全部删除?
- 哪里有《ATL开发指南》的电子版?
- VS2010的.NET Framework4.0转换成.NET Framework2.0.并且2008可以用
- WriteProcessMemory内存不能写入
例如,abc.lpszClassName="fb2009"; 应该改为abc.lpszClassName=_T("fb2009");改成这样,还需要包含TCHAR.h头文件。
最基本的类型转换。
UNICODE的代码。
在所有的常量字符前都加上 _T()或L例
TextOut(hDC,0,0,_T("维新培训"),strlen("维新培训"));
另外strlen必须使用_tcslen
看看有没有 UNICODE/_UNICODE, 有的话就去掉, 再看看程序中有没有 define 这些东西.
#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 个 ==========
#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; }
程序“[7176] L1.exe: 本机”已退出,返回值为 0 (0x0)。是什么问题