一个vc6的windows入门程序怎么修改至vs2010下运行
一个vc6的windows入门程序如何修改至vs2010上运行
程序如下:
#include <windows>
#include <stdio>
using namespace std;
LRESULT CALLBACK WProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
WNDCLASS wnda;
wnda.cbClsExtra=0;
wnda.cbWndExtra=0;
wnda.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);
wnda.hCursor=LoadCursor(hInstance,IDC_IBEAM);
wnda.hIcon=LoadIcon(hInstance,IDI_WINLOGO);
wnda.hInstance=hInstance;
wnda.lpfnWndProc=WProc;
wnda.lpszClassName="wei";
wnda.lpszMenuName=NULL;
wnda.style=CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
RegisterClass(&wnda);
HWND hwnd;
hwnd=CreateWindow("wei","windows入门",WS_OVERLAPPEDWINDOW,100,100,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 WProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_PAINT:
HDC hdc;
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,0,0,"人生得意须尽欢",strlen("莫使金枪空对穴"));
EndPaint(hwnd,&ps);
break;
case WM_CHAR:
char str[15];
sprintf(str,"char is %d",wParam);
MessageBox(hwnd,str,"字符ASCⅡ码为",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse click",NULL,MB_OK);
HDC dc;
dc=GetDC(hwnd);
TextOut(dc,0,50,"卖菊花",strlen("买菊花"));
ReleaseDC(hwnd,dc);
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;
}
以上能在vc6上运行,但在vs2010上报错了,如何修改?
------解决方案--------------------
试一下
#include <windows.h>
#include <stdio.h>
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"WinMainCRTStartup\"" )
LRESULT CALLBACK WProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
WNDCLASS wnda;
wnda.cbClsExtra=0;
wnda.cbWndExtra=0;
wnda.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);
wnda.hCursor=LoadCursor(hInstance,IDC_IBEAM);
wnda.hIcon=LoadIcon(hInstance,IDI_WINLOGO);
wnda.hInstance=hInstance;
wnda.lpfnWndProc=WProc;
wnda.lpszClassName="wei";
wnda.lpszMenuName=NULL;
wnda.style=CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
RegisterClass(&wnda);
HWND hwnd;
hwnd=CreateWindow("wei","windows入门",WS_OVERLAPPEDWINDOW,100,100,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
程序如下:
#include <windows>
#include <stdio>
using namespace std;
LRESULT CALLBACK WProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
WNDCLASS wnda;
wnda.cbClsExtra=0;
wnda.cbWndExtra=0;
wnda.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);
wnda.hCursor=LoadCursor(hInstance,IDC_IBEAM);
wnda.hIcon=LoadIcon(hInstance,IDI_WINLOGO);
wnda.hInstance=hInstance;
wnda.lpfnWndProc=WProc;
wnda.lpszClassName="wei";
wnda.lpszMenuName=NULL;
wnda.style=CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
RegisterClass(&wnda);
HWND hwnd;
hwnd=CreateWindow("wei","windows入门",WS_OVERLAPPEDWINDOW,100,100,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 WProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_PAINT:
HDC hdc;
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,0,0,"人生得意须尽欢",strlen("莫使金枪空对穴"));
EndPaint(hwnd,&ps);
break;
case WM_CHAR:
char str[15];
sprintf(str,"char is %d",wParam);
MessageBox(hwnd,str,"字符ASCⅡ码为",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse click",NULL,MB_OK);
HDC dc;
dc=GetDC(hwnd);
TextOut(dc,0,50,"卖菊花",strlen("买菊花"));
ReleaseDC(hwnd,dc);
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;
}
以上能在vc6上运行,但在vs2010上报错了,如何修改?
------解决方案--------------------
试一下
#include <windows.h>
#include <stdio.h>
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"WinMainCRTStartup\"" )
LRESULT CALLBACK WProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
WNDCLASS wnda;
wnda.cbClsExtra=0;
wnda.cbWndExtra=0;
wnda.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);
wnda.hCursor=LoadCursor(hInstance,IDC_IBEAM);
wnda.hIcon=LoadIcon(hInstance,IDI_WINLOGO);
wnda.hInstance=hInstance;
wnda.lpfnWndProc=WProc;
wnda.lpszClassName="wei";
wnda.lpszMenuName=NULL;
wnda.style=CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
RegisterClass(&wnda);
HWND hwnd;
hwnd=CreateWindow("wei","windows入门",WS_OVERLAPPEDWINDOW,100,100,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);