C# [Win32] [GDI+] [API] Load HFONT from Memory
// gdiplusenums.h //--------------------------------------------------------------------------
// FontStyle: face types and common styles
//-------------------------------------------------------------------------- public enum FontStyle
{
FontStyleRegular = ,
FontStyleBold = ,
FontStyleItalic = ,
FontStyleBoldItalic = ,
FontStyleUnderline = ,
FontStyleStrikeout =
}; //--------------------------------------------------------------------------
// Unit constants
//-------------------------------------------------------------------------- public enum Unit
{
UnitWorld, // 0 -- World coordinate (non-physical unit)
UnitDisplay, // 1 -- Variable -- for PageTransform only
UnitPixel, // 2 -- Each unit is one device pixel.
UnitPoint, // 3 -- Each unit is a printer's point, or 1/72 inch.
UnitInch, // 4 -- Each unit is 1 inch.
UnitDocument, // 5 -- Each unit is 1/300 inch.
UnitMillimeter // 6 -- Each unit is 1 millimeter.
};
// gdiplusgpstubs.h public unsafe struct GpFont { }; public unsafe struct GpFontCollection { }; public unsafe struct GpFontFamily { }; public unsafe struct GpStatus
{
private Int32 m_val;
};
// gdiplusflat.h
[DllImport("gdiplus.dll")]
public static extern
int /*GpStatus*/ /*WINGDIPAPI*/
GdipCloneFontFamily(GpFontFamily* fontFamily, GpFontFamily** clonedFontFamily); [DllImport("gdiplus.dll")]
public static extern
int /*GpStatus*/ /*WINGDIPAPI*/
GdipCreateFont(
/*GDIPCONST*/ GpFontFamily* fontFamily,
float /*REAL*/ emSize,
int /*INT*/ style,
Unit unit,
GpFont** font
); [DllImport("gdiplus.dll")]
public static extern
int /*GpStatus*/ /*WINGDIPAPI*/
GdipDeleteFont(GpFont* font); [DllImport("gdiplus.dll")]
public static extern
int /*GpStatus*/ /*WINGDIPAPI*/
GdipDeletePrivateFontCollection(GpFontCollection** fontCollection); [DllImport("gdiplus.dll")]
public static extern
int /*GpStatus*/ /*WINGDIPAPI*/
GdipGetFamily(GpFont* font, GpFontFamily** family); [DllImport("gdiplus.dll")]
public static extern
int /*GpStatus*/ /*WINGDIPAPI*/
GdipGetFontCollectionFamilyCount(
GpFontCollection* fontCollection,
int* /*INT**/ numFound
); [DllImport("gdiplus.dll")]
public static extern
int /*GpStatus*/ /*WINGDIPAPI*/
GdipGetFontCollectionFamilyList(
[In] /*_In_*/ GpFontCollection* fontCollection,
[In] /*_In_*/ int /*INT*/ numSought,
[Out] /*_Out_writes_to_(numSought, * numFound)*/ GpFontFamily** gpfamilies/*[]*/,
[Out] /*_Out_*/ int* /*INT**/ numFound
); [DllImport("gdiplus.dll")]
public static extern
int /*GpStatus*/ /*WINGDIPAPI*/
GdipGetFontHeight(/*GDIPCONST*/ GpFont* font, /*GDIPCONST*/ GpGraphics* graphics,
float* /*REAL**/ height); [DllImport("gdiplus.dll")]
public static extern
int /*GpStatus*/ /*WINGDIPAPI*/
GdipGetFontSize(GpFont* font, float* /*REAL**/ size); [DllImport("gdiplus.dll")]
public static extern
int /*GpStatus*/ /*WINGDIPAPI*/
GdipGetFontStyle(GpFont* font, int* /*INT**/ style); [DllImport("gdiplus.dll")]
public static extern
int /*GpStatus*/ /*WINGDIPAPI*/
GdipGetFontUnit(GpFont* font, Unit* unit); [DllImport("gdiplus.dll")]
public static extern
int /*GpStatus*/ /*WINGDIPAPI*/
GdipGetLogFontA(GpFont* font, GpGraphics* graphics, LOGFONTA* logfontA); [DllImport("gdiplus.dll")]
public static extern
int /*GpStatus*/ /*WINGDIPAPI*/
GdipGetLogFontW(GpFont* font, GpGraphics* graphics, LOGFONTW* logfontW); [DllImport("gdiplus.dll")]
public static extern
int /*GpStatus*/ /*WINGDIPAPI*/
GdipNewInstalledFontCollection(GpFontCollection** fontCollection); [DllImport("gdiplus.dll")]
public static extern
int /*GpStatus*/ /*WINGDIPAPI*/
GdipNewPrivateFontCollection(GpFontCollection** fontCollection); [DllImport("gdiplus.dll")]
public static extern
int /*GpStatus*/ /*WINGDIPAPI*/
GdipPrivateAddMemoryFont(
GpFontCollection* fontCollection,
/*GDIPCONST*/ void* memory,
int /*INT*/ length
);
// wingdi.h
[DllImport("gdi32.dll")]
public static extern
/*WINGDIAPI*/ void* /*HANDLE*/ /*WINAPI*/ AddFontMemResourceEx([In] /*_In_reads_bytes_(cjSize)*/ void* /*PVOID*/ pFileView,
[In] /*_In_*/ uint /*DWORD*/ cjSize,
/*_Reserved_*/ void* /*PVOID*/ pvResrved,
[In] /*_In_*/ uint* /*DWORD**/ pNumFonts); [DllImport("gdi32.dll")]
public static extern void* CreateFontIndirectW(
[In] LOGFONTW* lplf
); [DllImport("gdi32.dll")]
public static extern int DeleteObject(
[In] void* hObject
); [DllImport("gdi32.dll")]
public static extern /*WINGDIAPI*/ int /*BOOL*/ /*WINAPI*/ RemoveFontMemResourceEx([In] /*_In_*/ void* /*HANDLE*/ h);
// winuser.h
[DllImport("user32.dll")]
public static extern void* GetDC(
[In] void* hWnd
); [DllImport("user32.dll")]
public static extern int ReleaseDC(
[In] void* hWnd,
[In] void* hDC
);
public static bool GpSucceeded(int iGpStatus)
{
return iGpStatus == ;
} public static void* LoadHFontFromMemory(byte* pv, int iLength) {
void* hfont = null;
uint dw;
_hfontres = AddFontMemResourceEx(pv, (uint)iLength, null, &dw);
if (_hfontres != null)
{
int gps;
GdiplusStartupInput gsi; gsi.GdiplusVersion = ;
void* token;
if (GpSucceeded(gps = GdiplusStartup(&token, &gsi, null)))
{
GpFontCollection* gpfc;
if (GpSucceeded(gps = GdipNewPrivateFontCollection(&gpfc)))
{
if (GpSucceeded(gps = GdipPrivateAddMemoryFont(gpfc, pv, iLength)))
{
int f, f2;
GdipGetFontCollectionFamilyCount(gpfc, &f);
GpFontFamily** ppl = (GpFontFamily**)malloc((void*)(f * sizeof(void*)));
GdipGetFontCollectionFamilyList(gpfc, f, ppl, &f2);
GpFont* gpf;
if (GpSucceeded(gps = GdipCreateFont(*ppl, 16f, (int)FontStyle.FontStyleRegular, Unit.UnitPoint, &gpf)))
{
void* hdc = GetDC(null);
GpGraphics* gpg;
if (GpSucceeded(gps = GdipCreateFromHDC(hdc, &gpg)))
{
LOGFONTW lf;
GdipGetLogFontW(gpf, gpg, &lf);
hfont = CreateFontIndirectW(&lf); GdipDeleteGraphics(gpg);
}
ReleaseDC(null, hdc);
GdipDeleteFont(gpf);
}
free(ppl);
}
GdipDeletePrivateFontCollection(&gpfc);
}
GdiplusShutdown(token);
}
}
return hfont;
} void* _hfontres;
void* _hfont;
static void* WndProc(
void* hwnd,
uint uMsg,
void* wParam,
void* lParam
) {
switch (uMsg) {
case WM_CREATE: {
byte* pbuf = null;
//...
// Load Font Type from [File | Resources] to Memory
//...
_hfont = LoadHFontFromMemory(pbuf);
SendMessageW(hwnd, WM_SETFONT, _hfont, null);
}
break;
case WM_DESTROY: {
DeleteObject(_hfont);
RemoveFontMemResourceEx(_hfontres);
//...
}
break;
}
}
C# [Win32] [GDI+] [API] Load HFONT from Memory的更多相关文章
- C#中可直接调用WIN32的API函数--USER32.DLL
Win32的API函数可以直接在C#中直接调用,在做WinForm时还是很有帮助的.有时候直接调用Win32的API,可以很高效的实现想要的效果. using System; using System ...
- Delphi的Win32的API调用简单介绍
1. 介绍Win32 API和Win32系统.还要讨论Win32系统的功能以及它与16位系统在功能上的几个主要区别.只是让对Win32系统有一个基本的了解.当已经基本了解Win32操作后,就可 ...
- Win32调试API原理
在Win32中自带了一些API函数,它们提供了相当于一般调试器的大多数功能,这些函数统称为Win32调试API(Win32 Debug API).利用这些API可以做到加载一个程序或捆绑到一个正在运行 ...
- C#调用Win32 的API函数--User32.dll ----转载
Win32的API函数是微软自己的东西,可以直接在C#中直接调用,在做WinForm时还是很有帮助的.有时候我们之直接调用Win32 的API,可以很高效的实现想要的效果. using System; ...
- Windows Graphics Programming Win32 GDI and DirectDraw第六章疑问
<Windows Graphics Programming Win32 GDI and DirectDraw>6.1节中有这样的描述: The Windows NT/2000 graphi ...
- Fielddata is disabled on text fields by default. Set fielddata=true on [gender] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memor
ES进行如下聚合操作时,会报如题所示错误: ➜ Downloads curl -XPOST 'localhost:9200/bank/_search?pretty' -d ' { "size ...
- Elasticsearch 报错:Fielddata is disabled on text fields by default. Set `fielddata=true` on [`your_field_name`] in order to load fielddata in memory by uninverting the inverted index.
Elasticsearch 报错: Fielddata is disabled on text fields by default. Set `fielddata=true` on [`your_fi ...
- Load PE from memory(反取证)(未完)
Article 1:Loading Win32/64 DLLs "manually" without LoadLibrary() The most important step ...
- Win32 GDI 非矩形区域剪裁,双缓冲技术
传统的Win32通过GDI提供图形显示的功能,包括了基本的绘图功能,如画线.方块.椭圆等等,高级功能包括了多边形和Bezier的绘制.这样app就不用关心那些图形学的细节了,有点类似于UNIX上的X- ...
随机推荐
- js三种弹出框的用法
https://blog.csdn.net/cui_angel/article/details/7784211 js中prompt()的用法
- Vue学习——使用vue-cli搭建一个简单的本地vue项目
前提 安装好node.js.npm.vue-cli.为什么要先安装这些,建议查看https://www.cnblogs.com/jixue/p/10673875.html,这个对于vue-cli理解很 ...
- 一键git push脚本(python版)
#!/usr/bin/env python import os import subprocess import sys import time gitconfig = { 'cwd': './blo ...
- MySQL:(二)
多表查询-笛卡尔积 对于数据库中 针对于两张表的记录数的所有记录进行匹配,获得笛卡尔积!⚠️笛卡尔积结果是无效的,必须从笛卡尔积中选取有效的数据结果 !!! -- 显示结果就是笛卡尔积,两个表记录乘积 ...
- Xilinx Vivado的使用详细介绍(5):调用用户自定义封装的IP核
Zedboard OLED Display Controller IP v1 介绍 Author:zhangxianhe 本文档提供了快速添加,连接和使用ZedboardOLED v1.0 IP内核的 ...
- js实现word转换为html
前言 最近接到一个需求,实现上传一个word文档,然后将该word转换成html丢给服务端存上.进行技术调研后发现有三种方法可以实现这个功能:ActiveXObject.docx2html.mammo ...
- Android人脸识别Demo竖屏YUV方向调整和图片保存
本博客包含三个常用方法,用于盛开Android版人脸识别Demo中竖屏使用时送入yuv数据,但一直无法识别的情况. 1.首先可以尝试顺时针旋转90°或270°,然后送入识别SDK. 2.旋转方向后依然 ...
- ubuntu下安装 java环境
步骤1:下载jdk 我选择的jdk版本文件: jdk-8u201-linux-x64.tar 官网下载链接 步骤2:创建单独的目录 sudo mkdir /usr/local/java 步骤3:将下载 ...
- LCSS最长公共子序列算法
0.论文基本介绍以及相关内容 分析移动用户位置的相似性,提取移动用户的相似路径在出行路径预测.兴趣区域发现.轨迹聚类.个性化路径推荐等领域具有广泛的应用. 重点:利用移动用户定位数据找到合适轨迹的表示 ...
- 【杂】暴力出奇迹,lz水数据
做了个填涂颜色的题qwq 洛谷上的qwq,然后我就把这道题水过去了qwq(显然这是不对的,我们不能水数据qwq)当然我本身是80分的qwq end-