/* -------------------------------------------------------------------
MyWindows.c -- 基本窗口模型
《Windows 程序设计(SDK)》视频教程
--------------------------------------------------------------------*/
#include <windows.h>
void XY(HDC, int, int);
void RXY(HDC, int, int);
void LXY(HDC, int, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT("MyWindows");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if (!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("这个程序需要在 Windows NT 才能执行!"), szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(szAppName,
TEXT("鱼C工作室"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
static int cxChar, cyChar;
int i, j;
switch (message)
{
case WM_SIZE:
cxChar = LOWORD(lParam);
cyChar = HIWORD(lParam);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
MoveToEx(hdc, cxChar / 2 + 25, 50, NULL);
LineTo(hdc, cxChar / 2 + 25, 400);
//右竖线
for (i = 0;i < 5;i++)
{
MoveToEx(hdc, cxChar / 2 + 25 + 50 * i, 50, NULL);
LineTo(hdc, cxChar / 2 + 25 + 50 * i, 450);
}
MoveToEx(hdc, cxChar / 2 - 25, 50, NULL);
LineTo(hdc, cxChar / 2 - 25, 450);
//左竖线
for (i = 4;i > 0;i--)
{
MoveToEx(hdc, cxChar / 2 - 25 - (50 * i), 50, NULL);
LineTo(hdc, cxChar / 2 - 25 - (50 * i), 450);
}
MoveToEx(hdc, cxChar / 2 - 25 - 50 * 4, 50, NULL);
LineTo(hdc, cxChar / 2 + 25 + 50 * 4, 50);
//左横线
for (i = 2; i < 9; i++)
{
MoveToEx(hdc, cxChar / 2 - 25 - 50 * 4, 50 * i, NULL);
LineTo(hdc, cxChar / 2 - 25, 50 * i);
}
//右横线
for (i = 2; i < 9; i++)
{
MoveToEx(hdc, cxChar / 2 + 25 + 50 * 4, 50 * i, NULL);
LineTo(hdc, cxChar / 2 + 25, 50 * i);
}
MoveToEx(hdc, cxChar / 2 - 25 - 50 * 4, 450, NULL);
LineTo(hdc, cxChar / 2 + 25 + 50 * 4, 450);
MoveToEx(hdc, cxChar / 2 - 25 - 50 * 4, 200, NULL);
LineTo(hdc, cxChar / 2 - 25 - 50 * 2, 300);
MoveToEx(hdc, cxChar / 2 - 25 - 50 * 4, 300, NULL);
LineTo(hdc, cxChar / 2 - 25 - 50 * 2, 200);
MoveToEx(hdc, cxChar / 2 + 25 + 50 * 4, 200, NULL);
LineTo(hdc, cxChar / 2 + 25 + 50 * 2, 300);
MoveToEx(hdc, cxChar / 2 + 25 + 50 * 4, 300, NULL);
LineTo(hdc, cxChar / 2 + 25 + 50 * 2, 200);
XY(hdc, cxChar / 2 - 25 - 50 * 2, 100);
XY(hdc, cxChar / 2 + 25 + 50 * 2, 100);
XY(hdc, cxChar / 2 - 25 - 50 * 2, 400);
XY(hdc, cxChar / 2 + 25 + 50 * 2, 400);
for (j = 0;j < 3;j++)
{
XY(hdc, cxChar / 2 - 25 - 50, 200 + (100 * j)-50);
XY(hdc, cxChar / 2 + 25 + 50, 200 + (100 * j)-50);
}
RXY(hdc, cxChar / 2 + 25 + 50, 50);
RXY(hdc, cxChar / 2 - 25 - 50, 50);
LXY(hdc, cxChar / 2 + 25 + 50, 450);
LXY(hdc, cxChar / 2 -25 - 50, 450);
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
void XY(HDC hdc,int lx, int ly)
{
MoveToEx(hdc, lx - 16, ly+6, NULL);
LineTo(hdc, lx - 6, ly+6);
LineTo(hdc, lx - 6, ly+16);
MoveToEx(hdc, lx - 16, ly-6, NULL);
LineTo(hdc, lx - 6, ly-6);
LineTo(hdc, lx - 6, ly-16);
MoveToEx(hdc, lx + 16, ly+6, NULL);
LineTo(hdc, lx + 6, ly+6);
LineTo(hdc, lx + 6, ly+16);
MoveToEx(hdc,lx + 16, ly-6, NULL);
LineTo(hdc, lx + 6, ly-6);
LineTo(hdc, lx + 6, ly-16);
}
void RXY(HDC hdc, int lrx, int lry)
{
MoveToEx(hdc, lrx - 16, lry + 6, NULL);
LineTo(hdc, lrx - 6, lry + 6);
LineTo(hdc, lrx - 6, lry + 16);
MoveToEx(hdc, lrx + 16, lry + 6, NULL);
LineTo(hdc, lrx + 6, lry + 6);
LineTo(hdc, lrx + 6, lry + 16);
}
void LXY(HDC hdc, int lx, int ly)
{
MoveToEx(hdc, lx + 16, ly - 6, NULL);
LineTo(hdc, lx + 6, ly - 6);
LineTo(hdc, lx + 6, ly - 16);
MoveToEx(hdc, lx - 16, ly - 6, NULL);
LineTo(hdc, lx - 6, ly - 6);
LineTo(hdc, lx - 6, ly - 16);
}