Share via


PrivateFontCollection::AddFontFile-Methode (gdiplusheaders.h)

Die PrivateFontCollection::AddFontFile-Methode fügt dieser privaten Schriftartsammlung eine Schriftartdatei hinzu.

Syntax

Status AddFontFile(
  [in] const WCHAR *filename
);

Parameter

[in] filename

Typ: const WCHAR*

Zeiger auf eine Breitzeichenzeichenfolge, die den Namen einer Schriftartdatei angibt.

Rückgabewert

Typ: Status

Wenn die Methode erfolgreich ist, gibt sie OK zurück, ein Element der Status-Enumeration .

Wenn die Methode fehlschlägt, wird eines der anderen Elemente der Status-Enumeration zurückgegeben.

Hinweise

Wenn Sie die GDI+-API verwenden, dürfen Sie ihrer Anwendung niemals erlauben, beliebige Schriftarten aus nicht vertrauenswürdigen Quellen herunterzuladen. Das Betriebssystem erfordert erhöhte Berechtigungen, um sicherzustellen, dass alle installierten Schriftarten vertrauenswürdig sind.

Beispiele

Im folgenden Beispiel wird ein PrivateFontCollection-Objekt erstellt und der Auflistung drei Schriftartdateien hinzugefügt. Der Code ruft dann die Schriftartfamilien ab, die sich in der Auflistung befinden, und erstellt für jede Familie in der Auflistung eine Schriftart, die zum Zeichnen von Text verwendet wird.

VOID Example_AddFontFile(HDC hdc)
{
   Graphics              graphics(hdc);
   SolidBrush            solidBrush(Color(255, 0, 0, 0));
   INT                   found = 0;
   INT                   count = 0;
   WCHAR                 familyName[50];
   FontFamily*           pFontFamily;
   PrivateFontCollection privateFontCollection;

   // Add three font files to the private collection.
   privateFontCollection.AddFontFile(L"C:\\WINNT\\Fonts\\Arial.ttf");
   privateFontCollection.AddFontFile(L"C:\\WINNT\\Fonts\\Cour.ttf");
   privateFontCollection.AddFontFile(L"C:\\WINNT\\Fonts\\Times.ttf");

   // How many font families are in the private collection?
   count = privateFontCollection.GetFamilyCount();

   // Allocate a buffer to hold the array of FontFamily objects returned by
   // the GetFamilies method.
   pFontFamily = (FontFamily*)malloc(count * sizeof(FontFamily));

   // Get the array of FontFamily objects.
   privateFontCollection.GetFamilies(count, pFontFamily, &found);

   for(INT j = 0; j < found; ++j)
   {
      // Get the font family name.
      pFontFamily[j].GetFamilyName(familyName);
   
      // Pass the family name and the address of the private collection to a
      // Font constructor.
      Font* pFont = new Font(familyName, 16, FontStyleRegular,
                             UnitPixel, &privateFontCollection);

      // Use the font to draw a string.
      graphics.DrawString(
                          L"Hello", 
                          5,          // string length 
                          pFont, 
                          PointF(10.0f, (REAL)j*25), 
                          &solidBrush);

      delete(pFont);
   }

   free(pFontFamily);
}

Anforderungen

   
Unterstützte Mindestversion (Client) Windows XP, Windows 2000 Professional [nur Desktop-Apps]
Unterstützte Mindestversion (Server) Windows 2000 Server [nur Desktop-Apps]
Zielplattform Windows
Kopfzeile gdiplusheaders.h (include Gdiplus.h)
Bibliothek Gdiplus.lib
DLL Gdiplus.dll

Weitere Informationen

Erstellen einer privaten Schriftartsammlung

Installedfontcollection

Privatefontcollection

Verwenden von Text und Schriftarten