五角星

作者: Pwnmelife | 来源:发表于2019-02-18 21:11 被阅读0次
#include <strsafe.h>
#include "SysMets.h"
#include <math.h>

#define NUM 1000
#define R 100
#define PI 3.14159
#define TWOPI (2 * 3.14159)
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);


int WINAPI WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nShowCmd) {
    static TCHAR szAppName[] = TEXT("Bill");
    HWND hwnd;
    WNDCLASS wndclass;
    MSG msg;
    
    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.lpszClassName = szAppName;
    wndclass.lpszMenuName = NULL;
    wndclass.lpfnWndProc = WndProc;
    wndclass.style = CS_HREDRAW | CS_VREDRAW;

    RegisterClass(&wndclass);
    hwnd = CreateWindow(TEXT("Bill"), TEXT("Tip"), WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
        CW_USEDEFAULT, 40, CW_USEDEFAULT, 100,
        NULL, NULL, hInstance, NULL);

    ShowWindow(hwnd, nShowCmd);
    UpdateWindow(hwnd);
    while (GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;

}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
    HDC hdc;
    PAINTSTRUCT ps;
    RECT rect;
    static int cxClient, cyClient;
    static TCHAR szBuffer[128];
    POINT apt1[5] = { 100, 100, 200, 100, 200, 200, 100, 200, 100, 100 };
    POINT apt2[4] = { 300, 100, 400, 100, 400, 200, 300, 200 };
    POINT star[5];
    POINT ptCenter;
    int i;
    HBRUSH hBrush;
    HGDIOBJ hOldBrush;
    switch (message) {
    case WM_PAINT:
        hdc = BeginPaint(hwnd, &ps);
        
        //设定五角星的中心点的位置
        GetClientRect(hwnd, &rect);
        ptCenter.x = (rect.right - rect.left) / 2;
        ptCenter.y = (rect.bottom - rect.top) / 2;

        //左上点
        star[0].x = ptCenter.x - (int)(R * sin(2 * PI / 5));
        star[0].y = ptCenter.y - (int)(R * cos(2 * PI / 5));

        //右上点
        star[1].x = ptCenter.x + (int)(R * sin(2 * PI / 5));;
        star[1].y = ptCenter.y - (int)(R * cos(2 * PI / 5));;

        //左下点
        star[2].x = ptCenter.x - (int)(R * sin(PI / 5));
        star[2].y = ptCenter.y + (int)(R * cos(PI / 5));
        
        //顶点
        star[3].x = ptCenter.x;
        star[3].y = ptCenter.y - R;

        //右下点
        star[4].x = ptCenter.x + (int)(R*sin(PI / 5));
        star[4].y = ptCenter.y + (int)(R*cos(PI / 5));

        hBrush = CreateSolidBrush(RGB(255,255,0));
        hOldBrush = SelectObject(hdc, hBrush);
        Polygon(hdc, star, 5);
        /*star[5] = star[0];

        MoveToEx(hdc, star[0].x, star[0].y, NULL);
        for (int i = 0; i < 6; i++) {
            LineTo(hdc, star[i].x, star[i].y);
        }
        */
        DeleteObject(SelectObject(hdc, hOldBrush));
        EndPaint(hwnd, &ps);
        return 0;

    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }

    return DefWindowProc(hwnd, message, wParam, lParam);
}

结果图

Result.png

相关文章

  • turtle库

    画五角星(一) 画五角星(二) 画五角星(三)

  • jQuery五角星评分(end方法)

    当鼠标移入空心五角星时,该五角星和其前面的五角星变成实心。鼠标离开时,所有五角星为空心。当鼠标点击某一空心五角星时...

  • Bezierpath绘制五角星(swift星级评分控件)

    效果 五角星各点的数学坐标出处: 根据该数学坐标转换成UIView内坐标,生成正五角星 用法 附注:/*假设五角星...

  • 小孩启示录

    指认五角星。 菜菜时常去指认裤子上的五角星。并且擅长在他看到的世界里指认其他相似的五角星。 在门口幼儿园广场的塑胶...

  • java的for循环小例:打印倒三角形

    说明: 1,实现:每一行实际由空格和五角星组合而成,只要打印完空格后接着打印五角星即可。 2,每一行的空格与五角星...

  • AI应用:绘制立体五角星

    先绘制出一个五角星 选择五角星,点击对象—>路径—>添加锚点,再复制出一层放在正下面 选择上层五角星每个顶点右边线...

  • 应青约:也来说说网名那点事儿

    继五角星大会欢乐开幕讨论“郑小七到底信不信郑”和五角星面面改名字后,接着五角星兔兔读面十七有感说了关于名字的故事,...

  • 9月21日

    今晚接姑娘时姑娘很开心的告诉我在托辅得了一个小五角星,还说以后要好好表现争取得更多的五角星,说得10个五角星会有奖...

  • 手工小国旗

    今天我做了一个小国旗。先用白纸卷成圆柱,再用纸剪成长方形,在做上五个五角星,先做一个大五角星,小五角星围...

  • 社团课

    今天我们社团折的是五角星。我们先剪五角星。先把五角星做成一个图形,然后写着意见把剪下的那一脚给展开,就是一个平整的...

网友评论

      本文标题:五角星

      本文链接:https://www.haomeiwen.com/subject/rxnzeqtx.html