Einzelnen Beitrag anzeigen

venice2
(Gast)

n/a Beiträge
 
#5

AW: Richtige Text länge ist nicht berechenbar

  Alt 16. Nov 2020, 06:42
Die länge von Ellipsis Text stimmt nun habe aber ein ähnliches weiteres Problem.
Ich Ownerdraw mein Edit Control mit GDI+ dazu übergebe ich folgende Parameter.

Delphi-Quellcode:
edInput.SetFont(SKAERO_PUSHBUTFONTSIZE, PWideChar(SKAERO_TEXTFONT),
  FontStyleBoldItalic, SKAERO_ACTIVECAPTION, SKAERO_INACTIVECAPTION,
  True, -1);
Danach konvertiere ich den GDI+ Font in einen HFont damit das Edit den gleichen Font hat wie der den ich zeichne. Stimmt soweit.

Delphi-Quellcode:
procedure TSkinEdit.SetFont(nPointSize: Integer; FontName: String; FontStyle: TFontStyle;
  AktForecolor, InAktForecolor: COLORREF; Shadow: Boolean; ShadowOffset: Single);
var
  Fam: GpFontFamily;
  Gpf: GpFont;
  Graphics: LONG_PTR;
  DC: HDC;
  lf: LOGFONTW;

begin
  Graphics := 0;
  Gpf := nil;
  Fam := nil;

  if Handle <> 0 then
  begin
    FShadow := Shadow;
    FShadowColor := ShadowColor;
    FShadowOffset := ShadowOffset;
    FAktForecolor := AktForecolor;
    FInAktForecolor := InAktForecolor;
    FPointSize := nPointSize;
    FFontName := FontName;
    FFontStyle := FontStyle;

    DC := GetDC(0);
    try
      if GdipCheck(GdipCreateFromHDC(DC, Graphics)) = OK then
      begin
        if GdipCheck(GdipCreateFontFamilyFromName(PWideChar(FFontName), nil, Fam)) = OK then
        begin
          if assigned(Fam) then
          begin
            GdipCheck(GdipCreateFont(Fam, FPointSize, FontStyle, 2, Gpf));
            if assigned(Gpf) then
            begin
              GdipCheck(GdipGetLogFontW(Gpf, Graphics, lf));
              _hfont := CreateFontIndirectW(lf);
              SendMessageW(Handle, WM_SETFONT, WPARAM(_hfont), 0);
            end;
          end;
        end;
      end;
    finally
      ReleaseDC(0, DC);
      if Graphics <> 0 then
        GdipCheck(GdipDeleteGraphics(Graphics));
      if assigned(Gpf) then
        GdipCheck(GdipDeleteFont(Gpf));
      if assigned(Fam) then
        GdipCheck(GdipDeleteFontFamily(Fam));
    end;
  end;
end;
Aber das Caret Offset ist nicht gleich Gezeichneter Font -> Edit Font.

Der blinkende Cursor ist immer ein paar Pixel daneben abhängig von dem was ich schreibe.
Wie kann ich das beheben?

Geändert von venice2 ( 1. Dez 2020 um 15:05 Uhr)
  Mit Zitat antworten Zitat