zoukankan      html  css  js  c++  java
  • 学习windows编程 day4 之 矩形的操作

    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        HDC hdc;
        PAINTSTRUCT ps;
        static RECT rect,rect2,rect3;
        static cxClient, cyClient;
        static HBRUSH hBrush, hOldBrush;
        POINT pt;
    
        switch (message)
        {
        case WM_SIZE:
            cxClient = LOWORD(lParam);
            cyClient = HIWORD(lParam);
            break;
        case WM_LBUTTONDOWN:
            pt.x = LOWORD(lParam);
            pt.y = HIWORD(lParam);
            if (PtInRect(&rect2,pt))
            {
                MessageBox(NULL, L"clicked", L"info", NULL);
            }
    
            break;
        case WM_PAINT:
            hdc = BeginPaint(hwnd, &ps);
    //处理矩形
    //         rect.left = cxClient / 2 - 50;
    //         rect.right = cxClient / 2 + 50;
    //         rect.top = cyClient / 2 - 50;
    //         rect.bottom = cyClient / 2 + 50;
    
            hBrush = CreateSolidBrush(RGB(255,0,0));
    //1.fillrect    填充矩形
            //FillRect(hdc, &rect, hBrush);
    //2.framerect    改画笔为画刷来绘制边框
            //FrameRect(hdc, &rect, hBrush);
    //3.invertrect    翻转矩形内所有的像素
            //InvertRect(hdc, &rect);
    
    //4.生成矩形SetRect
            SetRect(&rect, cxClient / 2 - 50, cyClient / 2 - 50, cxClient/2 + 50, cyClient/2 + 50);
    //5.偏移矩形OffsetRect
            OffsetRect(&rect, -150, -150);
            FillRect(hdc, &rect, hBrush);
            InvertRect(hdc, &rect);    //先显示图像,后翻转
    //6.增大减小,长宽同时InflateRect
            SetRect(&rect, cxClient / 2 - 50, cyClient / 2 - 50, cxClient / 2 + 50, cyClient / 2 + 50);
            InflateRect(&rect, 50, 30);
            FillRect(hdc, &rect, hBrush);
    //7.setrectEmpty    设置矩形为空
            FillRect(hdc, &rect, hBrush);    //不会显示
    //8.copyrect    多用在映射中
            CopyRect(&rect2, &rect);    //将rect的坐标拷贝给rect2
            SetRectEmpty(&rect);//将矩形的各个坐标设为0,则会显示rect2
            hBrush = CreateSolidBrush(RGB(255, 255, 0));
            FillRect(hdc, &rect2, hBrush);
    //9.intersectrect    两个矩形交集
    //10.unionrect        两个矩形并集
    //11.Isrectempty    判断是否为空
    //12.ptinrect        判断点是否在矩形中(重要)
    
    
            EndPaint(hwnd, &ps);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
        }
    
    
        return DefWindowProc(hwnd, message, wParam, lParam);
    }
  • 相关阅读:
    P2161 [SHOI2009]会场预约
    struts jar包
    struts
    HTML 简述
    JSP入门 分页
    JSP入门 生命周期
    JSP入门 el表达式
    JSP入门 导出文件
    JSP入门 文件上传
    自动增量字段重新从1开始的方法
  • 原文地址:https://www.cnblogs.com/ssyfj/p/8511978.html
Copyright © 2011-2022 走看看