[游戏模版5] Win32 折线 弧线

2020-12-12 21:25

阅读:622

标签:des   style   blog   class   code   c   

 

>_<:first build some points put in poly1 and poly3 the function of>InitInstance

(...)

>_<:then in the function mydraw use> PolylineTo(...)\Polyline(...)\Polygon(...) draw diferent line and use PolyBezierTo(...)\PolyBezier(...) draw two kind curve  separately.

>_<:finally show the different among these functions.>

>_

soscw.com,搜素材  soscw.com,搜素材  soscw.com,搜素材 

soscw.com,搜素材  soscw.com,搜素材

soscw.com,搜素材soscw.com,搜素材
 1 //{{NO_DEPENDENCIES}}
 2 // Microsoft Visual C++ generated include file.
 3 // Used by FE.RC
 4 //
 5 #define IDR_MAINFRAME                    128
 6 #define IDD_FE_DIALOG        102
 7 #define IDD_ABOUTBOX                    103
 8 #define IDS_APP_TITLE                    103
 9 #define IDM_ABOUT                        104
10 #define IDM_EXIT                        105
11 #define IDS_HELLO                        106
12 #define IDI_FE                107
13 #define IDI_SMALL                        108
14 #define IDC_FE                109
15 #define IDC_MYICON                        2
16 #define IDC_STATIC                        -1
17 // Next default values for new objects
18 //
19 #ifdef APSTUDIO_INVOKED
20 #ifndef APSTUDIO_READONLY_SYMBOLS
21 
22 #define _APS_NEXT_RESOURCE_VALUE        129
23 #define _APS_NEXT_COMMAND_VALUE         32771
24 #define _APS_NEXT_CONTROL_VALUE         1000
25 #define _APS_NEXT_SYMED_VALUE           110
26 #endif
27 #endif
reourse.h
soscw.com,搜素材soscw.com,搜素材
 1 // stdafx.h : include file for standard system include files,
 2 //  or project specific include files that are used frequently, but
 3 //      are changed infrequently
 4 //
 5 
 6 #if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
 7 #define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_
 8 
 9 #if _MSC_VER > 1000
10 #pragma once
11 #endif // _MSC_VER > 1000
12 
13 #define WIN32_LEAN_AND_MEAN        // Exclude rarely-used stuff from Windows headers
14 
15 
16 // Windows Header Files:
17 #include 18 
19 // C RunTime Header Files
20 #include 21 #include 22 #include 23 #include 24 
25 // Local Header Files
26 
27 // TODO: reference additional headers your program requires here
28 
29 //{{AFX_INSERT_LOCATION}}
30 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
31 
32 #endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
StdAfx.h

main.cpp

