AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Load external font

Ein Thema von WojTec · begonnen am 8. Jan 2023 · letzter Beitrag vom 11. Jan 2023
Antwort Antwort
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#1

Load external font

  Alt 8. Jan 2023, 17:57
Delphi-Version: 11 Alexandria
Delphi-Quellcode:
function LoadResourceFont(const AFileName: string): Boolean;
begin
  Result := AddFontResourceW(PWideChar(AFileName)) <> 0;

  if Result then
    SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0)
  ;
end;
And a bit longer function for loading from resource.
I see that SendMessage freezes program. Without it not only not freezes app, but also font is loaded properly to controls

Initially I created functions in D7 and used it on XP-7.
Last I used it on D10.2 on 7, now after years in D11.2 also on 7, but now I see it not working as expacted (also in D7/XE2 test app).

What to do?
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.155 Beiträge
 
Delphi 12 Athens
 
#2

AW: Load external font

  Alt 8. Jan 2023, 19:12
HWND_BROADCAST is never sent with SendMessage, but with PostMessage.
Because otherwise there can be such problems if any application does not respond properly.
Alternatively SendNotifyMessage or SendMessageTimeout.

Why broadcast to ALL running applications in the system if you only temporarily install the font in your application?
SendMessage to Application.Handle



Zitat:
Delphi-Quellcode:
function LoadResourceFont(const AFileName: string): Boolean;
begin
  Result := AddFontResourceW(PWideChar(AFileName)) <> 0;
Delphi-Quellcode:
function LoadResourceFont(const AFileName: WideString): Boolean; // or UnicodeString
begin
  Result := AddFontResourceW(PWideChar(AFileName)) <> 0;
or
Delphi-Quellcode:
function LoadResourceFont(const AFileName: string): Boolean;
begin
  Result := AddFontResource(PChar(AFileName)) <> 0;
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu ( 8. Jan 2023 um 19:17 Uhr)
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#3

Re: Load external font

  Alt 11. Jan 2023, 22:13
Thank you, now working correctly!
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:46 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz