Autor Beitrag
DiamondDog
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Mo 08.12.08 14:17 
Hallo Leute,
kann mir jemand von euch sagen wie ich es hinbekomme das von meinem Text, auch die 2te Zeile angezeigt wird?
Hier mein Code:
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:
var ContactId : DWord;
    //Data      : Pointer;
    Cnv       : TCanvas;
    R         : PRect;
    wStr      : WideString;
    R1        : TRect;
    TestIcon  : HICON;
//   TestIcon  : TICON;
begin
  if not Assigned(FfrmMain) then Exit;
  //get unique contact id from msg
  ContactId := FfrmMain.PlugMsg1.WParam;

  //actually all incoming ContactIDs will be only of your plugin, but here i made condition just for example
  if (ContactId <> FfrmMain.UniqContactId) then Exit;

  //get your Data pointer which you added when sent PM_PLUGIN_SPEC_ADD_CNT.
  //IMPORTANT!!! Do NOT make here any heavy loading actions, like cycles FOR, WHILE etc.
  //That's why you have to add Data pointer to PM_PLUGIN_SPEC_ADD_CNT, to get quick access to your data.
  //Data not used here in this example because plugin added only one contact
  //Data      := Pointer(PlugMsg.LParam);

  //create temporary canvas to draw the contact
  Cnv       := TCanvas.Create;
  try

  //get canvas handle from msg
  Cnv.Handle := PlugMsg.NParam;

  //get drawing rectangle pointer from msg
  R := PRect(PlugMsg.Result);

  //this needed to draw text over contact list backgroud
  SetBkMode(Cnv.Handle, TRANSPARENT);

  //get test icon to draw
  TestIcon := LoadImage(0, IDI_INFORMATION, IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR or LR_SHARED or LR_LOADTRANSPARENT);
  //draw icon
  DrawIconEx(Cnv.Handle, 8, 2, TestIcon, 16, 16, 0, 0, DI_NORMAL);
  //dont forget to destroy your icon
  DestroyIcon(TestIcon);

  //text of your contact
  wStr := FfrmMain.Label1.Caption;

  //Use Tahoma to draw your text, because its unicode font
  Cnv.Font.Name  := 'Tahoma';
  Cnv.Font.Color := clNavy;
  Cnv.Font.Size  := 8;
  Cnv.Font.Style := [fsBold];


  R1 := Rect(R^.Left + 26 + FSpecLeft, R^.Top + 1 + FSpecTop, R^.Right, R^.Bottom);

  //text drawing
  //IMPORTANT! If your text may have non ascii symbols, then use unicode drawing.
  DrawTextW(Cnv.Handle, PWideChar(wStr), Length(wStr), R1, DT_LEFT);

  finally
  //free canvas
  Cnv.Free;
  end;
end;
ich hab schon ein wenig gesucht und probiert, aber irgend wie krieg ich es nicht hin.

Danke schon mal fürs Helfen.

Mfg Dog

Edit:

Label1 sieht so aus:
Text +#10#13+ Text


Zuletzt bearbeitet von DiamondDog am Mo 08.12.08 14:59, insgesamt 1-mal bearbeitet
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 08.12.08 14:43 
Versuch es mal mit dem Flag DT_WORDBREAK bei DrawText, außerdem ist unter Windows ein Zeilenumbruch #13#10.
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Mo 08.12.08 14:58 
Also habs so gemacht:
ausblenden Delphi-Quelltext
1:
DrawTextW(Cnv.Handle, PWideChar(wStr), Length(wStr), R1, DT_LEFT+DT_WORDBREAK);					
das funktioniert aber leider nicht wird immer noch nur die erste Zeile angezeigt.

Und da hab ich mich in der Eile wohl verschrieben sorry, habs koriegiert.
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Mo 08.12.08 15:02 
user profile iconDiamondDog hat folgendes geschrieben Zum zitierten Posting springen:
DT_LEFT+DT_WORDBREAK


Versuch es mit DT_LEFT OR DT_WORDBREAK

Gruß,
Jens
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Mo 08.12.08 15:07 
Immer noch das selbe Ergebniss, man sieht nur die erste Zeile
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Mo 08.12.08 15:15 
Komisch. Folgendes wird bei mir in 2 Zeilen ausgegeben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.Button1Click(Sender: TObject);
var r : TRect;
    sText : WideString;
