1- // **************************************************************************************************
1+ // **************************************************************************************************
22//
33// Unit uCustomImageDrawHook
44// unit for the WMI Delphi Code Creator
1515// The Original Code is uCustomImageDrawHook.pas.
1616//
1717// The Initial Developer of the Original Code is Rodrigo Ruz V.
18- // Portions created by Rodrigo Ruz V. are Copyright (C) 2011-2015 Rodrigo Ruz V.
18+ // Portions created by Rodrigo Ruz V. are Copyright (C) 2011-2019 Rodrigo Ruz V.
1919// All Rights Reserved.
2020//
21- // **************************************************************************************************
22-
23-
21+ // **************************************************************************************************
2422
2523unit uCustomImageDrawHook;
2624
@@ -43,15 +41,15 @@ implementation
4341 PXRedirCode = ^TXRedirCode;
4442
4543 TXRedirCode = packed record
46- Jump: byte;
44+ Jump: byte;
4745 Offset: TJumpOfs;
4846 end ;
4947
5048 PAbsoluteIndirectJmp = ^TAbsoluteIndirectJmp;
5149
5250 TAbsoluteIndirectJmp = packed record
5351 OpCode: word;
54- Addr: PPointer;
52+ Addr: PPointer;
5553 end ;
5654
5755 TCustomImageListClass = class (TCustomImageList);
@@ -63,8 +61,7 @@ function GetActualAddr(Proc: Pointer): Pointer;
6361begin
6462 if Proc <> nil then
6563 begin
66- if (Win32Platform = VER_PLATFORM_WIN32_NT) and
67- (PAbsoluteIndirectJmp(Proc).OpCode = $25FF) then
64+ if (Win32Platform = VER_PLATFORM_WIN32_NT) and (PAbsoluteIndirectJmp(Proc).OpCode = $25FF) then
6865 Result := PAbsoluteIndirectJmp(Proc).Addr^
6966 else
7067 Result := Proc;
@@ -75,14 +72,14 @@ function GetActualAddr(Proc: Pointer): Pointer;
7572
7673procedure HookProc (Proc, Dest: Pointer; var BackupCode: TXRedirCode);
7774var
78- lpNumberOfBytesRead: SIZE_T;
75+ lpNumberOfBytesRead: SIZE_T;
7976 Code: TXRedirCode;
8077begin
8178 Proc := GetActualAddr(Proc);
8279 Assert(Proc <> nil );
8380 if ReadProcessMemory(GetCurrentProcess, Proc, @BackupCode, SizeOf(BackupCode), lpNumberOfBytesRead) then
8481 begin
85- Code.Jump := $E9;
82+ Code.Jump := $E9;
8683 Code.Offset := PAnsiChar(Dest) - PAnsiChar(Proc) - SizeOf(Code);
8784 WriteProcessMemory(GetCurrentProcess, Proc, @Code, SizeOf(Code), lpNumberOfBytesRead);
8885 end ;
@@ -101,7 +98,7 @@ procedure UnhookProc(Proc: Pointer; var BackupCode: TXRedirCode);
10198 end ;
10299end ;
103100
104- procedure DoDrawGrayImage (hdcDst: HDC; himl: HIMAGELIST; ImageIndex, X, Y: Integer );
101+ procedure DoDrawGrayImage (hdcDst: HDC; himl: HIMAGELIST; ImageIndex, X, Y: integer );
105102var
106103 pimldp: TImageListDrawParams;
107104begin
@@ -111,13 +108,11 @@ procedure DoDrawGrayImage(hdcDst: HDC; himl: HIMAGELIST; ImageIndex, X, Y: Integ
111108 pimldp.hdcDst := hdcDst;
112109 pimldp.himl := himl;
113110 pimldp.i := ImageIndex;
114- pimldp.x := X;
115- pimldp.y := Y;
111+ pimldp.X := X;
112+ pimldp.Y := Y;
116113 ImageList_DrawIndirect(@pimldp);
117114end ;
118115
119-
120-
121116function GetRGBColor (Value : TColor): DWORD;
122117begin
123118 Result := ColorToRGB(Value );
@@ -129,19 +124,17 @@ function GetRGBColor(Value: TColor): DWORD;
129124 end ;
130125end ;
131126
132- procedure New_Draw (Self: TObject; Index: integer; Canvas: TCanvas;
133- X, Y: integer; Style: cardinal; Enabled: boolean);
127+ procedure New_Draw (Self: TObject; Index: integer; Canvas: TCanvas; X, Y: integer; Style: cardinal; Enabled: boolean);
134128var
135- LImageList : TCustomImageList;
129+ LImageList: TCustomImageList;
136130begin
137- LImageList:= TCustomImageListClass(Self);
131+ LImageList := TCustomImageListClass(Self);
138132 with TCustomImageListClass(Self) do
139133 begin
140134 if not HandleAllocated then
141135 Exit;
142136 if Enabled then
143- ImageList_DrawEx(Handle, Index, Canvas.Handle, X, Y, 0 , 0 ,
144- GetRGBColor(BkColor), GetRGBColor(BlendColor), Style)
137+ ImageList_DrawEx(Handle, Index, Canvas.Handle, X, Y, 0 , 0 , GetRGBColor(BkColor), GetRGBColor(BlendColor), Style)
145138 else
146139 DoDrawGrayImage(Canvas.Handle, LImageList.Handle, Index, X, Y);
147140 end ;
@@ -157,10 +150,12 @@ procedure UnHookDraw;
157150 UnhookProc(@TCustomImageListClass.DoDraw, DoDrawBackup);
158151end ;
159152
160-
161153initialization
162- HookDraw;
154+
155+ HookDraw;
163156
164157finalization
165- UnHookDraw;
158+
159+ UnHookDraw;
160+
166161end .
0 commit comments