#include <windows.h>
#include <stdio.h>
#include <tchar.h>
LRESULT CALLBACK winsunproc( HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
WNDCLASS cls;
cls.cbClsExtra=0;
cls.cbClsExtra=0;
cls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
cls.hCursor=LoadCursor(NULL,IDC_CROSS);
cls.hIcon=LoadIcon(NULL,IDI_ERROR);
cls.hInstance=hInstance;
cls.lpfnWndProc=(WNDPROC)winsunproc;
cls.lpszClassName=_T("zhy");
cls.lpszMenuName=NULL;
cls.style=CS_HREDRAW|CS_VREDRAW;
RegisterClass(&cls);
HWND hwnd;
hwnd=CreateWindow(_T("zhy"),_T("zhy0408"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT ,CW_USEDEFAULT ,CW_USEDEFAULT ,CW_USEDEFAULT ,NULL,NULL,hInstance,NULL);
int t=GetLastError();
ShowWindow(hwnd,SW_MAXIMIZE);
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
)
{
switch(uMsg)
{
case WM_CHAR:
char a[20];
sprintf_s(a,"char is %d",wParam);
MessageBox(hwnd,(LPCTSTR)a,(LPCTSTR)("zhy0408"),0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,(LPCTSTR)"mouse is click",(LPCTSTR)"zhy0408",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,(LPCTSTR)"zhy",3);
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDc;
PAINTSTRUCT ps;
hDc=BeginPaint(hwnd,&ps);
TextOut(hDc,0,0,_T("zhy0408"),7);
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,_T("close?"),(LPCTSTR)"zhy0408",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!