zoukankan      html  css  js  c++  java
  • 《windows程序设计》哆啦A梦(10)

    代码如下:

    program Project2;
    
    {$APPTYPE CONSOLE}
    
    {$R *.res}
    
    uses
      System.SysUtils,
      windows,
      Winapi.Messages,
      Vcl.Dialogs;
    
    type
      Point = record
        x: Integer;
        y: Integer;
      end;
    
    var
      swndClass: tagWNDCLASS;
      message: MSG;
      mHwnd: hwnd;
      cxClient, cyClient: Integer;
    
    function WindowProc(hwnd: hwnd; uMsg: UINT; wParam: wParam; lParam: lParam): LRESULT; stdcall;
    var
      i: integer;
      uhdc: HDC;
      ps: PAINTSTRUCT;
      GrayPen: HPEN;
      hOldPen: HPEN;
      hTempPen: HPEN;
      hBlueBrush: HBRUSH;
      hRedBrush: HBRUSH;
      hOldBrush: HBRUSH;
      HyelloBrush: HBRUSH;
      apt: array[0..128] of Point;
    begin
      case uMsg of
        WM_CREATE:
          begin
    
          end;
        WM_SIZE:
          begin
            cxclient := loword(lParam);
            cyclient := HiWord(lParam);
            result := 0;
            Exit;
          end;
        wm_paint:
          begin
            uhdc := BeginPaint(hwnd, ps);
            //辅助线
            GrayPen := CreatePen(PS_DOT, 1, RGB(192, 192, 192));
            hOldPen := SelectObject(uhdc, GrayPen);
            MoveToEx(uhdc, cxClient div 2, 0, nil);
            LineTo(uhdc, cxClient div 2, cyClient);
            MoveToEx(uhdc, 0, cyClient div 2, nil);
            LineTo(uhdc, cxClient, cyClient div 2);
            SelectObject(uhdc, hOldPen);
    
            //头(直径240)
            hBlueBrush := CreateSolidBrush(RGB(0, 159, 232));
            hOldBrush := SelectObject(uhdc, hBlueBrush);
            Ellipse(uhdc, cxClient div 2 - 120, cyClient div 2 - 200, cxClient div 2 + 120, cyClient div 2 + 40);
            SelectObject(uhdc, hOldBrush);
    
            //脸(直径200)
            Ellipse(uhdc, cxClient div 2 - 100, cyClient div 2 - 160, cxClient div 2 + 100, cyClient div 2 + 40);
             
             //眼睛
            Ellipse(uhdc, cxClient div 2 - 50, cyClient div 2 - 180, cxClient div 2, cyClient div 2 - 120);
            Ellipse(uhdc, cxClient div 2 + 50, cyClient div 2 - 180, cxClient div 2, cyClient div 2 - 120);
    
            //眼珠
            hOldBrush := SelectObject(uhdc, GetStockObject(BLACK_BRUSH));
            Ellipse(uhdc, cxClient div 2 - 20, cyClient div 2 - 160, cxClient div 2 - 5, cyClient div 2 - 140);
            Ellipse(uhdc, cxClient div 2 + 20, cyClient div 2 - 160, cxClient div 2 + 5, cyClient div 2 - 140);
            SelectObject(uhdc, hOldBrush);
    
            //瞳孔
            Ellipse(uhdc, cxClient div 2 - 15, cyClient div 2 - 155, cxClient div 2 - 10, cyClient div 2 - 145);
            Ellipse(uhdc, cxClient div 2 + 15, cyClient div 2 - 155, cxClient div 2 + 10, cyClient div 2 - 145);
    
            //鼻子
            hRedBrush := CreateSolidBrush(RGB(255, 0, 0));
            hOldBrush := SelectObject(uhdc, hRedBrush);
            Ellipse(uhdc, cxClient div 2 - 10, cyClient div 2 - 135, cxClient div 2 + 10, cyClient div 2 - 115);
            SelectObject(uhdc, hOldBrush);
            MoveToEx(uhdc, cxClient div 2, cyClient div 2 - 115, nil);
            LineTo(uhdc, cxClient div 2, cyClient div 2 - 30);
    
            //嘴巴
            Arc(uhdc, cxClient div 2 - 70, cyClient div 2 - 120, cxClient div 2 + 70, cyClient div 2 - 30, cxClient div 2 - 60, cyClient div 2 - 50, cxClient div 2 + 60, cyClient div 2 - 50);
    
            //胡子
            MoveToEx(uhdc, cxClient div 2 - 70, cyClient div 2 - 115, nil);
            LineTo(uhdc, cxClient div 2 - 20, cyClient div 2 - 100);
            MoveToEx(uhdc, cxClient div 2 - 80, cyClient div 2 - 85, nil);
            LineTo(uhdc, cxClient div 2 - 20, cyClient div 2 - 85);
            MoveToEx(uhdc, cxClient div 2 - 70, cyClient div 2 - 55, nil);
            LineTo(uhdc, cxClient div 2 - 20, cyClient div 2 - 70);
            MoveToEx(uhdc, cxClient div 2 + 70, cyClient div 2 - 115, nil);
            LineTo(uhdc, cxClient div 2 + 20, cyClient div 2 - 100);
            MoveToEx(uhdc, cxClient div 2 + 80, cyClient div 2 - 85, nil);
            LineTo(uhdc, cxClient div 2 + 20, cyClient div 2 - 85);
            MoveToEx(uhdc, cxClient div 2 + 70, cyClient div 2 - 55, nil);
            LineTo(uhdc, cxClient div 2 + 20, cyClient div 2 - 70);
    
            //身体
            hOldBrush := SelectObject(uhdc, hBlueBrush);
            Rectangle(uhdc, cxClient div 2 - 90, cyClient div 2, cxClient div 2 + 90, cyClient div 2 + 150);
            SelectObject(uhdc, hOldBrush);
    
            //肚子
            Ellipse(uhdc, cxClient div 2 - 70, cyClient div 2 - 20, cxClient div 2 + 70, cyClient div 2 + 120);
            hTempPen := CreatePen(PS_SOLID, 2, RGB(255, 255, 255));
            hOldPen := SelectObject(uhdc, hTempPen);
            Arc(uhdc, cxClient div 2 - 70, cyClient div 2 - 20, cxClient div 2 + 70, cyClient div 2 + 120, cxClient div 2 + 60, cyClient div 2 - 10, cxClient div 2 - 60, cyClient div 2 - 10);
            SelectObject(uhdc, hOldPen);
    
            //项圈
            hOldBrush := SelectObject(uhdc, hRedBrush);
            RoundRect(uhdc, cxClient div 2 - 95, cyClient div 2 - 5, cxClient div 2 + 95, cyClient div 2 + 10, 20, 20);
            SelectObject(uhdc, hOldBrush);
    
              //铃铛
            HyelloBrush := CreateSolidBrush(RGB(255, 255, 0));
            hOldBrush := SelectObject(uhdc, HyelloBrush);
            Ellipse(uhdc, cxClient div 2 - 15, cyClient div 2, cxClient div 2 + 15, cyClient div 2 + 30);
            RoundRect(uhdc, cxClient div 2 - 15, cyClient div 2 + 10, cxClient div 2 + 15, cyClient div 2 + 15, 2, 2);
            SelectObject(uhdc, hRedBrush);
            Ellipse(uhdc, cxClient div 2 - 4, cyClient div 2 + 18, cxClient div 2 + 4, cyClient div 2 + 26);
            MoveToEx(uhdc, cxClient div 2, cyClient div 2 + 26, nil);
            LineTo(uhdc, cxClient div 2, cyClient div 2 + 30);
            SelectObject(uhdc, hOldBrush);
    
            //口袋
            pie(uhdc, cxClient div 2 - 50, cyClient div 2, cxClient div 2 + 50, cyClient div 2 + 100, cxClient div 2 - 50, cyClient div 2 + 50, cxClient div 2 + 50, cyClient div 2 + 50);
    
            //裤裆
            pie(uhdc, cxClient div 2 - 20, cyClient div 2 + 130, cxClient div 2 + 20, cyClient div 2 + 170, cxClient div 2 + 20, cyClient div 2 + 150, cxClient div 2 - 20, cyClient div 2 + 150);
            hTempPen := CreatePen(PS_SOLID, 2, RGB(255, 255, 255));
            hOldPen := SelectObject(uhdc, hTempPen);
            MoveToEx(uhdc, cxClient div 2 - 20, cyClient div 2 + 150, nil);
            LineTo(uhdc, cxClient div 2 + 20, cyClient div 2 + 150);
            SelectObject(uhdc, hOldPen);
               
            //
            Ellipse(uhdc, cxClient div 2 - 110, cyClient div 2 + 130, cxClient div 2 - 10, cyClient div 2 + 170);
            Ellipse(uhdc, cxClient div 2 + 110, cyClient div 2 + 130, cxClient div 2 + 10, cyClient div 2 + 170);
               
           //
            hOldBrush := SelectObject(uhdc, hBlueBrush);
            apt[0].x := cxClient div 2 - 90;
            apt[0].y := cyClient div 2 + 10;
            apt[1].x := cxClient div 2 - 130;
            apt[1].y := cyClient div 2 + 50;
            apt[2].x := cxClient div 2 - 110;
            apt[2].y := cyClient div 2 + 70;
            apt[3].x := cxClient div 2 - 90;
            apt[3].y := cyClient div 2 + 60;
            Polygon(uhdc, apt, 4);
            SelectObject(uhdc, hOldBrush);
            Ellipse(uhdc, cxClient div 2 - 150, cyClient div 2 + 46, cxClient div 2 - 110, cyClient div 2 + 86);
            hOldBrush := SelectObject(uhdc, hBlueBrush);
            apt[0].x := cxClient div 2 + 90;
            apt[0].y := cyClient div 2 + 10;
            apt[1].x := cxClient div 2 + 130;
            apt[1].y := cyClient div 2 + 50;
            apt[2].x := cxClient div 2 + 110;
            apt[2].y := cyClient div 2 + 70;
            apt[3].x := cxClient div 2 + 90;
            apt[3].y := cyClient div 2 + 60;
            Polygon(uhdc, apt, 4);
            SelectObject(uhdc, hOldBrush);
            Ellipse(uhdc, cxClient div 2 + 150, cyClient div 2 + 46, cxClient div 2 + 110, cyClient div 2 + 86);
            hTempPen := CreatePen(PS_SOLID, 2, RGB(0, 159, 232));
            hOldPen := SelectObject(uhdc, hTempPen);
            MoveToEx(uhdc, cxClient div 2 - 90, cyClient div 2 + 10, nil);
            LineTo(uhdc, cxClient div 2 - 90, cyClient div 2 + 50);
            MoveToEx(uhdc, cxClient div 2 + 90, cyClient div 2 + 10, nil);
            LineTo(uhdc, cxClient div 2 + 90, cyClient div 2 + 50);
            MoveToEx(uhdc, cxClient div 2 - 20, cyClient div 2 + 150, nil);
            SelectObject(uhdc, hOldPen);
            EndPaint(hwnd, ps);
            Exit;
          end;
      end;
    
      result := DefWindowProc(hwnd, uMsg, wParam, lParam);
    end;
    
    begin
      swndClass.cbClsExtra := 0; //窗口类扩展,无
      swndClass.cbWndExtra := 0; //窗口实例扩展
      swndClass.hbrBackground := COLOR_BACKGROUND; //窗口背景颜色黑色
      //LoadCursor()
      swndClass.hCursor := LoadCursor(0, IDC_ARROW); //窗口采用箭头光标
      swndClass.hIcon := LoadIcon(0, IDI_APPLICATION); //窗口最小化图标:采用缺省图标
      swndClass.hInstance := hInstance; //窗口实例句柄
      swndClass.lpfnWndProc := @WindowProc; //窗口处理函数
      swndClass.lpszClassName := 'myWnd'; //窗口类名
      swndClass.lpszMenuName := nil; //窗口菜单
      swndClass.style := CS_DBLCLKS; //窗口样式
      if RegisterClass(swndClass) = 0 then
      begin
        Writeln('windows class register error!');
        Exit;
      end;
    
      mHwnd := CreateWindowEx(0, 'myWnd', 'Delphi Windows', WS_OVERLAPPEDWINDOW,  {滚动条添加}
        CW_USEDEFAULT, CW_USEDEFAULT, 800, 800, HWND_DESKTOP, 0, hInstance, 0);
    
      ShowWindow(mHwnd, SW_SHOW);
      UpdateWindow(mHwnd);
      while GetMessage(message, 0, 0, 0) do
      begin
        TranslateMessage(message);
        DispatchMessage(message);
      end;
    end.

    CreatePen

    CreateSolidBrush

    MoveToEx

    LineTo

    Rectangle

    Ellipse

    RoundRect

    Polygon

    pie

    SelectObject

  • 相关阅读:
    Codevs 2296 仪仗队 2008年省队选拔赛山东
    Codevs 1535 封锁阳光大学
    Codevs 1069 关押罪犯 2010年NOIP全国联赛提高组
    Codevs 1218 疫情控制 2012年NOIP全国联赛提高组
    Codevs 1684 垃圾陷阱
    洛谷 P1108 低价购买
    Vijos P1325桐桐的糖果计划
    Codevs 3289 花匠 2013年NOIP全国联赛提高组
    Codevs 2611 观光旅游(floyed最小环)
    C语言基础之彩色版C语言(内含linux)
  • 原文地址:https://www.cnblogs.com/YiShen/p/9748091.html
Copyright © 2011-2022 走看看