soscw.com,搜素材
  1 #include "stdafx.h"
  2 #include "resourse.h"
  3 #include "math.h"
  4 
  5 #define MAX_LOADSTRING 100
  6 
  7 // Global Variables:
  8 HINSTANCE hInst;                                // current instance
  9 TCHAR szTitle[MAX_LOADSTRING];                                // The title bar text
 10 TCHAR szWindowClass[MAX_LOADSTRING];                                // The title bar text
 11 HPEN hPen;
 12 HBRUSH hBru;
 13 POINT poly1[5];
 14 POINT poly2[5];
 15 POINT poly3[5];
 16 // Foward declarations of functions included in this code module:
 17 ATOM                MyRegisterClass(HINSTANCE hInstance);
 18 BOOL                InitInstance(HINSTANCE, int);
 19 LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
 20 LRESULT CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
 21 void                MyPaint(HDC hdc);
 22 //========================================================================================
 23 int APIENTRY WinMain(HINSTANCE hInstance,
 24                      HINSTANCE hPrevInstance,
 25                      LPSTR     lpCmdLine,
 26                      int       nCmdShow)
 27 {
 28      // TODO: Place code here.
 29     MSG msg;
 30 
 31     MyRegisterClass(hInstance);//调用函数向系统注册窗口类别,输入参数hInstance是目前运行程序的对象代码;
 32 
 33     // 调用InitInstance函数,进行初始化操作;
 34     if (!InitInstance (hInstance, nCmdShow))
 35     {
 36         return FALSE;
 37     }
 38 
 39     // 消息循环(通过消息循环来获取信息,
 40     //进行必要的键盘信息转换而后将控制权交给操作系统,
 41     //有操作系统决定哪个程序的消息处理函数处理消息
 42     while (GetMessage(&msg, NULL, 0, 0)) //获取程序消息
 43     {
 44             TranslateMessage(&msg);//转换伪码及字符
 45             DispatchMessage(&msg);//将控制权交给系统,再有系统决定负责处理消息的程序;
 46     }
 47 
 48     return msg.wParam;
 49 }
 50 //=====================================================================================
 51 
 52 
 53 
 54 //=============================================================================================
 55 //在建立程序窗口实体之前,必须先定义一个窗口类别,其中包含所要建立窗口的信息,
 56 //并向系统注册,这里的MyRegisterClass函数就是进行定义及注册窗口类别的函数。
 57 //==============================================================================================
 58 ATOM MyRegisterClass(HINSTANCE hInstance)
 59 {
 60     WNDCLASSEX wcex;            //申请一个窗口类别“WNDCLASSEX”和结构”wcex“
 61                                 //--------------------------------------------------------------
 62                                 //定义vcex结构的各项信息,其中设定信息处理函数(lpfnWndProc)
 63                                 //为WNDPROC,类别名称为(lpszClassName)为”fe";
 64                                 //--------------------------------------------------------------
 65     wcex.cbSize = sizeof(WNDCLASSEX);
 66 
 67     wcex.style            = CS_HREDRAW | CS_VREDRAW;
 68     wcex.lpfnWndProc    = (WNDPROC)WndProc;
 69     wcex.cbClsExtra        = 0;
 70     wcex.cbWndExtra        = 0;
 71     wcex.hInstance        = hInstance;
 72     wcex.hIcon            = NULL;
 73     wcex.hCursor        = NULL;
 74     wcex.hCursor        = LoadCursor(NULL,IDC_ARROW);
 75     wcex.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);
 76     wcex.lpszMenuName    = NULL;
 77     wcex.lpszClassName    = "fe";
 78     wcex.hIconSm        = NULL;
 79 
 80     return RegisterClassEx(&wcex);//调用RegisterClassEx函数注册类别,返回一个“ATOM"形态的字符串
 81                                   //此字符串即为类别名称”fe";
 82 }
 83 //============================================================================================
 84 
 85 
 86 //============================================================================================
 87 //按照前面所定义的窗口类别来建立并显示实际的程序窗口
 88 //============================================================================================
 89 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
 90 {
 91    HWND hWnd;
 92    HDC hdc;
 93    int i;
 94    const double pi=3.1415926535;
 95    hInst = hInstance; // 把instance handle 储存在全局变量中;
 96 
 97    hWnd = CreateWindow("fe","绘图窗口",WS_OVERLAPPEDWINDOW,
 98       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
 99                       //-----------------------------------------------
100                       //调用CreateWindow函数来建立一个窗口对象
101                       //第一个参数就是窗口建立依据的类别名称
102                       //-----------------------------------------------
103    if (!hWnd)
104    {
105       return FALSE;
106    }
107    //------------------------------------------------
108    //设定窗口的位置及窗口的大小,然后绘制显示在设备上
109    //-------------------------------------------------
110    MoveWindow(hWnd,10,10,600,450,true);//位置及大小
111    ShowWindow(hWnd, nCmdShow);//改定窗口显示时的状态
112    UpdateWindow(hWnd);//将窗口绘制在显示设备上
113 
114    for(i=0;i4;i++)
115    {
116        poly1[i].x = 100 + 100 * sin(i * 72 * pi / 180);
117        poly1[i].y = 100 + 100 * cos(i * 72 * pi / 180);
118 
119        poly2[i].x = poly1[i].x + 300;
120        poly2[i].y = poly1[i].y;
121 
122        poly3[i].x = poly1[i].x + 180;
123        poly3[i].y = poly1[i].y + 200;
124    }
125 
126    hPen = CreatePen(PS_SOLID,5,RGB(20,240,0));
127    //hBru = GreateHatchBrush(HS_BDIAGONAL,RGB(0,255,0));
128 
129    hdc = GetDC(hWnd);
130    MyPaint(hdc);
131    ReleaseDC(hWnd,hdc);
132 
133    return TRUE;
134 }
135 //============================================================================================
136 
137 
138 //============================================================================================
139 //
140 //============================================================================================
141 void MyPaint(HDC hdc)
142 {
143     SelectObject(hdc,hPen);
144     SelectObject(hdc,hBru);
145 
146     //PolylineTo(hdc,poly1,4);
147     //Polyline(hdc,poly2,4);
148     //Polygon(hdc,poly3,4);
149 
150     //PolyBezierTo(hdc,poly1,3);
151     PolyBezier(hdc,poly1,4);
152 }
153 //============================================================================================
154 
155 //============================================================================================
156 //在前面定义类别的时候把WndProc定义为消息处理函数(当某些外部消息发生时,会按消息的类型
157 //来决定该如何进行处理。此外该函数也是一个回叫函数(CALLBACK)(windows系统函数)每一个
158 //程序都会接收信息,选择性接受、处理;
159 //============================================================================================
160 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
161 {
162     PAINTSTRUCT ps;
163     HDC hdc;
164 
165     switch (message)                   //判断消息类型
166     {
167         case WM_PAINT:                //窗口重绘制
168             hdc = BeginPaint(hWnd, &ps);
169             EndPaint(hWnd, &ps);
170             break;
171         case WM_DESTROY:              //处理窗口结束消息
172             PostQuitMessage(0);
173             break;
174         default:
175             return DefWindowProc(hWnd, message, wParam, lParam);
176    }
177    return 0;
178 }
179 //============================================================================================
soscw.com,搜素材

 

[游戏模版5] Win32 折线 弧线,搜素材,soscw.com

[游戏模版5] Win32 折线 弧线

标签:des   style   blog   class   code   c   

原文地址:http://www.cnblogs.com/zjutlitao/p/3732639.html


评论


亲,登录后才可以留言!