ExtTextOut plus DrawText and DeviceContext

c++ / delphi package - dll injection and api hooking

ExtTextOut plus DrawText and DeviceContext

Postby Claes » Mon Jul 19, 2004 4:25 pm

I'm hooking ExtTextOut and DrawText. These API's work on a DeviceContext (DC). My question is: For filter purposes, I'd like to know WHICH window (hWnd) is drawing on the DC. I tried using WindowFromDC, but this seems to work solely on what is called a Form in Delphi - it doesn't work on child windows like e.g., a Panel.

Any suggestions would be much appreciated! ;)
Claes
 
Posts: 52
Joined: Thu Apr 22, 2004 10:52 pm
Location: Denmark

Postby Claes » Mon Jul 19, 2004 11:16 pm

Actually, it seems to work on DrawText, but before/after ExtTextOut is called, the handle returned from WindowFromDC is always zero! Could this be a Win2K bug?
Claes
 
Posts: 52
Joined: Thu Apr 22, 2004 10:52 pm
Location: Denmark

Postby madshi » Tue Jul 20, 2004 7:32 am

Maybe the one calling ExtTextOut is using double buffering? That is writing the text into a bitmap and then painting the bitmap on the window? This technique is often used to reduce flickering. The DC is a bitmap DC then, so WindowFromDC can't work.
madshi
Site Admin
 
Posts: 9790
Joined: Sun Mar 21, 2004 5:25 pm

Postby Claes » Tue Jul 20, 2004 9:29 am

It's a good guess! But the window in question is a Delphi TStringGrid component. I checked the source, and it doesn't use any bitmaps. To draw the text in the grid, he calls TextRect of TCanvas, which is implemented as follows:

Code: Select all
procedure TCanvas.TextRect(Rect: TRect; X, Y: Integer; const Text: string);
var
  Options: Longint;
begin
  Changing;
  RequiredState([csHandleValid, csFontValid, csBrushValid]);
  Options := ETO_CLIPPED or FTextFlags;
  if Brush.Style <> bsClear then
    Options := Options or ETO_OPAQUE;
  if ((FTextFlags and ETO_RTLREADING) <> 0) and
     (CanvasOrientation = coRightToLeft) then Inc(X, TextWidth(Text) + 1);
  Windows.ExtTextOut(FHandle, X, Y, Options, @Rect, PChar(Text),
    Length(Text), nil);
  Changed;
end;

So I'm still puzzled! :sceptic:
Claes
 
Posts: 52
Joined: Thu Apr 22, 2004 10:52 pm
Location: Denmark

Postby madshi » Tue Jul 20, 2004 10:17 am

Well, TCanvas can be a window canvas or a bitmap canvas or a printer canvas. Where does this specific canvas come from?
madshi
Site Admin
 
Posts: 9790
Joined: Sun Mar 21, 2004 5:25 pm


Return to madCodeHook

Who is online

Users browsing this forum: No registered users and 4 guests

cron