码迷,mamicode.com
首页 > Windows程序 > 详细

《windows程序设计》哆啦A梦(10)

时间:2018-10-06 19:18:06      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:temp   The   window   span   apt   rectangle   hwnd   uname   最小   

技术分享图片

代码如下:

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.

 

《windows程序设计》哆啦A梦(10)

标签:temp   The   window   span   apt   rectangle   hwnd   uname   最小   

原文地址:https://www.cnblogs.com/YiShen/p/9748091.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!