Solved

another windows capture quesion

Posted on 2007-12-05
9
465 Views
Last Modified: 2010-04-04
hi experts,

need an function to get a bitmap of an desktop window from my delphi application.
the problem is somtimes the windows is overlapt or a part of. and i still need the picture out of that.

i create a windows preview like in vista.
0
Comment
Question by:dMa
[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
  • 4
  • 3
  • 2
9 Comments
 
LVL 16

Expert Comment

by:CodedK
ID: 20411044
Hi

In general 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
This article says how you can grab a window that is minimized.

Now about your problem the trick is to bring it in front and then put it back as it was...


use
SetWindowPos(WndHandle,HWND_TOPMOST,0,0,500,200,SWP_SHOWWINDOW or SWP_NOSIZE);
OR
SetForegroundWindow(handle);
 
 
then use the grab function
 
Hope this helps.

Open in new window

0
 
LVL 16

Accepted Solution

by:
CodedK earned 300 total points
ID: 20411063
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 20411540
As CodedK mentions, bring your window to the forefront and do the form copy. Here si one way to bring the application to the forefront or bring it active if hidden or minimized...

var
  WindowHandle : HWND;

function EnumWindowsProc(WHandle: HWND; lParam: LPARAM): BOOL; export; stdcall;
const
  MAX_WINDOW_NAME_LEN = 80;
var
  WindowName : array[0..MAX_WINDOW_NAME_LEN] of char;
begin
  {Can't test GetWindowText's return value since some windows don't have a title}
  GetWindowText(WHandle,WindowName,MAX_WINDOW_NAME_LEN);
  Result := (StrLIComp(WindowName,PChar(lParam), StrLen(PChar(lParam))) <> 0);
  If (not Result) then WindowHandle:=WHandle;
end;

function AppActivate(WindowName : PChar) : boolean;
begin
  try
    Result:=true;
    WindowHandle:=FindWindow(nil,WindowName);
    If (WindowHandle=0) then EnumWindows(@EnumWindowsProc,Integer(PChar(WindowName)));
    If (WindowHandle<>0) then begin
      SendMessage(WindowHandle, WM_SYSCOMMAND, SC_HOTKEY, WindowHandle);
      SendMessage(WindowHandle, WM_SYSCOMMAND, SC_RESTORE, WindowHandle);
    end else Result:=false;
  except
    on Exception do Result:=false;
  end;
end;

end.

Use AppActivate('WindowName');

WindowName is the text in the caption or a portion of it.

Now take your window snapshot.

In rereading your question, are you wanting to make a bmp of the entire desktop? If so and you have a window overlapping another, that's how the snapshot will be. Exactly what you see on the desktop unless you move one of the overlapping windows. What you see is what you'll get... WYSIWYG!

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 18

Expert Comment

by:Johnjces
ID: 20411586
I am not certain if you now want to capture that window, so here is some code that simulates the capture screes, puts it in the clipboard then into a TImage.

Uses
  ClipBrd;

procedure CopyActiveWindow;
begin
  keybd_event(VK_SNAPSHOT, 1, 0, 0);
  Application.ProcessMessages;
  Image1.AutoSize := True;
  Image1.Picture.Bitmap.Assign(Clipboard);
end;

John
0
 
LVL 2

Author Comment

by:dMa
ID: 20411698
no sorry.... there is a problem.

to CodedK:
1. delphi do not support the printwindow command.

to Johnjces:
2. thats a bad hack just becouse of events thats are runnign in the time you bring the window to front
for example onactivate...

but ok i could live with that if
1. it's fast enougth so the user did't see it

2.(i cann live with it to ...)  i do not loos the focus for the user (for example i runn it every 2 secound and user trys to write somthing in word the same time :)  )


3. AND THE MOST IMPORTAND THINK is
show me a code thats brings me the window back to the same positions it was before, so hidden is not the problem but if it was just in background of some over windows.....


0
 
LVL 2

Author Comment

by:dMa
ID: 20411712
to CodedK:
1. delphi do not support the printwindow command.

i mean it do not support delphi forms
0
 
LVL 18

Assisted Solution

by:Johnjces
Johnjces earned 200 total points
ID: 20411889
dMa.

One simple way here would be to, after you take your picture, make the other window the active one using the Appactivate.

But in any event the user is going to see something happen. A flicker at least.

If this is your delphi application that you need an image of, you could do something like a Form.GetFormImage and capture its image.

John

0
 
LVL 16

Expert Comment

by:CodedK
ID: 20412480
I know delphi does not support this.
But i gave you the link to see the example exe file that brings up all the windows and captures them.
Test it while running your sensitive code to check if there is any issue like the one you fear with onactivate. You want even notice the windows...
I didnt give you a capture code coz i thought you are allready running yours.
0
 
LVL 16

Expert Comment

by:CodedK
ID: 20412516
I've tested the full source code posted in CodeProject.
The tricks mentioned there.. We can implement this easily in Delphi.
I dont thing you need to mess with the registry section because you didnt mentioned minimized windows...
Also duringthe test there was no flicker :) ... nothing.
Just test it.
0

Featured Post

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!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

734 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