ExtTextOut plus DrawText and DeviceContext

c++ / delphi package - dll injection and api hooking
Post Reply
Claes
Posts: 52
Joined: Thu Apr 22, 2004 10:52 pm
Location: Denmark

ExtTextOut plus DrawText and DeviceContext

Post by Claes »

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

Post by Claes »

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?
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

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.
Claes
Posts: 52
Joined: Thu Apr 22, 2004 10:52 pm
Location: Denmark

Post by Claes »

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:
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Well, TCanvas can be a window canvas or a bitmap canvas or a printer canvas. Where does this specific canvas come from?
Post Reply