#include <windows.h>
#include <stdio.h>
/**********************************************
* 窗口过程函数的声明
* WinSunProc 是函数名 可以随便起 但要有意义
**********************************************/
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lparam
);
/***********************************************
WinMain 函数 主函数、入口函数
LP long point 长指针
窗口的创建过程:
1.设计一个窗口类
2.注册窗口类
3.创建窗口
4.显示及更新窗口
***********************************************/
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra =
0;
wndcls.cbWndExtra =
0;
wndcls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndcls.hCursor = LoadCursor(NULL , IDC_CROSS);
wndcls.hIcon = LoadIcon(NULL , IDI_ERROR);
wndcls.hInstance = hInstance;
wndcls.lpfnWndProc = WinSunProc;
wndcls.lpszClassName =
"xiaobei2017";
wndcls.lpszMenuName = NULL;
wndcls.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd = CreateWindow(
"xiaobei2017",
"翼佳奕",
WS_OVERLAPPEDWINDOW,
200,
200,
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 msg.wParam;
}
/**********************************************
* 窗口过程函数
* WinSunProc 是函数名 可以随便起 但要有意义
**********************************************/
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lparam
)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[
20];
sprintf(szChar,
"输入的字符是%d",wParam);
MessageBox(hwnd,szChar,
"char",
0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,
"mouse clicked",
"message",
0);
HDC hdc;
hdc = GetDC(hwnd);
TextOut(hdc,
0,
30,
"科技大学",strlen(
"科技大学"));
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,
"是否真的结束?",
"message",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(
0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lparam);
}
return 0;
}