unit uGrid;
interface
uses Windows, Classes, Messages, SysUtils, uGlobal, uGDIUnit, uSkin, uTrackBar;
type
ISkinGrid =
interface
['
{89A97429-5E4B-43B6-87D8-381DD4E8CF21}']
function GetHandle: hWnd;
property Handle: hWnd
read GetHandle;
end;
TSkinGrid =
class(TInterfacedObject, ISkinGrid)
private
FHGrid: HWND;
FWidth: Integer;
FHeight: Integer;
Img: cardinal;
dwStyle: DWORD;
IsInitialized: BOOL;
FOffsetX: Integer;
FOffsetY: Integer;
function GetOffsetY: Integer;
function GetOffsetX: Integer;
function GetHandle: hWnd;
procedure DrawGrid(WinHandle: HWND);
public
property Handle: HWND
Read FhGrid;
property Width: Integer
Read FWidth;
property Height: Integer
Read FHeight;
property OffsetX: Integer
read GetOffsetX
write FOffsetX;
property OffsetY: Integer
read GetOffsetY
write FOffsetY;
constructor Create(hOwner: HWND; FullpathImageName:
string;
x, y, xW, yH, OffsX, OffsY, ButID: Integer);
destructor Destroy;
override;
end;
function GridProc(WinHandle: HWND; Msg: UINT; wP: WParam; lP: LParam): LRESULT;
stdcall;
var
SkinGrid : TSkinGrid;
implementation
constructor TSkinGrid.Create(hOwner: HWND; FullpathImageName:
string;
x, y, xW, yH, OffsX, OffsY, ButID: integer);
var
wc: TWndClassEx;
zClass: PAnsiChar;
begin
inherited Create;
with SkinEngine
do
begin
zClass := SKGRID;
wc.cbSize := SIZEOF(wc);
IsInitialized := GetClassInfoEx(skInstance, zClass, wc);
if IsInitialized = False
then
begin
wc.cbSize := SIZEOF(wc);
wc.style := CS_HREDRAW
or CS_VREDRAW
or CS_DBLCLKS;
{ or CS_PARENTDC;}
wc.lpfnWndProc := @GridProc;
wc.cbClsExtra := 0;
wc.cbWndExtra := EXTEND_EXTRA * 4;
wc.hInstance := skInstance;
wc.hIcon := 0;
wc.hCursor := 0;
wc.hbrBackground := 0;
wc.lpszMenuName :=
nil;
wc.lpszClassName := zClass;
wc.hIconSm := wc.hIcon;
if RegisterClassEx(wc) <> 0
then
IsInitialized := True;
end;
if IsInitialized = True
then
begin
dwStyle := WS_CHILD
or WS_VISIBLE
or WS_TABSTOP;
// Erstelle das GDIPLUS image von Datei
Img := AddResource(PAnsiChar(FullpathImageName));
if Img <> 0
then
begin
// Hole die Thumb GDIPLUS image größe
GetImageSize(Img, imgW, imgH);
FWidth := xW;
FHeight := yH;
FOffsetX := OffsX;
FOffsetY := OffsY;
FHGrid := CreateWindowEx(WS_EX_TRANSPARENT,
SKGRID,
nil, dwStyle, x, y, xW, yH,
hOwner, ButID, skInstance,
nil);
if FHGrid <> 0
then
begin
// Speichere das Image Handle in die Property
SetImageProperty(FHGrid, PROP_STYLE, BS_GROUPBOX);
SetImageProperty(FHGrid, GRID_IMAGE, Img);
SkinGrid := @FHGrid;
SkinGrid.Img := Img;
SkinGrid.dwStyle := dwStyle;
SkinGrid.FWidth := xW;
SkinGrid.FHeight := yH;
SkinGrid.FOffsetX := OffsX;
SkinGrid.FOffsetY := OffsY;
end else
// Image löschen wenn Fehler
DeleteResource(Img);
end;
end;
end;
end;
function GridProc(WinHandle: HWND; Msg: UINT; wP: WParam; lP: LParam): LRESULT;
var
ps: TPaintstruct;
begin
with SkinEngine
do
begin
case Msg
of
WM_ERASEBKGND:
begin
Result := 1;
exit;
end;
WM_DESTROY:
begin
PostQuitMessage(0);
Result := 0;
Exit;
end;
WM_PAINT:
begin
BeginPaint(WinHandle, ps);
SkinGrid.DrawGrid(WinHandle);
EndPaint(WinHandle, ps);
Result := 0;
Exit;
end;
end;
Result := DefWindowProc(WinHandle, Msg, wP, lP);
end;
// end SkinEngine
end;
destructor TSkinGrid.Destroy;
begin
inherited Destroy;
end;
procedure TSkinGrid.DrawGrid(WinHandle: HWND);
var
graphics: Cardinal;
pen: Integer;
IntI: Integer;
DC: HDC;
rc: TRect;
begin
with SkinEngine
do
begin
// Initialisierern
DC := GetDC(WinHandle);
GetClientRect(WinHandle, rc);
GdipCreateFromHDC(
DC, graphics);
GdipCreatePen1(ColorARGB(255,
RGB(0, 0, 0)), 1, UnitPixel, pen);
for IntI := 0
to rc.Right
do
begin
if IntI
mod FOffsetX <> 0
then continue;
GdipDrawLineI(graphics, pen, IntI, 0, IntI, rc.Bottom);
end;
for IntI := 0
to rc.Bottom
do
begin
if IntI
mod FOffsetY <> 0
then continue;
GdipDrawLineI(graphics, pen, 0, IntI, rc.Right, IntI);
end;
// Freigeben
GdipDeletePen(pen);
GdipDeleteGraphics(graphics);
ReleaseDC(WinHandle,
DC);
end;
end;
function TSkinGrid.GetHandle: hWnd;
begin
result := FhGrid;
end;
function TSkinGrid.GetOffsetX: Integer;
begin
Result := FOffsetX;
end;
function TSkinGrid.GetOffsetY: Integer;
begin
Result := FOffsetY;
end;
end.