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
Solved

another windows capture quesion

Posted on 2007-12-05
9
463 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
  • 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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