// 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. hello2代码的简单分析

    hello2部分代码: String username = request.getParameter("username");//将get~这个方法赋给username这个对象 i ...

  2. Python day 05

    day05 数据类型 今日内容 字典 补充 .extend() users = [1,2,3,4] people = [5,6,7,8] users.extend(people) people.ext ...

  3. ace-editor线上代码编辑器

    package.json { "name": "vue-cli", "version": "1.0.0", " ...

  4. 论文笔记:Learning regression and verification networks for long-term visual tracking

    Learning regression and verification networks for long-term visual tracking 2019-02-18 22:12:25 Pape ...

  5. [luaj]在安卓用使用luaj

    luaj与安卓 什么是luaj luaj是一个Java的一个lua语言引擎,他可以让你在java上运行Lua代码. 在安卓中使用lua干嘛 lua代码可以用来书写布局,或者一些业务逻辑. 为什么要在安 ...

  6. [opengl]Clion配置opengl

    如何在Clion中编写Opengl程序 首先下载 GLAD GLFW 创建Clion工程 在工程中创建文件夹lib.dll.include文件夹 把下载下来的东西放入对应的文件夹 CMakeLists ...

  7. Lintcode93-Balanced Binary Tree-Easy

    93. Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, ...

  8. 单端测序(Single- ead)和双端测序(Pai ed-end和Mate-pai )的关系

    Roche 454,Solexa和ABI SOLID均有单端测序和双端测序两种方式.在基因组De Novo测序过程中,Roche454的单端测序读长可以达到400p,经常用于基因组骨架的组装,而Sol ...

  9. c代码写数据到二进制的bin文件中

    需要将数据写入到bin文件中,打开该文件是一堆乱码,增加数据的保密性 例如:要写入的数据为一个字符串,加上若干个int型整数 #define _CRT_SECURE_NO_WARNINGS #incl ...

  10. go_micro相关书签

    https://micro.mu/docs/cn/index.html gomicro文档 https://github.com/micro/go-micro gomicro代码 windows安装 ...