Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

another windows capture quesion

Posted on 2007-12-05
9
Medium Priority
?
468 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 900 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
Technology Partners: 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 600 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

715 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