// 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的更多相关文章

  1. C#中可直接调用WIN32的API函数--USER32.DLL

    Win32的API函数可以直接在C#中直接调用,在做WinForm时还是很有帮助的.有时候直接调用Win32的API,可以很高效的实现想要的效果. using System; using System ...

  2. Delphi的Win32的API调用简单介绍

    1.     介绍Win32 API和Win32系统.还要讨论Win32系统的功能以及它与16位系统在功能上的几个主要区别.只是让对Win32系统有一个基本的了解.当已经基本了解Win32操作后,就可 ...

  3. Win32调试API原理

    在Win32中自带了一些API函数,它们提供了相当于一般调试器的大多数功能,这些函数统称为Win32调试API(Win32 Debug API).利用这些API可以做到加载一个程序或捆绑到一个正在运行 ...

  4. C#调用Win32 的API函数--User32.dll ----转载

    Win32的API函数是微软自己的东西,可以直接在C#中直接调用,在做WinForm时还是很有帮助的.有时候我们之直接调用Win32 的API,可以很高效的实现想要的效果. using System; ...

  5. Windows Graphics Programming Win32 GDI and DirectDraw第六章疑问

    <Windows Graphics Programming Win32 GDI and DirectDraw>6.1节中有这样的描述: The Windows NT/2000 graphi ...

  6. 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 ...

  7. 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 ...

  8. Load PE from memory(反取证)(未完)

      Article 1:Loading Win32/64 DLLs "manually" without LoadLibrary() The most important step ...

  9. Win32 GDI 非矩形区域剪裁,双缓冲技术

    传统的Win32通过GDI提供图形显示的功能,包括了基本的绘图功能,如画线.方块.椭圆等等,高级功能包括了多边形和Bezier的绘制.这样app就不用关心那些图形学的细节了,有点类似于UNIX上的X- ...

随机推荐

  1. 标定版制作(棋盘、圆点、aruco等)

    标定板这个东西,对于双目.立体视觉来说那都是必须的.我们这里提供一些做好的标定板,也提供制作标定板的制作方法 一.基本制作思路(以棋盘标定板为例) 1.  “插入” - “表格” 根据提示选择多少行乘 ...

  2. ZOJ 2112 Dynamic Rankings(树状数组套主席树 可修改区间第k小)题解

    题意:求区间第k小,节点可修改 思路:如果直接用静态第k小去做,显然我更改一个节点后,后面的树都要改,这个复杂度太高.那么我们想到树状数组思路,树状数组是求前缀和,那么我们可以用树状数组套主席树,求出 ...

  3. 论文笔记:Siamese Cascaded Region Proposal Networks for Real-Time Visual Tracking

    Siamese Cascaded Region Proposal Networks for Real-Time Visual Tracking 2019-03-20 16:45:23 Paper:ht ...

  4. j2ee课程设计—基于activiti的请休假系统

    前言 课设基于SSM框架,数据库采用mysql,主要业务交给activiti,版本控制利用github. 参考资料: Intellij 部署SSM框架 Activiti就是这么简单 方大师的教材 下文 ...

  5. 前端学习之HTML

    HTML介绍 Web服务本质 import socket sk = socket.socket() sk.bind(("127.0.0.1", 8080)) sk.listen(5 ...

  6. CI框架简单使用

    CodeIgniter框架 1.回忆MVC 1.1.M:模型,提供数据,保存数据 1.2.V:视图,只负责显示,表单form 1.3.C:控制器,协调模型和视图 1.4.action:动作,是控制器中 ...

  7. vue文档阅读笔记——计算属性和侦听器

    页面链接:https://cn.vuejs.org/v2/guide/computed.html 注意点 计算属性用于 替代模板内的表达式. 如果计算属性所依赖的属性未更新,会返回自身的缓存. 侦听器 ...

  8. scss、sass、less的对比与区别

    什么是Sass和Less? sass和less都属于CSS预处理器. css预处理定义了一种新的语言,其基本思想是,用一种专门的编程语言,为css增加了一些编程的特性,将CSS作为目标生成文件,然后开 ...

  9. UP_GetRecordByPage

    CREATE PROCEDURE [dbo].[UP_GetRecordByPage] @tblName varchar(255), -- 表名 @fldName varchar(255), -- 主 ...

  10. 小程序App.js 传递数据给实例(app异步数据问题)

    在最开始初始化的时候,都会触发app.js 这个里面的onload生命方法, 在这个方法里面我们可以获取之前的存储数据/异步请求等等操作, 但是这些操作一般都是需要稍许时间.也就是说在其他界面加载结束 ...