下面的程序在VS2008不能通过,在VC6通过,怎么改能在VS2008通过?
#include<windows.h>#include<stdio.h>intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPre...
#include<windows.h>
#include<stdio.h>
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
LRESULT CALLBACK WndSunProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
WNDCLASS wndclass;
wndclass.style=CS_HREDRAW|CS_NOCLOSE;
wndclass.lpfnWndProc=WndSunProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_ERROR);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName="fanqie";
RegisterClass(&wndclass);
HWND hwnd;
hwnd=CreateWindow("fanqie","我的第一个窗口",WS_OVERLAPPEDWINDOW,50,50,300,200,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,hwnd,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WndSunProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char is %c",wParam);
MessageBox(hwnd,szChar,"字符",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"left button down","",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,20,"我的第一个窗口",strlen("我的第一个窗口"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,40,"窗口重画输出文字",strlen("窗口重画输出文字"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"确定退出?","?",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
} 展开
#include<stdio.h>
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
LRESULT CALLBACK WndSunProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
WNDCLASS wndclass;
wndclass.style=CS_HREDRAW|CS_NOCLOSE;
wndclass.lpfnWndProc=WndSunProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_ERROR);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName="fanqie";
RegisterClass(&wndclass);
HWND hwnd;
hwnd=CreateWindow("fanqie","我的第一个窗口",WS_OVERLAPPEDWINDOW,50,50,300,200,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,hwnd,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WndSunProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char is %c",wParam);
MessageBox(hwnd,szChar,"字符",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"left button down","",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,20,"我的第一个窗口",strlen("我的第一个窗口"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,40,"窗口重画输出文字",strlen("窗口重画输出文字"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"确定退出?","?",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
} 展开
3个回答
展开全部
两种方法:
1. 把所有char都改成TCHAR,然后所有字符串都用_T()包起来,还有涉及到字符串和字符的函数,比如strlen()要改成_tcslen(),sprintf要改成_stprintf等等。这个方法比较麻烦,但是如果在实际项目开发中,为了保持字符集之间的兼容性,一般都用这种方式
2. 在VS2008 IDE中,项目-属性-配置属性-常规,把字符集从“使用Unicode字符集”改成“使用多字节字符集”,这种方式方便,但是无法支持Unicode,如果只是自己学习编程的话可以这么做
1. 把所有char都改成TCHAR,然后所有字符串都用_T()包起来,还有涉及到字符串和字符的函数,比如strlen()要改成_tcslen(),sprintf要改成_stprintf等等。这个方法比较麻烦,但是如果在实际项目开发中,为了保持字符集之间的兼容性,一般都用这种方式
2. 在VS2008 IDE中,项目-属性-配置属性-常规,把字符集从“使用Unicode字符集”改成“使用多字节字符集”,这种方式方便,但是无法支持Unicode,如果只是自己学习编程的话可以这么做
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询