1、GDI和GDI+区别
GDI GDI+ 的区别 - DoubleLi - 博客园GDI+是GDI的下一个版本,它进行了很好的改进,并且易用性更好。GDI的一个好处就是你不必知道任何关于数据怎样在设备上渲染的细节,GDI+更好的实现了这个优点,也就是说,GDI是一个中低层API,你https://www.cnblogs.com/lidabo/p/3701252.html
2、MFC 初始化GDI+
MFC 初始化 GDI+_jiangqin115的专栏-CSDN博客1. 在stdafx.h文件中在#include 后面加#include //将GDI+头文件加入到工程中 #pragma comment(lib, "gdiplus.lib") //将GDI+的lib文件加入到工程中 using namespace Gdiplus; //使用GDI+的命名空间 2. 在 class C**App : public CWhttps://blog.csdn.net/jiangqin115/article/details/47020583
3、MFC GDI+例子
TestPercent.h
// TestPercent.h : PROJECT_NAME 应用程序的主头文件
//
#pragma once
#ifndef __AFXWIN_H__
#error "在包含此文件之前包含“stdafx.h”以生成 PCH 文件"
#endif
#include "resource.h" // 主符号
// CTestPercentApp:
// 有关此类的实现,请参阅 TestPercent.cpp
//
class CTestPercentApp : public CWinApp
{
public:
CTestPercentApp();
// 重写
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
// 实现
DECLARE_MESSAGE_MAP()
protected:
ULONG_PTR m_gdiplusToken;
};
extern CTestPercentApp theApp;
TestPercent.cpp
// TestPercent.cpp : 定义应用程序的类行为。
//
#include "stdafx.h"
#include "TestPercent.h"
#include "TestPercentDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CTestPercentApp
BEGIN_MESSAGE_MAP(CTestPercentApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
// CTestPercentApp 构造
CTestPercentApp::CTestPercentApp()
{
// 支持重新启动管理器
m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
// TODO: 在此处添加构造代码,
// 将所有重要的初始化放置在 InitInstance 中
}
// 唯一的一个 CTestPercentApp 对象
CTestPercentApp theApp;
// CTestPercentApp 初始化
BOOL CTestPercentApp::InitInstance()
{
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
// 如果一个运行在 Windows XP 上的应用程序清单指定要
// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
//则需要 InitCommonControlsEx()。否则,将无法创建窗口。
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// 将它设置为包括所有要在应用程序中使用的
// 公共控件类。
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
AfxEnableControlContainer();
// 创建 shell 管理器,以防对话框包含
// 任何 shell 树视图控件或 shell 列表视图控件。
CShellManager *pShellManager = new CShellManager;
// 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
// 标准初始化
// 如果未使用这些功能并希望减小
// 最终可执行文件的大小,则应移除下列
// 不需要的特定初始化例程
// 更改用于存储设置的注册表项
// TODO: 应适当修改该字符串,
// 例如修改为公司或组织名
SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
CTestPercentDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: 在此放置处理何时用
// “确定”来关闭对话框的代码
}
else if (nResponse == IDCANCEL)
{
// TODO: 在此放置处理何时用
// “取消”来关闭对话框的代码
}
else if (nResponse == -1)
{
TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n");
TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n");
}
// 删除上面创建的 shell 管理器。
if (pShellManager != NULL)
{
delete pShellManager;
}
// 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
// 而不是启动应用程序的消息泵。
return FALSE;
}
int CTestPercentApp::ExitInstance()
{
// TODO: 在此添加专用代码和/或调用基类
Gdiplus::GdiplusShutdown(m_gdiplusToken); //关闭GDI +
return CWinApp::ExitInstance();
}
TestPercentDlg.cpp
#include "stdafx.h"
#include "TestPercent.h"
#include "TestPercentDlg.h"
#include "afxdialogex.h"
using namespace Gdiplus;
void CTestPercentDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast
// 使图标在工作区矩形中居中
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this); // device context for painting
Graphics gdi(dc);
CRect rt;
GetClientRect(&rt);
SolidBrush brush(Color(188,188,188));
Rect rc2(100, 100, 200, 200);
gdi.FillRectangle(&brush, rc2);
rc2.Inflate(2, 2);
Pen pen(Color(30,30,30));
gdi.DrawRectangle(&pen, rc2);
Pen pen2(Color(188,88,88), 1);
gdi.DrawLine(&pen2, Point(100, 50), Point(200, 400));
CDialogEx::OnPaint();
}
}
4、GDI+文本
Gdi+ drawstring - hgy413 - 博客园1.犯了一个错误:Brush(RGB(255,0,0));这样写程序不会报错,然后很悲剧的怎么也显示不出文字,记录下,以后不要再犯了。自己写的示例代码:CPaintDC dc(this); Graphhttps://www.cnblogs.com/hgy413/archive/2011/09/08/3693595.html