Autor Beitrag
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Mo 02.06.03 15:08 
Hi,

ich bin gerade dabei ein wenig rumzuprobieren.. :)
Wenn ich eine Komponente von TButton ableite und den Button selber zeichnen möchte.. wie geht das???

Nen Canvas hat ein TWinControl ja logischerweise nicht, deswegen hab ich versucht die WM_PAINT Message abzufangen und dort selber zu zeichnen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TMyButton.WMPaint(var Message: TWMPaint);
var
  R: TRect;
  B: HBrush;
begin
  R:=BoundsRect;
  B:=CreateSolidBrush($0000FF00);
  FillRect(Message.DC,R,B);
end;


Wenn ich nun den Button auf mein Form klicke, zerschießt es mir mein ganzes Delphi... (bzw ganz Windows.. scheint so als würde ich ALLE WM_PAINT's abfangen *gg*)

Hat jemand ne ahnung wie ich das machen kann??? (Möchte KEIN TGraphicControl auf den Button packen, und auch keinen Button von TGraphicControl ableiten :) )

Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
ErnestoChe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 528

Win 2000 pro, CRUX 2.0
Delphi 6 Pers, Open K3
BeitragVerfasst: Mo 02.06.03 15:12 
Hi,

ich weiss nicht, wie das ist mit TButton. Aber ich kann dir empfehlen von TCustomControl abzuleiten. Das kann nämlich auch den Fokus bekommen, und lässt sich ganz easy zeichnen, da es schon die Paint-Methode hat.

MFG

- Ernesto -
Aya Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Mo 02.06.03 15:15 
Hi,

ja.. aber ich möchte es ja grade vom TButton, bzw TControl.
Nicht TCustomControl und nicht TGraphicControl ;)

Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
ErnestoChe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 528

Win 2000 pro, CRUX 2.0
Delphi 6 Pers, Open K3
BeitragVerfasst: Mo 02.06.03 15:22 
Hallo nochmal,

mir fällt da was ein. Ich hatte mal ein Edit von TEdit abgeleitet, da hab ich auch WM_PAINT abgefangen und nen Canvas implementiert. Probiers mal so:

ausblenden 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:
type
  TMyButton = class(TButton)
  public
    FCanvas: TControlCanvas;

// ..................................


procedure TMyButton.WMPaint(var Message: TWMPaint); 
//var 
 // R: TRect; 
  //B: HBrush; 
begin 
  //  R:=BoundsRect; 
  //  B:=CreateSolidBrush($0000FF00); 
  //  FillRect(Message.DC,R,B); 

  FCanvas := TControlCanvas.Create;
  FCanvas.Control := Self;  

  with FCanvas do 
  begin
    //........
    // .......
  end;
end;


MFG

- Ernesto -
Aya Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Mo 02.06.03 15:27 
Hi,

das mit dem Canvas hatte ich eben auch gemacht (nur halt das Canvas im Constructor erstellt).

Nur, wenn ich jetzt im WM_PAINT auf dem Canvas zeichne hab ich ProzessorAuslastung von 100%...

Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
ErnestoChe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 528

Win 2000 pro, CRUX 2.0
Delphi 6 Pers, Open K3
BeitragVerfasst: Mo 02.06.03 15:50 
Hi,

wann hast Du die Auslastung? Wenn du dein Programm mit deinem Button startest?

Das hatte ich bei meinem Edit nicht. Hab jetzt allerdings den Quellcode nicht da. Wenn ich wieder daheim bin schau ich mal, wie ich das gemacht hatte.

MFG

- Ernesto -
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Mo 02.06.03 15:56 
Wenn du tatsächlich der Meinung bist, daß du alle WM_PAints abfängst (kann ich eigentlich kaum glauben :shock:), hat die Message soweit ich weiß ein hwnd-Field, das könntest du auf das Handle des Buttons überprüfen, wenn's gleich ist, gehört's zum Button, wenn nicht, ist es irgendein anderen Paint.
Ansonsten wäre vielleicht ein Screenshot hilfreich, wie dein Windows aussieht, nachdem das Programm mit dem Button gestartet wurde, falls das möglich ist.
Andererseits: Warum willst du nicht von TCustomControl ableiten? Was stört dich denn daran, außer das es anscheinend leichter zu implementieren ist?

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
Aya Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Mo 02.06.03 16:02 
huhu,

@Auslastung: Sobald der Button sichtbar ist, und halt gezeichnet wird :)

@Fehler: Na ja... es wird alles links oben in der Ecke gezeichnet.. ob es nu ICQ der IE oder sonstwas is *g* Alles schwupp links oben in die ecke...

und warum ich kein TCustomControl will is einfach, das ich nen bissel rumprobieren will... irgendwie muß es doch mit TControl gehen.. :roll:

Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Mo 02.06.03 16:15 
Also auch normale Fenster...
Werden die denn wenigstens in der richtigen Größe angezeigt? Oder die richtigen Grafiken? Oder sieht alles so aus wie dein Button?

Und hast du das mit dem Handle denn mal ausprobiert?

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert