Link to home
Start Free TrialLog in
Avatar of Cédric MARCOUX
Cédric MARCOUXFlag for Belgium

asked on

Delphi: grab window content that is hidden or minimized

Hi all!
I currently try to capture content of a specific Window that does not have focus.
This is a direct3d application

Currently working but when capturing this window, if another is on the front, i have this fronted window on my screenshot (that normal)

But I want to be able to capture a screenshot of this window even if another is on the front and get exact image capture of this window.

Any idea?

Currently I use this code:


procedure TFRM_Main.Grab(bm: TBitMap; gt : GrabType);
var
  h: THandle;
  hdcSrc : THandle;
  var WoWHandle : THandle; // handle global de wow
classname: array[0..255] of char; // class du handle de wow
begin
  case(gt) of
    GTWINDOW : h := GetForeGroundWindow;
    GTSCREEN : h := GetDesktopWindow;
  else h := 0;
  end;
  try
    if h <> 0 then
    begin
      WoWHandle := FindWindow(nil,'My Direct3D App');
      GetClassName(WoWHandle,ClassName,SizeOf(ClassName));
      h := FindWindow(classname,nil);
      hdcSrc := GetWindowDC(h);
      GetWindowRect(h, SourceRect);
      bm.PixelFormat:=pf4bit;
      bm.Width  := SourceRect.Right - SourceRect.Left;
      bm.Height := SourceRect.Bottom - SourceRect.Top;
      DestRect := Rect(0, 0,
            SourceRect.Right - SourceRect.Left,
            SourceRect.Bottom - SourceRect.Top);
      StretchBlt(bm.Canvas.Handle, 0, 0, bm.Width,
            bm.Height, hdcSrc, 0, 0,bm.Width,bm.Height,
            SRCCOPY);
      end;
  finally
    ReleaseDC(0, hdcSrc);
  end;
end;

Open in new window

Avatar of CodedK
CodedK
Flag of Greece image

Hi.

Can you try :
SetFocus(h); after FindWindow ?
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
If this doesnt work then try :
...
  if (GetForegroundWindow <> h) then
  begin
   SetWindowPos(h, HWND_TOPMOST, 0,0,0,0,SWP_NOACTIVATE  or SWP_NOMOVE or SWP_NOSIZE);
  end;
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Avatar of Cédric MARCOUX

ASKER

I don't want to get back focus, I want to let the appz hidden or minimised...
But will try your peice of code, thx
Setfocus works even if its minimized or hidden !
SetFocus(h);

give error "Too many actual parameters"


Sorry for this.
I am at work and i can test this right.
Try : SetForegroundWindow(h);
work if window is on the front
White capture if minimised or on another virtual desktop
I'm reading an article in CodeProjects.
It says that there is no problem to capture a hidden OR partially hidden window.
The problem appears when its minimized !
Read this :
http://www.codeproject.com/useritems/CapturingMinimizedWindow.asp
It explains in detail the steps you should take.

Basically the trick is to put in front one way or another and then back to the previous state....

seems tricky but very loud to do.
Keep in mind that i want capture direct3d screen, perhaps possible do to it thrue a directx api???
Hi Cmarcx.
DirectX is fast. But its purpose is to draw graphics, not to read.
ASKER CERTIFIED SOLUTION
Avatar of wd123
wd123
Flag of Belarus image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you, this should help me finish my code, I have found several code using this method, i'em pretty sure that I will found solution using this way.