// 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. 机器学习总结(二)bagging与随机森林

    一:Bagging与随机森林 与Boosting族算法不同的是,Bagging和随机森林的个体学习器之间不存在强的依赖关系,可同时生成并行化的方法. Bagging算法 bagging的算法过程如下: ...

  2. Android ANR(应用无响应)解决分析【转】

    本文转载自:https://blog.csdn.net/u014630142/article/details/81709459 来自: http://blog.csdn.net/tjy1985/art ...

  3. Linux常用命令——关机重启命令

    Linux常用命令--关机重启命令 Linux  shutdown 语法:shutdown [选项] 时间 -c 取消前一个关机命令 -h 关机 -r 重启 示例:shutdown -r now 其它 ...

  4. 近视BFC

    首先按照常规解释一下名词,BFC(Block formatting context)直译为"块级格式化上下文".一个独立的渲染区域,只有Block-level box参与, 它规定 ...

  5. OceanBase迁移服务:向分布式架构升级的直接路径

    2019年1月4日,OceanBase迁移服务解决方案在ATEC城市峰会中正式发布.蚂蚁金服资深技术专家师文汇和技术专家韩谷悦共同分享了OceanBase迁移服务的重要特性和业务实践. 蚂蚁数据库架构 ...

  6. 业务限流场景简单实现方案:RateLimiter

    前因:因为本系统中,有大数据高并发的场景.在向下游系统发送请求的时候,需要限流.否则会造成下游系统的堵塞. 实现方案1: Thread.sleep(ms). 优点:简单粗暴,一行代码搞定 缺点:有点l ...

  7. python-*args和**kwargs作用和区别

    1. *args 不定长的参数:*args 无论你传递一个参数还是二个还是多个都可以.(*args传入的是无命名参数,例如:add(1,2,3,4,5)存储的是元祖)args可以自定义其他名称 def ...

  8. selenium、UA池、ip池、scrapy-redis的综合应用案例

    案例: 网易新闻的爬取: https://news.163.com/ 爬取的内容为一下4大板块中的新闻内容 爬取: 特点: 动态加载数据  ,用 selenium 爬虫 1. 创建项目 scrapy ...

  9. IDEA(添加类注释以及方法注释)

    添加类注释: File---Setting----Editor----Code Style-----File and    Code  Templates--------Class #if (${PA ...

  10. 在java程序代码中打开文件

    class     TEST {      public  static  void  main(String[]  args){        System.out.println("He ...