![]() |
Windows.GradientFill
Hi,
Habe gerade mal die Windows Unit durchgekramt aus Langeweile.. Bin auf ne Funktion namens GradientFill gestoßen. Macht die echt das was ich denke was sie macht? Naja egal. Ich will sie gerne mal ausprobieren. Aber ich weiß bei manchen Parametern nicht weiter:
Delphi-Quellcode:
1. NumVertex: Cardinal
procedure TForm1.Button1Click(Sender: TObject);
var test: _TRIVERTEX; begin test.x := 20; test.y := 50; test.Red := 100; test.Green := 50; test.Blue := 30; test.Alpha := 125; Windows.GradientFill(Canvas.Handle,ehm,{1},{2},{3},GRADIENT_FILL_TRIANGLE); end; 2. Mesh: Pointer 3. NumMesh: Cardinal Was bedeuten diese Parameter und was muss ich übergeben? Vorallem bei dem Pointer hab ich keine Ahnung was ich da Pointern soll... Ich hab mal irgendnen Schwachsinn übergeben da oder was nicht so Schwachsinniges aber es passiert einfach nie was. Es gibt auch keine AV... Gruß Neutral General |
Re: Windows.GradientFill
Die Hilfe sagt mir:
Zitat:
|
Re: Windows.GradientFill
Ok danke... Naja meine Hilfe hat mir komischerweise nichts dazu gesagt .... :roll:
STOPP! Zitat:
|
Re: Windows.GradientFill
Ist halt (wie so viele Dinge) von Borland nicht korrekt deklariert worden. Nimm ein Array von TTriVertex Elementen und übergib das erste als Var-Parameter.
|
Re: Windows.GradientFill
Ich habe mir grad eine Funktion gebastelt:
Delphi-Quellcode:
Aufruf zB.:
var
_GradientFill: function(DC: HDC; pTriVertex: Pointer; dwNumVertex: DWORD; pMesh: Pointer; dwNumMesh, dwMode: DWORD): DWORD; stdcall; { external in "msimg32.dll" } type TFillMode = GRADIENT_FILL_RECT_H..GRADIENT_FILL_RECT_V; function wGradientFill(DC: HDC; fillRect: TRect; startColor, endColor: COLORREF; FillMode: TFillMode): Boolean; type _TTRIVERTEX = packed record X, Y: DWORD; Red, Green, Blue, Alpha: Word; end; var tv: array [0..1] of _TTRIVERTEX; gr: GRADIENT_RECT; hLib: THandle; begin // ------------------------------------------------------------------------- // sollte global aufgerufen werden zB. in FormCreate // an sonsten wird das laden und freigeben unnötig oft aufgerufen hLib := LoadLibrary('MSIMG32.DLL'); if hLib <> 0 then @_GradientFill := GetProcAddress(hLib, 'GradientFill'); // ------------------------------------------------------------------------- if @_GradientFill <> nil then begin // fillmode direction gr.UpperLeft := 0; gr.LowerRight := 1; // eckpunkte festlegen tv[0].x := fillRect.Left; tv[0].y := fillRect.Top; tv[1].x := fillRect.Right; tv[1].y := fillRect.Bottom; // ------------------------------------------------------------------------- // -> $0000 or BYTE(startColor shr 8) shl 8; // ein wenig trciki, GradientFill erwartet als farbwert ein word // wobei das farbbyte an erster stelle stehen muss. // ich verzichte hierbei gleich auf GetRValue() usw. von Windows. ;-) tv[0].Red := $0000 or BYTE(startColor) shl 8; tv[0].Green := $0000 or BYTE(startColor shr 8) shl 8; tv[0].Blue := $0000 or BYTE(startColor shr 16) shl 8; tv[0].Alpha := $0000 or BYTE(startColor shr 24) shl 8; tv[1].Red := $0000 or BYTE(endColor) shl 8; tv[1].Green := $0000 or BYTE(endColor shr 8) shl 8; tv[1].Blue := $0000 or BYTE(endColor shr 16) shl 8; tv[1].Alpha := $0000 or BYTE(endColor shr 24) shl 8; Result := _GradientFill(DC, @tv, 2, @gr, 1, FillMode) <> 0; end else Result := FALSE; // ------------------------------------------------------------------------- // sollte global aufgerufen werden zB. in FormDestroy if hLib <> 0 then FreeLibrary(hLib); // ------------------------------------------------------------------------- end;
Delphi-Quellcode:
begin
//... r := FormX.Clientrect; if @wGradientFill <> nil then wGradientFill(FormX.Canvas.Handle, r, clRed, clGreen, GRADIENT_FILL_RECT_H) else FormX.Canvas.FillRect(r); Ich wusste doch das wir das in DP schon mal als Thema hatten. :gruebel: |
Re: Windows.GradientFill
Hier mal noch ein Beispiel mit drei Farben:
Delphi-Quellcode:
unit Unit1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 = class(TForm) procedure FormPaint(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.dfm} function GradientFill(DC: HDC; pTriVertex: Pointer; dwNumVertex: DWORD; pMesh: Pointer; dwNumMesh, dwMode: DWORD): BOOL; stdcall; external 'msimg32.dll' name 'GradientFill'; type TFillMode = (fmHorizontal = GRADIENT_FILL_RECT_H, fmVertiktal = GRADIENT_FILL_RECT_V); function wGradientFill(DC: HDC; fillRect: TRect; Col: array of COLORREF; FillMode: TFillMode): Bool; type _TTRIVERTEX = packed record X, Y: DWORD; Red, Green, Blue, Alpha: Word; end; var tv: array [0..3] of _TTRIVERTEX; gr: array [0..1] of GRADIENT_RECT; begin if length(col) = 3 then begin // fillmode direction gr[0].UpperLeft := 0; gr[0].LowerRight := 1; gr[1].UpperLeft := 2; gr[1].LowerRight := 3; // eckpunkte festlegen tv[0].x := fillRect.Left; tv[0].y := fillRect.Top; tv[1].x := fillRect.Right; tv[1].y := fillRect.Bottom div 2; tv[2].x := fillRect.Left; tv[2].y := fillRect.Bottom div 2; tv[3].x := fillRect.Right; tv[3].y := fillRect.Bottom; // ------------------------------------------------------------------------- // -> $0000 or BYTE(startColor shr 8) shl 8; // ein wenig trckiki, GradientFill erwartet als farbwert ein word // wobei das farbbyte an erster stelle stehen muss. // ich verzichte hierbei gleich mal auf GetRValue() usw. von Windows. ;-) tv[0].Red := BYTE(col[0]) shl 8; tv[0].Green := BYTE(col[0] shr 8) shl 8; tv[0].Blue := BYTE(col[0] shr 16) shl 8; tv[0].Alpha := BYTE(col[0] shr 24) shl 8; tv[1].Red := BYTE(col[1]) shl 8; tv[1].Green := BYTE(col[1] shr 8) shl 8; tv[1].Blue := BYTE(col[1] shr 16) shl 8; tv[1].Alpha := BYTE(col[1] shr 24) shl 8; tv[2].Red := BYTE(col[1]) shl 8; tv[2].Green := BYTE(col[1] shr 8) shl 8; tv[2].Blue := BYTE(col[1] shr 16) shl 8; tv[2].Alpha := BYTE(col[1] shr 24) shl 8; tv[3].Red := BYTE(col[2]) shl 8; tv[3].Green := BYTE(col[2] shr 8) shl 8; tv[3].Blue := BYTE(col[2] shr 16) shl 8; tv[3].Alpha := BYTE(col[2] shr 24) shl 8; Result := GradientFill(DC, @tv, length(tv), @gr, length(gr), DWORD(FillMode)); end else begin Application.MessageBox('Anzahl der Farben stimmt nicht.', 'wGradientFill:', MB_OK); Result := False; end; end; procedure TForm1.FormPaint(Sender: TObject); begin wGradientFill(Canvas.Handle, ClientRect, [clNavy, clLime, clYellow], fmVertiktal); end; end. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:03 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz