学孙老师例子发生的问题
各位大哥,这是我照着孙鑫老师的视频教程上写下来的程序:
#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 szCmdLine,
int iCmdShow
)
{
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_ERROR);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WinSunProc;
wndclass.lpszClassName="Weixin2003";
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
RegisterClass(&wndclass);
HWND hwnd;
hwnd=CreateWindow("Weixin2003","北京维新技术培训中心",WS_OVERLAPPEDWINDOW,0,0,600,400,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 WindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
case WM_CHAR:
char zcxchar[20];
sprintf(zcxchar,"输入的是%d",wParam);
MessageBox(hwnd,zcxchar,"Weixin",0);//??????????????????????????????
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse click","Weixin",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_DESTROY:
PostQuitMessage(0);
break;
case WM_CLOSE:
{
if(IDYES==MessageBox(hwnd,"zhen de jieshu ?","Weixin",MB_YESNO))
DestroyWindow(hwnd);
}
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
我有几个问题想问:
1。
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR szCmdLine,
int iCmdShow
)我看见孙老师在MSDN上面查到的函数是这样的,但是为什么在我的MSDN上面查到的就没有这个函数呢???我的意思是说我能查到两个函数
一个是:
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR szCmdLine,
int iCmdShow
)这个和上面的区别在于LPWSTR szCmdLine; 这个类型不符合我的要求
还有一个版本是:
intWinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR szCmdLine,
int iCmdShow
) 也不符合我的要求 因为缺少了 WINAPI 。我在想为什么会这样呢??既然他可以有直接拷贝的函数,为什么我的MSDN上就没有呢???
还有一个问题就是:
error C2440: “=”: 无法从“const char [11]”转换为“LPCWSTR”
error C2664: “CreateWindowExW”: 不能将参数 2 从“const char [11]”转换为“LPCWSTR”
error C2664: “CreateWindowExW”: 不能将参数 2 从“const char [11]”转换为“LPCWSTR”
。。。。。。都是这样饿错误!!!
这到底是怎么回事 啊 ??