begin
  sText := 'Test' + #13 + '2. Zeile';
  r.Left := 0;
  r.Top := 0;

  DrawTextW(self.Canvas.Handle,PWideChar(sText), length(sText), r, DT_LEFT or DT_WORDBREAK);
end;

Bist Du sicher, dass in deinem Text ein Zeilenumbruch drin ist? Ich habe es mit #13#10, #10 und #13 probiert. Alle Möglichkeiten funktionieren.

Gruß,
Jens
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Mo 08.12.08 15:21 
Ja bin mir 100%tig sicher.
Hab es auch extra noch mal so getestet:
ausblenden Delphi-Quelltext
1:
2:
  //text of your contact
  wStr := 'Das ist'+#10#13+'Ein Test';
führ aber zum selben Ergebniss wie die andern male auch.

Edit liegt es vll an der Zeile:
ausblenden Delphi-Quelltext
1:
R1 := Rect(R^.Left + 26 + FSpecLeft, R^.Top + 1 + FSpecTop, R^.Right, R^.Bottom);					
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Mo 08.12.08 15:27 
user profile iconDiamondDog hat folgendes geschrieben Zum zitierten Posting springen:

Edit liegt es vll an der Zeile:
ausblenden Delphi-Quelltext
1:
R1 := Rect(R^.Left + 26 + FSpecLeft, R^.Top + 1 + FSpecTop, R^.Right, R^.Bottom);					

das war auch mein Gedanke. Vielleicht ist Dein Rect zu klein. Die 2. Zeile wird zwar gezeichnet, aber weil das Rect zu klein ist, nicht angezeigt.

Gruß,
Jens
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Mo 08.12.08 15:37 
Ok habs nun so versucht:
ausblenden Delphi-Quelltext
1:
R1 := Rect(R^.Left + 26 + FSpecLeft, R^.Top + 1 + FSpecTop, R^.Right+10, R^.Bottom+10);					
Mir wird die 2te Zeile angezeigt aber nur so gerade ebend, so das man sehn kann das da was ist. Aber egal ob ich jetzt + 10 oder + 100 dahinter setze es wird kein Stück größer.
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 08.12.08 15:51 
Es gibt ja auch noch DT_CALCRECT, damit kann man errechnen lassen, wie hoch das Rechteck sein muss, um den ganzen Text anzuzeigen.
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Mo 08.12.08 18:58 
Wenn ich es so mache:
ausblenden Delphi-Quelltext
1:
DrawTextW(Cnv.Handle, PWideChar(wStr), Length(wStr), R1, DT_LEFT OR DT_WORDBREAK OR DT_CALCRECT);					
dann wird kein Text mehr angezeigt.

Kannes vll auch an dem Bild was vorher gezeichnet wird liegen?
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 09.12.08 12:05 
Wirft eigentlich außer mir noch irgendwer gelegentlich einen Blick in die Hilfe?
Zitat:
DT_CALCRECT
Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the lpRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Mi 10.12.08 09:06 
user profile iconDeddyH hat folgendes geschrieben Zum zitierten Posting springen:
Wirft eigentlich außer mir noch irgendwer gelegentlich einen Blick in die Hilfe?
Zitat:
DT_CALCRECT
Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the lpRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.
Ok und was soll ich Bitte nun noch machen?
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Mi 10.12.08 09:10 
Du musst DrawTextW 2x aufrufen. Das erste mal mit DT_CALRECT, um zu berechnen, wie groß das Rect für Deinen Text sein muss (das übergebene Rect wird entsprechend geändert). Danach nochmal aufrufen (mit DT_LEFT OR DT_WORDBREAK), um den Text zu zeichnen.

Gruß,
Jens
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Mi 10.12.08 13:58 
Ich habs hinbekommen, hab was im übersehen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
  //to add only one contact
  ButtonAdd.Enabled := False;

  {===================================================}
  {example of how to add own contact to qip contact list}
  PlugMsg1.Msg    := PM_PLUGIN_SPEC_ADD_CNT;

  //set height of your contact here, min 8, max 100.
  PlugMsg1.WParam := 38; // <<< hier kann die höhe eingestellt werden

  //Here you can add pointer to your any record/structure or object,
  //because it will be returned in drawing and in any action with your contact
  PlugMsg1.LParam := 0;

  //send msg to core
  PlugMsg1.DllHandle := FDllHandle;
  FPluginSvc.OnPluginMessage(PlugMsg1);

  if (PlugMsg1.Result <> 0) then UniqContactId := PlugMsg1.Result;