第一个window 程序,用vc2005写的,错误全是类型转换.自己不知道要怎么改.
#include<windows.h>
#include<stdio.h>
LRESULT CallWindowProc( WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam );
int WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground =(HBRUSH)COLOR_ACTIVEBORDER;
wndclass.hCursor =LoadCursor(NULL,IDC_CROSS);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc =CallWindowProc;
wndclass.lpszClassName ="Myapplication";
wndclass.lpszMenuName =NULL;
wndclass.style =CS_HREDRAW |CS_VREDRAW;
RegisterClass(&wndclass);
HWND hwnd;
hwnd=CreatWindow("Myapplication","第一个window程序",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;//这里只是随便写上 return 0.
// MSDN 上写正常结束返回带wParam parameter的值,不知道要怎么写?
}
LRESULT CallWindowProc( WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam )
{
switch(Msg)
{
case WM_PAINT :
HDC hdc;
PAINTSTRUCT ps;
hdc=BeginPaint(hWnd,&ps);
EndPaint(hWnd,&ps);
break;
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char is %d",wParam);
MessageBox(hWnd,szChar,"Myapplication",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hWnd,"mouse click","Myapplication",MB_OK);
HDC hDC;
hDC=GetDC(hWnd);
TextOut(hDC,0,50,"VC2005.net",strlen("VC2005.net"));
ReleaseDC(hWnd,hDC);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hWnd,"你是否要退出程序?","Myapplication",MB_YESNO))
{
DestroyWindow(hWnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,Msg,wParam,lParam);
}
return 0;
}
/* winmain return
If the function succeeds, terminating when it receives a WM_QUIT message, it should return the exit value contained in that message's wParam parameter. If the function terminates before entering the message loop, it should return zero.
*/