• 学习windows编程 day4 之 多边矩形填充


    #include <windows.h>
    #include <math.h>
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
    
    #define R 200
    #define PI 3.1415926
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
        //声明全局数据:类名
        static TCHAR szClassName[] = TEXT("MyWindows");
        HWND hwnd;
        MSG msg;
    
        //注册窗口类
        WNDCLASS wndclass;
    
        wndclass.hInstance = hInstance;
        wndclass.lpszClassName = szClassName;
        wndclass.cbClsExtra = 0;
        wndclass.cbWndExtra = 0;
        wndclass.lpfnWndProc = WndProc;
        wndclass.lpszMenuName = NULL;
        wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
        wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
        wndclass.style = CS_HREDRAW;
    
        if (!RegisterClass(&wndclass))
        {
            MessageBox(NULL, TEXT("this program must run in Windows NT!"), szClassName, MB_ICONERROR);
            return 0;
        }
    
        hwnd = CreateWindow(
            szClassName,
            TEXT("MyFirstPractice"),
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            NULL,
            NULL,
            hInstance,
            NULL
            );
    
        ShowWindow(hwnd, nShowCmd);
        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;
        RECT rect;
    
        static HBRUSH hBrush, hOldBrush;
    //    绘制一个多边形,可填充是需要顶点的个数polygon
        POINT apt1[4] = { 100, 200, 200, 100, 300, 200,200, 300 };
    //    绘制一个封闭多边形polyline需要顶点数+1    注意:用线绘制的封闭图像不具有填充能力
    //    POINT apt2[5] = { 400, 200, 500, 100, 600, 200, 500, 300, 400, 200 };
        POINT apt2[5];
        int cxClient, cyClient;    //星星的中心位置
    
        switch (message)
        {
        case WM_PAINT:
            hdc = BeginPaint(hwnd, &ps);
            GetClientRect(hwnd, &rect);
    
            cxClient = rect.right / 2;
            cyClient = rect.bottom / 2;
    
            //获取五个顶点
            //左上顶点
            apt2[0].x = cxClient - (int)(R*cos(PI / 5));
            apt2[0].y = cyClient - (int)(R*sin(PI / 5));
    
            //右上顶点
            apt2[1].x = cxClient + (int)(R*cos(PI / 5));
            apt2[1].y = cyClient - (int)(R*sin(PI / 5));
    
            //左下顶点
            apt2[2].x = cxClient - (int)(R*cos(PI / 5));
            apt2[2].y = cyClient + (int)(R*sin(PI / 5));
    
            //上顶点
            apt2[3].x = cxClient;
            apt2[3].y = cyClient - R;
    
            //右下顶点
            apt2[4].x = cxClient + (int)(R*cos(PI / 5));
            apt2[4].y = cyClient + (int)(R*sin(PI / 5));
    
             hBrush = CreateSolidBrush(RGB(255,255,0));
             hOldBrush = SelectObject(hdc, hBrush);
    
    //        SetPolyFillMode(hdc, ALTERNATE);    //交替填充
            SetPolyFillMode(hdc, WINDING);    //螺旋填充,填充所有能够一笔完成的图形
    // 
             Polygon(hdc, apt2, 5);
    //         Polyline(hdc, apt2, 5);
    // 
             SelectObject(hdc, hOldBrush);
             DeleteObject(hOldBrush);
            EndPaint(hwnd, &ps);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
        }
    
    
        return DefWindowProc(hwnd, message, wParam, lParam);
    }

    #include <windows.h>#include <math.h>
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
    #define R 200#define PI 3.1415926
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){//声明全局数据:类名static TCHAR szClassName[] = TEXT("MyWindows");HWND hwnd;MSG msg;
    //注册窗口类WNDCLASS wndclass;
    wndclass.hInstance = hInstance;wndclass.lpszClassName = szClassName;wndclass.cbClsExtra = 0;wndclass.cbWndExtra = 0;wndclass.lpfnWndProc = WndProc;wndclass.lpszMenuName = NULL;wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);wndclass.style = CS_HREDRAW;
    if (!RegisterClass(&wndclass)){MessageBox(NULL, TEXT("this program must run in Windows NT!"), szClassName, MB_ICONERROR);return 0;}
    hwnd = CreateWindow(szClassName,TEXT("MyFirstPractice"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
    ShowWindow(hwnd, nShowCmd);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;RECT rect;
    static HBRUSH hBrush, hOldBrush;//绘制一个多边形,可填充是需要顶点的个数polygonPOINT apt1[4] = { 100, 200, 200, 100, 300, 200,200, 300 };//绘制一个封闭多边形polyline需要顶点数+1注意:用线绘制的封闭图像不具有填充能力//POINT apt2[5] = { 400, 200, 500, 100, 600, 200, 500, 300, 400, 200 };POINT apt2[5];int cxClient, cyClient;//星星的中心位置
    switch (message){case WM_PAINT:hdc = BeginPaint(hwnd, &ps);GetClientRect(hwnd, &rect);
    cxClient = rect.right / 2;cyClient = rect.bottom / 2;
    //获取五个顶点//左上顶点apt2[0].x = cxClient - (int)(R*cos(PI / 5));apt2[0].y = cyClient - (int)(R*sin(PI / 5));
    //右上顶点apt2[1].x = cxClient + (int)(R*cos(PI / 5));apt2[1].y = cyClient - (int)(R*sin(PI / 5));
    //左下顶点apt2[2].x = cxClient - (int)(R*cos(PI / 5));apt2[2].y = cyClient + (int)(R*sin(PI / 5));
    //上顶点apt2[3].x = cxClient;apt2[3].y = cyClient - R;
    //右下顶点apt2[4].x = cxClient + (int)(R*cos(PI / 5));apt2[4].y = cyClient + (int)(R*sin(PI / 5));
     hBrush = CreateSolidBrush(RGB(255,255,0)); hOldBrush = SelectObject(hdc, hBrush);
    //SetPolyFillMode(hdc, ALTERNATE);//交替填充SetPolyFillMode(hdc, WINDING);//螺旋填充,填充所有能够一笔完成的图形//  Polygon(hdc, apt2, 5);// Polyline(hdc, apt2, 5);//  SelectObject(hdc, hOldBrush); DeleteObject(hOldBrush);EndPaint(hwnd, &ps);break;case WM_DESTROY:PostQuitMessage(0);return 0;}

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

  • 相关阅读:
    网站并发量的计算方法
    Kubernetes-1.16部署之一 ETCD+K8s+Calico
    CentOS 7和Ubuntu 18.04安装Docker
    Tomcat8的kryo序列化方式session共享
    Tomcat启动慢问题解决
    Memcached集群配置
    sed命令使用方法
    python数据分析与算法之五 算法
    python数据分析与算法之四 二叉树和排序二叉树
    python数据分析与算法之三 顺序表和链表
  • 原文地址:https://www.cnblogs.com/ssyfj/p/8510681.html
Copyright © 2020-2023  润新知