7Windows_paint GDI绘图
Posted 养老保险年审
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了7Windows_paint GDI绘图相关的知识,希望对你有一定的参考价值。
// 7Windows_paint.cpp : 定义应用程序的入口点。
//
#include "stdafx.h"
#include "7Windows_paint.h"
#include "resource.h"
#include <iostream>
HINSTANCE g_hInst = NULL;
HANDLE g_hStdout = NULL; //控制台
int g_DrawType = 0;
COLORREF g_nPenColor = RGB(0,0,0); //画笔颜色
int g_nPenStyle = PS_SOLID; //画笔样式
int g_nPenWdith = 1; //画笔宽度
COLORREF g_nBrushColor = RGB(0, 0, 0); //画刷
int g_nBrushStyle = 0xFFFFFFFF; //画刷样式
CHAR szText[256] = { 0 }; //备用字符串
#define PrintLog(x) WriteConsole(g_hStdout, x, strlen(x), NULL, NULL)
void DrawPixel(HDC hDC)
{
COLORREF nColor = RGB(255,0,0);
SetPixel(hDC, 100, 100, nColor);
}
void GetPixelColor(HDC hDC)
{
COLORREF nColor = GetPixel(hDC, 100, 100);
int nRed = GetRValue(nColor);
int nGreen = GetGValue(nColor);
int nBlue = GetBValue(nColor);
sprintf_s(szText, 256, "nRed=%d,nGreen=%d,nBlue=%d", nRed, nGreen, nBlue);
//PrintLog(szText);
MessageBox(NULL, szText, "color", MB_OK);
}
//DrawLine
void DrawLine(HDC hDC)
{
MoveToEx(hDC, 0, 0, NULL); //当前点
LineTo(hDC, 500, 500);
MoveToEx(hDC, 500, 0, NULL);
LineTo(hDC, 0, 500);
}
//DrawArc弧
void DrawArc(HDC hDC)
{
SetArcDirection(hDC, AD_CLOCKWISE);//AD_COUNTERCLOCKWISE //顺时针
Arc(hDC, 400, 200, 500, 300, 500, 200, 400, 200); //顺时针和逆时针画出来的东西不同
SetArcDirection(hDC, AD_COUNTERCLOCKWISE);//AD_CLOCKWISE //逆时针
Arc(hDC, 500, 200, 600, 300, 600, 200, 500, 400); //顺时针和逆时针画出来的东西不同
MoveToEx(hDC, 200, 200, NULL);
AngleArc(hDC, 200, 200, 100, 90, 270);
LineTo(hDC, 200, 200);
}
//DrawPolyLine
//折线
void DrawPolyLine(HDC hDC)
{
POINT ptPolyLine[7] = { 0 }; //三角形需要4个点
ptPolyLine[0].x = 100;
ptPolyLine[0].y = 100;
ptPolyLine[1].x = 200;
ptPolyLine[1].y = 100;
ptPolyLine[2].x = 200;
ptPolyLine[2].y = 200;
ptPolyLine[3].x = 300;
ptPolyLine[3].y = 200;
ptPolyLine[4].x = 300;
ptPolyLine[4].y = 300;
ptPolyLine[5].x = 400;
ptPolyLine[5].y = 300;
ptPolyLine[6].x = 400;
ptPolyLine[6].y = 400;
//两点绘制一直线
Polyline(hDC, ptPolyLine, 7); //绘制折线
//PolylineTo(hDC, ptPolyLine, 4);
/*
分成两组,这两组之间没有任何关联
*/
DWORD nGroup[2] = { 3, 4 };
//PolyPolyline(hDC, ptPolyLine, nGroup, 2);
}
//DrawBizer曲线
void DrawBizer(HDC hDC)
{
POINT ptBizer[7] = { 0 };
ptBizer[0].x = 100; //端点
ptBizer[0].y = 100;
ptBizer[1].x = 150; //控制点
ptBizer[1].y = 50;
ptBizer[2].x = 300; //控制点
ptBizer[2].y = 150;
ptBizer[3].x = 300; //端点
ptBizer[3].y = 100;
ptBizer[4].x = 300; //控制点
ptBizer[4].y = 400;
ptBizer[5].x = 400; //控制点
ptBizer[5].y = 200;
ptBizer[6].x = 500; //端点
ptBizer[6].y = 300;
PolyBezier(hDC, ptBizer, 7);
//为了看的更清楚,把切线也给划出来
MoveToEx(hDC, ptBizer[0].x, ptBizer[0].y,NULL);
LineTo(hDC, ptBizer[1].x, ptBizer[1].y);
MoveToEx(hDC, ptBizer[2].x, ptBizer[2].y, NULL);
LineTo(hDC, ptBizer[3].x, ptBizer[3].y);
}
//DrawPolyDraw多样式线
void DrawPolyDraw(HDC hDC)
{
POINT ptDraw[4] = { 0 };
ptDraw[0].x = 100;
ptDraw[0].y = 100;
ptDraw[1].x = 200;
ptDraw[1].y = 100;
ptDraw[2].x = 200;
ptDraw[2].y = 200;
ptDraw[3].x = 300;
ptDraw[3].y = 200;
BYTE ptType[4] = { 0 }; //PolyDraw第三个参数
ptType[0] = PT_MOVETO;
ptType[1] = PT_LINETO;
ptType[2] = PT_MOVETO;
ptType[3] = PT_LINETO;
PolyDraw(hDC, ptDraw, ptType, 4);
}
//Rect 矩形
void DrawRect(HDC hDC)
{
//矩形
Rectangle(hDC, 100, 100, 200, 200);
//带圆角矩形
RoundRect(hDC, 300, 100, 400, 200, 10, 10);
}
//DrawEllipse圆和椭圆
void DrawEllipse(HDC hDC)
{
//圆
Ellipse(hDC, 100, 100, 200, 200);
//椭圆
Ellipse(hDC, 300, 100, 500, 200);
}
//DrawPie饼图
void DrawPie(HDC hDC)
{
Pie(hDC, 100, 100, 500, 400, 500, 100, 100, 100);
}
//Chord弦
void DrawChord(HDC hDC)
{
Chord(hDC, 100, 100, 500, 400, 500, 100, 100, 100);
}
//DrawPolygon多边形
void DrawPolygon(HDC hDC)
{
POINT ptPolygon[7] = { 0 };
ptPolygon[0].x = 100;
ptPolygon[0].y = 100;
ptPolygon[1].x = 200;
ptPolygon[1].y = 100;
ptPolygon[2].x = 200;
ptPolygon[2].y = 200;
ptPolygon[3].x = 300;
ptPolygon[3].y = 200;
ptPolygon[4].x = 300;
ptPolygon[4].y = 300;
ptPolygon[5].x = 400;
ptPolygon[5].y = 300;
ptPolygon[6].x = 400;
ptPolygon[6].y = 400;
Polygon(hDC, ptPolygon, 7);
}
void OnPaint(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps = { 0 };
HDC hDC = BeginPaint(hWnd,&ps);
//画笔使用
//创建画笔
HPEN hPen = CreatePen(g_nPenStyle, g_nPenWdith, g_nPenColor);
//设置画笔到当前DC
HPEN hOldPen = (HPEN)SelectObject(hDC, hPen);
//画刷使用*/
//创建画刷
/*以下一句为默认画刷*/
//HBRUSH hBrush = CreateSolidBrush(g_nBrushColor);
//创建画刷样式时改写
HBRUSH hBrush = NULL;
if (g_nBrushStyle == 0xFFFFFFFF)
{
hBrush = CreateSolidBrush(g_nBrushColor);
}
else
{
hBrush = CreateHatchBrush(g_nBrushStyle, g_nBrushColor);
}
//设置画刷到当前DC
HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush);
//绘制图形
//在绘制图形里面根据类型绘制图形
- 以上是关于7Windows_paint GDI绘图的主要内容,如果未能解决你的问题,请参考以下文章
适用于所有 Win32 程序员的在 Windows Aero Glass(DWM、GDI、GDI+)上绘图的文档和 API 示例