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
|
type
// Pour accéder au champs privé FResource
TGraphicsObject2 = class(TPersistent)
private
FOnChange: TNotifyEvent;
FResource: PResource;
end;
procedure GetControlFontInfo(hWnd: HWND; AFont: TFont);
var
OFF_FONT, OFF_COLOR, OFF_Resource: integer;
ProcessId: DWORD;
hProc: THandle;
pWinControl, pFont, pRes: Pointer;
Color: TColor;
AtomName: string;
Atom: word;
ResData: TResource;
procedure ReadMem(pSrc: Pointer; Offset, Size: integer; var Dest);
var
BytesRead: DWORD;
begin
ReadProcessMemory(hProc, Pointer(DWORD(pSrc) + Offset), @Dest, Size, BytesRead)
end;
begin
if GetWindowThreadProcessId(hWnd, @ProcessId) = 0 then
Exit;
AtomName := Format('Delphi%.8X', [ProcessId]);
Atom := GlobalFindAtom(PChar(AtomName));
if Atom = 0 then
Exit;
pWinControl := Pointer(GetProp(hWnd, MakeIntAtom(Atom)));
if pWinControl = nil then
Exit;
OFF_FONT := Integer(@TEdit(0).Font);
OFF_COLOR:= Integer(@TFont(0).Color);
OFF_Resource:= Integer(@TGraphicsObject2(0).FResource);
hProc := OpenProcess(PROCESS_VM_READ, False, ProcessId);
if hProc = 0 then
Exit;
try
ReadMem(pWinControl, OFF_FONT, SizeOf(Pointer), pFont);
ReadMem(pFont, OFF_COLOR, SizeOf(TColor), Color);
ReadMem(pFont, OFF_Resource, SizeOf(Pointer), pRes);
ReadMem(pRes, 0, SizeOf(TResource), ResData);
AFont.Color := Color;
AFont.Name := ResData.Font.Name;
AFont.Height:= ResData.Font.Height;// définit aussi le size
AFont.Style := ResData.Font.Style;
finally
CloseHandle(hProc);
end;
end; |
Partager