vc2005使用api编写基本的窗口错误
#include<windows.h>#include<stdio.h>LRESULTCALLBACKWinSunproc(HWNDhwnd,UINTuMsg,WPARA...
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinSunproc
(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int WINAPI WinMain
(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd
)
{
WNDCLASS wndclass;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor (NULL,IDC_CROSS);
wndclass.hIcon=LoadIcon (NULL,IDI_ERROR);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WinSunproc;
wndclass.lpszClassName="LiJingYi";
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW | CS_VREDRAW ;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
RegisterClass(&wndclass);
HWND hwnd;
hwnd=CreateWindow("LiJingYi","李敬医",WS_OVERLAPPEDWINDOW ,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWDEFAULT);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinSunproc
(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
HDC hdc;
PAINTSTRUCT ps;
switch (uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf (szChar,"char is %d" ,wParam);
MessageBox(hwnd,szChar,"LiJingYi",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","LiJingYi",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut (hdc,0 ,59,"hello world!",strlen("hello world!"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
TextOut (hdc,0,0,"李敬医",strlen("李敬医"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"你真的要走吗?","LiJingYi",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default :
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
1>g:\c++教程\winmian\winmian\winmain.cpp(26) : error C2440: “=”: 无法从“const char [9]”转换为“LPCWSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>g:\c++教程\winmian\winmian\winmain.cpp(34) : error C2664: “CreateWindowExW”: 不能将参数 2 从“const char [9]”转换为“LPCWSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>g:\c++教程\winmian\winmian\winmain.cpp(64) : error C2664: “MessageBoxW”: 不能将参数 2 从“char [20]”转换为“LPCWSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>g:\c++教程\winmian\winmian\winmain.cpp(67) : error C2664: “MessageBoxW”: 不能将参数 2 从“const char [14]”转换为“LPCWSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
与指向的类型无关;转换要求 reinterpret_cast、C 样式转换
错误信息类似都是无法转换。。什么原因啊。C++ 6.0就可以过,是不是2005在什么规则上做了更改? 展开
#include <stdio.h>
LRESULT CALLBACK WinSunproc
(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int WINAPI WinMain
(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd
)
{
WNDCLASS wndclass;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor (NULL,IDC_CROSS);
wndclass.hIcon=LoadIcon (NULL,IDI_ERROR);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WinSunproc;
wndclass.lpszClassName="LiJingYi";
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW | CS_VREDRAW ;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
RegisterClass(&wndclass);
HWND hwnd;
hwnd=CreateWindow("LiJingYi","李敬医",WS_OVERLAPPEDWINDOW ,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWDEFAULT);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinSunproc
(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
HDC hdc;
PAINTSTRUCT ps;
switch (uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf (szChar,"char is %d" ,wParam);
MessageBox(hwnd,szChar,"LiJingYi",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","LiJingYi",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut (hdc,0 ,59,"hello world!",strlen("hello world!"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
TextOut (hdc,0,0,"李敬医",strlen("李敬医"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"你真的要走吗?","LiJingYi",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default :
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
1>g:\c++教程\winmian\winmian\winmain.cpp(26) : error C2440: “=”: 无法从“const char [9]”转换为“LPCWSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>g:\c++教程\winmian\winmian\winmain.cpp(34) : error C2664: “CreateWindowExW”: 不能将参数 2 从“const char [9]”转换为“LPCWSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>g:\c++教程\winmian\winmian\winmain.cpp(64) : error C2664: “MessageBoxW”: 不能将参数 2 从“char [20]”转换为“LPCWSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>g:\c++教程\winmian\winmian\winmain.cpp(67) : error C2664: “MessageBoxW”: 不能将参数 2 从“const char [14]”转换为“LPCWSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
与指向的类型无关;转换要求 reinterpret_cast、C 样式转换
错误信息类似都是无法转换。。什么原因啊。C++ 6.0就可以过,是不是2005在什么规则上做了更改? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询