?
Solved

Delphi: grab window content that is hidden or minimized

Posted on 2007-11-23
11
Medium Priority
?
1,431 Views
Last Modified: 2010-04-21
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

0
Comment
Question by:Cédric MARCOUX
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
11 Comments
 
LVL 16

Expert Comment

by:CodedK
ID: 20338726
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;
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
0
 
LVL 1

Author Comment

by:Cédric MARCOUX
ID: 20338756
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
0
 
LVL 16

Expert Comment

by:CodedK
ID: 20338759
Setfocus works even if its minimized or hidden !
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Cédric MARCOUX
ID: 20338778
SetFocus(h);

give error "Too many actual parameters"


0
 
LVL 16

Expert Comment

by:CodedK
ID: 20338794
Sorry for this.
I am at work and i can test this right.
Try : SetForegroundWindow(h);
0
 
LVL 1

Author Comment

by:Cédric MARCOUX
ID: 20338866
work if window is on the front
White capture if minimised or on another virtual desktop
0
 
LVL 16

Expert Comment

by:CodedK
ID: 20338933
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....

0
 
LVL 1

Author Comment

by:Cédric MARCOUX
ID: 20339265
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???
0
 
LVL 16

Expert Comment

by:CodedK
ID: 20345050
Hi Cmarcx.
DirectX is fast. But its purpose is to draw graphics, not to read.
0
 
LVL 5

Accepted Solution

by:
wd123 earned 1500 total points
ID: 20547851
try something from it:
1. WM_PRINT/ WM_PRINTCLIENT (http://www.fengyuan.com/article/wmprint.html)
2. PrintWindow
0
 
LVL 1

Author Closing Comment

by:Cédric MARCOUX
ID: 31410659
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.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question