Windows程式設計畫圖實現哆啦A夢

來源:互聯網
上載者:User

標籤:extra   int   line   cmd   icm   round   div   dex   哆啦a夢   

在看雪論壇上看到的一個文章,很喜歡,轉載一下。原文地址:http://bbs.pediy.com/showthread.php?t=138630
哆啦A夢是畫出來的,不知道作者算這些座標位置算了多久,真的很犀利。記得原來看《Windows程式設計》的時候,每次看到GDI都不是很理解,也沒有仔細去研究。現在編程也很少與GDI打交道,還是等以後有空了在深入瞭解一下吧。把這個代碼轉載一份到部落格,以後再回頭研究一下。順便貼一下程式運行後的:(很酷吧~~~)
字數補丁~代碼瘋子~程式人生~字數補丁~代碼瘋子~程式人生~字數補丁~代碼瘋子~程式人生

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
// 請以C語言尾碼(*.c)儲存檔案#include <windows.h>#include <math.h> #define NUM    1000#define TWOPI  (2 * 3.1415926) LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){static TCHAR szAppName[] = TEXT ("HelloWin") ;HWND         hwnd ;MSG          msg ;WNDCLASS     wndclass ;int cx, cy ; cx = GetSystemMetrics(SM_CXSCREEN) / 2 - 200;cy = GetSystemMetrics(SM_CYSCREEN) / 2 - 200;  wndclass.style         = CS_HREDRAW | CS_VREDRAW ;wndclass.lpfnWndProc   = WndProc ;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 (/*GRAY*/WHITE_BRUSH) ;wndclass.lpszMenuName  = NULL ;wndclass.lpszClassName = szAppName ; if (!RegisterClass (&wndclass)){MessageBox (NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR) ;return 0 ;} RegisterClass (&wndclass); hwnd = CreateWindow (szAppName,                  // window class nameTEXT ("The Hello Program"), // window captionWS_OVERLAPPEDWINDOW,        // window stylecx,               // initial x positioncy,               // initial y position400,              // initial x size400,              // initial y sizeNULL,                       // parent window handleNULL,                       // window menu handlehInstance,                  // program instance handleNULL) ;                     // creation parameters ShowWindow (hwnd, iCmdShow) ;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 ;static int cxClient, cyClient ;HBRUSH hBrush ;int i ;POINT apt[NUM],leftHand[] = {cxClient / 2 - 60, cyClient / 2 - 20,cxClient / 2 - 100, cyClient / 2 + 10,cxClient / 2 - 100, cyClient / 2 + 30,cxClient / 2 - 60, cyClient / 2 + 10},rightHand[] = {cxClient / 2 + 60, cyClient / 2 - 20,cxClient / 2 + 100, cyClient / 2 + 10,cxClient / 2 + 100, cyClient / 2 + 30,cxClient / 2 + 60, cyClient / 2 + 10} ; switch (message){case WM_SIZE:cxClient = LOWORD (lParam) ;cyClient = HIWORD (lParam) + 120;return 0 ; case WM_PAINT:hdc = BeginPaint (hwnd, &ps) ; Ellipse (hdc, cxClient / 2 - 70, cyClient / 2 + 55, cxClient / 2, cyClient / 2 + 85) ;      //腳Ellipse (hdc, cxClient / 2, cyClient / 2 + 55, cxClient / 2 + 70, cyClient / 2 + 85) ; hBrush = CreateSolidBrush (RGB (100, 150, 255)) ;SelectObject (hdc, hBrush) ; //    Rectangle (hdc, cxClient / 2 - 60, cyClient / 2 - 60, cxClient / 2 +60, cyClient / 2 + 70);    //身體RoundRect (hdc, cxClient / 2 - 60, cyClient / 2 - 60, cxClient / 2 + 60, cyClient / 2 + 70, 50, 20); DeleteObject (hBrush) ; hBrush = GetStockObject (WHITE_BRUSH) ;SelectObject (hdc, hBrush) ; Ellipse (hdc, cxClient / 2 - 50, cyClient / 2 - 50, cxClient / 2 + 50, cyClient / 2 + 50) ;    //肚子部分 hBrush = CreateSolidBrush (RGB (100, 150, 255)) ;SelectObject (hdc, hBrush) ; Ellipse (hdc, cxClient / 2 - 100, cyClient / 2 - 220, cxClient / 2 +100, cyClient / 2 - 20) ;  //頭部 DeleteObject (hBrush) ; hBrush = GetStockObject (WHITE_BRUSH) ;SelectObject (hdc, hBrush) ; Ellipse (hdc, cxClient / 2 - 85, cyClient / 2 - 170, cxClient / 2 + 85, cyClient / 2 - 20) ;  //臉部Ellipse (hdc, cxClient / 2 - 40, cyClient / 2 - 190, cxClient / 2, cyClient / 2 - 140 ) ;    //眼眶左Ellipse (hdc, cxClient / 2, cyClient / 2 - 190, cxClient / 2 + 40, cyClient /2 - 140) ;      //眼眶右 hBrush = GetStockObject (BLACK_BRUSH) ;SelectObject (hdc, hBrush) ; Ellipse (hdc, cxClient / 2 - 15, cyClient / 2 - 155, cxClient / 2 -10, cyClient / 2 - 150) ;  //眼睛左Ellipse (hdc, cxClient / 2 + 10, cyClient / 2 - 155, cxClient / 2 + 15, cyClient / 2 -150) ;  //眼睛右 DeleteObject (hBrush) ; hBrush = CreateSolidBrush (RGB (255, 0, 0)) ;SelectObject (hdc, hBrush) ; Ellipse (hdc, cxClient / 2 - 10, cyClient / 2 - 150, cxClient / 2 +10, cyClient / 2 -130) ;    //鼻子 MoveToEx (hdc, cxClient / 2, cyClient / 2 -130, NULL) ;LineTo (hdc, cxClient / 2, cyClient / 2 - 60) ; MoveToEx (hdc, cxClient / 2 - 40, cyClient / 2 - 75, NULL);          //嘴for (i = 0; i < NUM / 2; i++){apt[i].x = cxClient / 2 - 40 + i * 160 / NUM ;apt[i].y = cyClient / 2 - 75 +(int) (30 * sin (TWOPI * i / NUM)) / 2 ; LineTo(hdc, apt[i].x, apt[i].y) ;}  MoveToEx (hdc, cxClient / 2 - 60, cyClient / 2 - 140, NULL) ;        //鬍鬚LineTo (hdc, cxClient / 2 - 20, cyClient / 2 - 120) ; MoveToEx (hdc, cxClient / 2 - 60, cyClient / 2 - 110, NULL) ;LineTo (hdc, cxClient / 2 - 20, cyClient / 2 - 110) ; MoveToEx (hdc, cxClient / 2 - 60, cyClient / 2 - 80, NULL);LineTo (hdc, cxClient / 2 - 20, cyClient / 2 - 100) ; MoveToEx (hdc, cxClient / 2 + 60, cyClient / 2 -140, NULL) ;LineTo (hdc, cxClient / 2 + 20, cyClient / 2 - 120) ; MoveToEx (hdc, cxClient / 2 + 60, cyClient / 2 - 110, NULL) ;LineTo (hdc, cxClient / 2 +20, cyClient / 2 - 110) ; MoveToEx (hdc, cxClient / 2 +60, cyClient / 2 - 80, NULL) ;LineTo (hdc, cxClient / 2 + 20, cyClient / 2 - 100) ;  hBrush = GetStockObject (WHITE_BRUSH) ;                    //口袋SelectObject (hdc, hBrush) ; Chord (hdc, cxClient / 2 - 40, cyClient / 2 - 40, cxClient / 2 + 40, cyClient / 2 +40,cxClient / 2 - 40, cyClient / 2 + 10, cxClient / 2 +40, cyClient / 2 + 10) ;   hBrush = CreateSolidBrush (RGB (255, 0, 0));                //脖子上的套圈SelectObject (hdc, hBrush) ; RoundRect (hdc, cxClient / 2 - 70, cyClient / 2 - 40, cxClient / 2 + 70, cyClient / 2 - 20, 20, 20); DeleteObject (hBrush) ; hBrush = CreateSolidBrush (RGB (100, 150, 255)) ;              //手臂SelectObject (hdc, hBrush) ; SetPolyFillMode (hdc, WINDING) ;Polygon (hdc, leftHand, 4) ; SetPolyFillMode (hdc, WINDING) ;Polygon (hdc, rightHand, 4) ; DeleteObject (hBrush) ; hBrush = GetStockObject (WHITE_BRUSH) ;                    //手SelectObject (hdc, hBrush) ; Ellipse (hdc, cxClient / 2 - 115, cyClient / 2 + 5, cxClient / 2 - 85, cyClient / 2 + 35) ;Ellipse (hdc, cxClient / 2 + 115, cyClient / 2 + 5, cxClient / 2 + 85, cyClient / 2 + 35) ;  hBrush = CreateSolidBrush (RGB (250, 255, 150)) ;              //鈴鐺SelectObject (hdc, hBrush) ; Ellipse (hdc, cxClient / 2 - 10, cyClient / 2 - 35, cxClient / 2 + 10, cyClient / 2 - 15) ; DeleteObject (hBrush) ; hBrush = GetStockObject (BLACK_BRUSH) ;SelectObject (hdc, hBrush) ; Ellipse (hdc, cxClient / 2 - 4, cyClient / 2 - 29, cxClient / 2 + 4, cyClient / 2 - 21) ; MoveToEx (hdc, cxClient / 2, cyClient / 2 - 25, NULL) ;LineTo (hdc, cxClient / 2, cyClient / 2 - 15) ; EndPaint (hwnd, &ps) ;return 0 ; case WM_DESTROY:PostQuitMessage (0) ;return 0 ; }return DefWindowProc (hwnd, message, wParam, lParam) ;}

 

 

http://www.programlife.net/using-windows-programming-paint-doraemon.html

Windows程式設計畫圖實現哆啦A夢

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.