Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
getoutlinetextmetrics (gdi32)
 
.
Summary

C# Signature:

[DllImport("gdi32.dll")]
static extern uint GetOutlineTextMetrics(IntPtr hdc, uint cbData, IntPtr ptrZero);

User-Defined Types:

OUTLINETEXTMETRIC

Notes:

Since otmpFamilyName, otmpFaceName, otmpStyleName, otmpFullName are actually offsets into the structure from the beginning of the structure you need double call GetOutlineTextMetrics.

First call returns needed buffer size the second fills buffer by actual data.

Warning
The OUTLINETEXTMETRIC structure includes a TEXTMETRIC structure which includes some TCHAR fields. A TCHAR can compile to a 16 bit character or a 8 bit character (depending on whether UNICODE is defined). The C# version of the TEXTMETRIC structure on PInvoke.net assumes that the TCHAR is a 16 bit character and when you retrieve a TEXTMETRIC structure with GetTextMetrics you do get a TEXTMETRIC structure with 16 bit characters. However, when you retrive an OUTLINETEXTMETRIC structure with GetOutlineTextMetrics the included TEXTMETRIC structure appears to have 8 bit characters. (These observations were with Windows XP and might not hold true for other operating systems or all fonts.)

Sample Code:

private static void GetOutlineMetrics(IntPtr hdc)
{
    uint cbBuffer = GetOutlineTextMetrics(hdc, 0, IntPtr.Zero);
    if (cbBuffer == 0)
        return;
    IntPtr buffer = Marshal.AllocHGlobal((int)cbBuffer);
      try
    {
        if (GetOutlineTextMetrics(hdc, cbBuffer, buffer) != 0)
        {
            OUTLINETEXTMETRIC otm = new OUTLINETEXTMETRIC();
            otm = (OUTLINETEXTMETRIC)Marshal.PtrToStructure(buffer, typeof(OUTLINETEXTMETRIC));
            string otmpFamilyName = Marshal.PtrToStringAnsi(new IntPtr((int)buffer + otm.otmpFamilyName));
            string otmpFaceName = Marshal.PtrToStringAnsi(new IntPtr((int)buffer + otm.otmpFaceName));;
            string otmpStyleName = Marshal.PtrToStringAnsi(new IntPtr((int)buffer + otm.otmpStyleName));;
            string otmpFullName = Marshal.PtrToStringAnsi(new IntPtr((int)buffer + otm.otmpFullName));;
        }
    }
    finally
    {
        Marshal.FreeHGlobal(buffer);
    }
}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions