1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <windows.h>
#include <stdio.h>
//声明回调函数
LRESULT CALLBACK WinSunProc(HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int _WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wndcls;
//设计窗口类
wndcls.cbClsExtra = 0;
wndcls.cbWndExtra = 0;
wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor = LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon = LoadIcon(NULL, IDI_ERROR);
wndcls.hInstance = hInstance;
wndcls.lpfnWndProc = WinSunProc;
wndcls.lpszClassName = "2009";
wndcls.lpszMenuName = NULL;
wndcls.style = CS_HREDRAW | CS_VREDRAW;
//注册窗口类
RegisterClass(&wndcls);
//创建窗口
HWND hwnd;
hwnd = CreateWindow("2009","中国北京",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 WinSunProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
char szChar[20];
HDC hdc;
PAINTSTRUCT ps;
switch(uMsg)
{
case WM_CHAR:
//char szChar[20];
sprintf(szChar,"Char is %d", wParam);
MessageBox(hwnd,szChar,"中国北京",MB_OK);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"Mouse Click","中国北京",MB_OK);
//HDC hdc;
hdc = GetDC(hwnd);
TextOut(hdc,0,50,"Win32应用程序",strlen("Win32应用程序"));
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_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;
}
|