#include <windows.h>
#include <strsafe.h>
#include <math.h>
#define NUM 1000
#define PI 3.14
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstcance, PSTR lpCmdLine, int iCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
//窗口类名
WCHAR szClassName[] = TEXT("FristWindow");
//初始化窗口类
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hInstance = hInstance;
wndclass.lpszClassName = szClassName;
wndclass.lpszMenuName = NULL;
//注册窗口类
if (!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("本程序只能在 WINDOWS NT 框架上运行!!!"), TEXT("提示信息:"), MB_OK | MB_ICONERROR);
return 0;
}
//创建窗口
hwnd = CreateWindow(szClassName, TEXT("FristWindow"), 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 msg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
WCHAR szBuffer[128];
static int xClient, yClient;
static POINT apt[4];
switch (msg)
{
case WM_SIZE:
xClient = LOWORD(lParam);
yClient = HIWORD(lParam);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect);
SetPixelV(hdc,xClient/2,yClient/2, RGB(255,0,0));
if (yClient < xClient)
{
//SelectObject(hdc, GetStockObject(BLACK_BRUSH));
Ellipse(hdc, xClient/2-yClient/2, 0, xClient/2+yClient/2, yClient);
apt[0].x = xClient / 2;
apt[0].y = 0;
apt[2].x = xClient/2-yClient/2;
apt[2].y = yClient / 2;
apt[1].x = xClient / 2 + yClient / 2;
apt[1].y = yClient / 2;
apt[3].x = xClient / 2;
apt[3].y = yClient;
//SelectObject(hdc, GetStockObject(WHITE_BRUSH));
PolyBezier(hdc, apt, 4);
SelectObject(hdc, GetStockObject(WHITE_BRUSH));
Ellipse(hdc,xClient/2-20,yClient/4-20 ,xClient/2+20,yClient/4+20);
SelectObject(hdc, GetStockObject(BLACK_BRUSH));
Ellipse(hdc, xClient / 2 - 20, 3*yClient / 4 - 20, xClient / 2 + 20, 3*yClient / 4 + 20);
}
//结束绘画
/* MoveToEx(hdc, 0, yClient / 2, 0);
LineTo(hdc, xClient, yClient / 2);
MoveToEx(hdc, xClient / 2, 0, 0);
LineTo(hdc, xClient / 2, yClient);*/
EndPaint(hwnd, &ps);
break;
case WM_CLOSE:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}