Autor Beitrag
uko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 220
Erhaltene Danke: 1

Win XP, VISTA, WIndows 7
Delphi 2007/2010 Prof
BeitragVerfasst: Fr 07.05.10 16:01 
Hi,

ich such gerade nach einer Möglichkeit, einen beliebig großen Textcursor darzustellen. Hintergrund ist der: in meinem Programm kann man auf einem Canvas Text eingeben (mittels selbst gezeichneter Texteditoren). Wenn das Programm in diesem Modus ist, wird als Cursor crIBeam verwendet. Da der Benutzer die Fontgröße einstellen kann würde ich gerne den Cursor in der Größe des Fonts darstellen (nicht im Editor, sondern solange ich in diesem Modus über den Canvas mit der Maus rumbewege!). Also 40pt Font, sollte einen entsprechend großen Cursor haben.
Das hat nämlich dann den Vorteil, daß man sieht, wo sein Text genau plaziert wird.

Nur, wie kann man das machen? Ein extra transparentes Fenster mitlaufen zu lassen und den Cursor auf einen Punkt zu reduzieren geht aus Performancegründen nicht, da dann ständig der Hintergrund neu gezeichnet werden müßte.

Kann man den Standardcursor irgendwie dazu mißbrauchen? Oder gibt's da andere Methoden?


ps: wenn es besser passen sollte, dann bitte nach Windows API verschieben

Grüße,
Uli
ffgorcky
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 573

WIN XP/2000 & 7Prof (Familie:Win95,Win98)

BeitragVerfasst: Fr 07.05.10 16:24 
Entschuldigung - meinst Du
1.)den Cursor, der zur Texteingabe blinkt, oder
2.)meinst Du den Mauszeiger?
Wenn Du 1. meinst, dann gucke doch z.B. mal auf der Seite Extrem grosser Cursor - MCSEboard.de MCSE Forum.
uko Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 220
Erhaltene Danke: 1

Win XP, VISTA, WIndows 7
Delphi 2007/2010 Prof
BeitragVerfasst: Fr 07.05.10 16:32 
Ich meine den Mauszeiger, ersteres ist mit Carets erledigt.

Uli
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Fr 07.05.10 16:41 
Ich würde sagen, du Zeichnest dir ein passendes Icon (kann Delphi nicht nativ in der Größe->WinAPI) und lädst selbiges per LoadCursor, so wie man das allgemein für eigene Cursor macht.

Alternativ: Cursor ausblenden und direkt auf dem Ziel-Canvas per XOR malen, das kriegt man dann auch ohne alles neu zeichnen zu müssen wieder weg.

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
uko Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 220
Erhaltene Danke: 1

Win XP, VISTA, WIndows 7
Delphi 2007/2010 Prof
BeitragVerfasst: Mo 10.05.10 14:57 
user profile iconMartok hat folgendes geschrieben Zum zitierten Posting springen:
Ich würde sagen, du Zeichnest dir ein passendes Icon (kann Delphi nicht nativ in der Größe->WinAPI) und lädst selbiges per LoadCursor, so wie man das allgemein für eigene Cursor macht.

Ja, so hab ich's nun gemacht. Funktioniert prima, und nun hab ich auch die Speicherlecks weg :-) Ach ja, nicht wundern wegen dem IPicture unten: ich brauch es als solches um es dem Cursor eines InkOverlays zuweisen zu können.

Danke an alle,
Uli

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
    // Daraus das Text-Cursoricon neu zeichnen
    bmpMask := TBitmap.Create;
    bmpColor := TBitmap.Create;
    try
      With bmpColor do
      begin
        Width  := 8;
        Height := Round5(dFontBaseline);
        Canvas.Brush.Color := clBlack;
        Canvas.FillRect(RECT(0,0,Width,Height));
        Canvas.Pen.Color := clBlack;
        Canvas.MoveTo(4,1);
        Canvas.LineTo(4, Height - 2);
        Canvas.MoveTo(1,0);
        Canvas.LineTo(3,0);
        Canvas.MoveTo(5,0);
        Canvas.LineTo(7,0);
        Canvas.MoveTo(1,Height - 1);
        Canvas.LineTo(3,Height - 1);
        Canvas.MoveTo(5,Height - 1);
        Canvas.LineTo(7,Height - 1);
      end;

      With bmpMask do
      begin
        Width  := 8;
        Height := Round5(dFontBaseline);
        Monochrome := true;
        Canvas.Brush.Color := clWhite;
        Canvas.FillRect(RECT(0,0,Width,Height));
        Canvas.Pen.Color := clBlack;
        Canvas.MoveTo(4,1);
        Canvas.LineTo(4,Height - 2);
        Canvas.MoveTo(1,0);
        Canvas.LineTo(3,0);
        Canvas.MoveTo(5,0);
        Canvas.LineTo(7,0);
        Canvas.MoveTo(1,Height - 1);
        Canvas.LineTo(3,Height - 1);
        Canvas.MoveTo(5,Height - 1);
        Canvas.LineTo(7,Height - 1);
      end;

      // Icon erstellen
      with IconInfo do
      begin
        fIcon := False; // kein Icon sondern Cursor
        xHotspot := 4;
        yHotspot := Round5(dFontBaseline) - 1;
        hbmMask := bmpMask.Handle;
        hbmColor := bmpColor.Handle;
      end;

      // Icon in IPicture laden
      lPictureDisp := nil;
      FCursorTextModePicture.Icon.Handle := CreateIconIndirect(iconInfo);  // FCursorTextModePicture: TPicture als private deklariert und im Create/Destroy erzeugt/gelöscht
      GetOlePicture(FCursorTextModePicture, lPictureDisp);

      // Und als selbiges Speichern
      FCursorTextMode := lPictureDisp as IPicture;
    finally
      bmpColor.Free;
      bmpMask.Free;
    end;