Question

how to capture desktop image ?

Asked by: fifthelement80

Hi,
I am going to take a screenshot of my desktop , I simply have a Timage on my form which I copy the desktop area to it using the attached code , it works fine , but vista side bar is not captured in the image ! and desktop behind it is captured , look at the pictures , one is captured by snagit , other one which doesnt have side bar is captured by my program , how can I solve this problem ?
Regards

hdcSrc := GetWindowDC(h);
StretchBlt(bm.Canvas.Handle, 0, 0, bm.Width,bm.Height,hdcSrc,lft,0,wdh,hgh,SRCCOPY);
ReleaseDC(0, hdcSrc);
                                  
1:
2:
3:

Select allOpen in new window

  • 12.jpg
    • 187 KB

    captured by my program

  • 11.jpg
    • 200 KB

    captured by snagit

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-02-24 at 08:27:41ID23188519
Tags

delphi capture screen image

Topics

Graphics and Delphi Programming

,

Delphi Programming

Participating Experts
6
Points
0
Comments
21

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Capture picture
    How do you capture an image of the screen on the computer and save it as a jpg file?
  2. Remote Screen Capture: Server's TImage to Client's TI…
    Hi, I'm sharing my internet account with my neighbour and I don't want to get in trouble because of his actions so I decided to make a program that captures his screen when I want (he agreed). I know how to capture it and store it into a TImage, but how can I send it? Usual...
  3. TImage problem
    TImage problem How to put components to TImage and save them as picture file, if components are hided (on TForm) or visible:=false ? Thank You.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: alkisgPosted on 2008-02-24 at 13:11:05ID: 20971376

Just an idea:

SnagIt doesn't capture the desktop, it captures the entire screen, that's why it includes the sidebar.
(at least from what I read at http://www.techsmith.com/snagit/featureslist.asp)

To do the same thing from your program, you would minimize all windows except the sidebar and then capture the entire screen. I don't think users would like auto-minimizing windows! :)

So, you should
a) capture the desktop
b) capture the sidebar
c) overlay the two images at the correct position.

For (b) and (c) a starting point:
http://www.codeprof.com/dev-archive/206/296-1063-2065220.shtm

 

by: ciulyPosted on 2008-02-24 at 13:18:56ID: 20971425

well, it's only normal. you are copying the desktop but the sidebar is not drawn on the desktop. it's actually a window. so in order to catch everything, you will need to catch all windows bitmap in order to make out o full screenshot. but this means that you wil be catching all windows. (here is a sample code to capture one: http://delphi.about.com/od/adptips2006/qt/captureactive.htm)
basically, you will have to use enumwindows to find all active windows which are not minimized (and maybe whic hare on teh current desktop) and maybe even check if they are partly visible or not (in order to not capture windows that are not visible at all) and then you will have a complete capture of the screen.
but again, it will be capturing of the screen, not the desktop, sicne you already done that.

if you don't want to capture the whole screen, only desktop plus sidebar, you can check if you are on vista (http://www.delphi3000.com/articles/article_5145.asp) and if so, then find the sidebar and capture that (if it's visible).

 

by: fifthelement80Posted on 2008-02-24 at 13:24:33ID: 20971466

alkisg : my program captures the entire screen too , anything on screen , except sidebar of vista !
ciuly : my code captures all windows on desktop , if you look at the sent image , you can see a program is running and it is captured , my only issue is with vista side bar , I dont have any problems in XP. seems somehow this sidebar is different. may be I should use another method to capture screen.

 

by: Steven-FernandezPosted on 2008-02-24 at 13:35:54ID: 20971523

Try this app:

FRAPS:

Download from:

http://www.fraps.com/download.php

 

by: ciulyPosted on 2008-02-24 at 13:47:35ID: 20971572

well, I don't have vista to investigate so .. I'm bailing out on this one :)

 

by: alkisgPosted on 2008-02-24 at 13:52:20ID: 20971586

Sorry, I misunderstood.

MSDN has a sample program for screen/window capturing, called WinCap:
http://support.microsoft.com/kb/97193

I'd suggest you have a look at these two functions:

COPY.C: HBITMAP FAR CopyScreenToBitmap(LPRECT lpRect)
and the calling function,
WINCAP.C: void DoCapture(HWND hWnd, WORD wCommand)
maybe you'll find something you overlooked.

For example, in DoCapture, it waits for all windows to draw themselves before calling CopyScreenToBitmap:
             // Wait until everybody repaints themselves

             while (PeekMessage(&msg,NULL,0,0,PM_REMOVE) != 0) {
                    TranslateMessage(&msg);
                    DispatchMessage(&msg);
                    }

 

by: fifthelement80Posted on 2008-02-24 at 13:55:34ID: 20971608

@Steven-Fernandez : I dont need an app , I need a working code for delphi.
@alkisg : thx , I look into it and will tell you the result

 

by: Steven-FernandezPosted on 2008-02-24 at 23:32:04ID: 20973433

Understood. And I too as I don't have Vista have to bail out of this question. Good Luck.

 

by: diniludPosted on 2008-02-25 at 05:47:37ID: 20975106

 

by: diniludPosted on 2008-02-25 at 05:50:56ID: 20975133

procedure InitScreen;
var i,j:integer;
begin
  //get Desktop bitmap
  DesktopBitmap := TBitmap.Create;
  with DesktopBitmap do begin
    Width := Screen.Width;
    Height := Screen.Height;
  end;
  BitBlt(DesktopBitmap.Canvas.Handle,
         0,0,Screen.Width,Screen.Height,
         GetDC(GetDesktopWindow),0,0,SrcCopy);

  Shuffler.Image1.Picture.Bitmap := DesktopBitmap;

end;

 

by: fifthelement80Posted on 2008-02-25 at 06:14:06ID: 20975346

I am using almost the same code ! I just used StretchBlt , you have used BitBlt. anyway I will try it to see if it works.

 

by: fifthelement80Posted on 2008-02-25 at 08:05:20ID: 20976608

@dinilud : BitBlt produced the same result as StretchBlt , sidebar is not captured.

 

by: fifthelement80Posted on 2008-02-25 at 08:44:46ID: 20977003

@alkisg : Hi , I looked into WinCap , it suggest not to use BitBlt and use DibAPI which is included in package , I downloaded dibapi.dll and I tried to import and use the following function :

HBITMAP   FAR  CopyScreenToBitmap (LPRECT);

but no success , can you tell me how to import this function into delphi and call it ?

 

by: fifthelement80Posted on 2008-02-25 at 09:16:41ID: 20977256

 

by: alkisgPosted on 2008-02-25 at 10:03:05ID: 20977665

I don't have Delphi installed yet because I bought a new pc, so I'm not sure this is correct:
type
  CopyScreenToBimap: function(r: PRect): HBITMAP; stdcall; external 'dibapi.dll';

Be sure to include "uses Windows". If PRect (long pointer to rectangle) is undeclared, you can either do (var r: Rect) or (r: LPRECT).

But I think it will be easier if you just convert the CopyScreenToBitmap source code to Pascal. If you don't find a solution for several days :-) (I hope that you do) I'll have Delphi installed and I'll be able to convert it for you then.

 

by: fifthelement80Posted on 2008-02-25 at 11:01:27ID: 20978200

@alkisg : I tried it , it didnt work :(

 

by: fifthelement80Posted on 2008-02-25 at 11:04:41ID: 20978224

I solved the problem myself , in fact there is a very simple method to capture screen. we can simply use windows internal capture screen API , if we press print screen key , windows copies a screenshot of the screen to the clipboard , then we can use the image from clipboard.
I post the code so it may help someone who has the same problem.

procedure PostKeyEx32(key: Word; const shift: TShiftState; specialkey: Boolean) ;
{
Parameters :
* key : virtual keycode of the key to send. For printable keys this is simply the ANSI code (Ord(character)) .
* shift : state of the modifier keys. This is a set, so you can set several of these keys (shift, control, alt, mouse buttons) in tandem. The TShiftState type is declared in the Classes Unit.
* specialkey: normally this should be False. Set it to True to specify a key on the numeric keypad, for example.
 
Description:
Uses keybd_event to manufacture a series of key events matching the passed parameters.
The events go to the control with focus. Note that for characters key is always the upper-case version of the character. Sending without any modifier keys will result in a lower-case character, sending it with [ ssShift ] will result in an upper-case character!
}
type
   TShiftKeyInfo = record
     shift: Byte ;
     vkey: Byte ;
   end;
   ByteSet = set of 0..7 ;
const
   shiftkeys: array [1..3] of TShiftKeyInfo =
     ((shift: Ord(ssCtrl) ; vkey: VK_CONTROL),
     (shift: Ord(ssShift) ; vkey: VK_SHIFT),
     (shift: Ord(ssAlt) ; vkey: VK_MENU)) ;
var
   flag: DWORD;
   bShift: ByteSet absolute shift;
   j: Integer;
begin
   for j := 1 to 3 do
   begin
     if shiftkeys[j].shift in bShift then
       keybd_event(shiftkeys[j].vkey, MapVirtualKey(shiftkeys[j].vkey, 0), 0, 0) ;
   end;
   if specialkey then
     flag := KEYEVENTF_EXTENDEDKEY
   else
     flag := 0;
 
   keybd_event(key, MapvirtualKey(key, 0), flag, 0) ;
   flag := flag or KEYEVENTF_KEYUP;
   keybd_event(key, MapvirtualKey(key, 0), flag, 0) ;
 
   for j := 3 downto 1 do
   begin
     if shiftkeys[j].shift in bShift then
       keybd_event(shiftkeys[j].vkey, MapVirtualKey(shiftkeys[j].vkey, 0), KEYEVENTF_KEYUP, 0) ;
   end;
end;
 
PostKeyEx32(VK_SNAPSHOT, [], False) ;
application.ProcessMessages;
if Clipboard.HasFormat(CF_BITMAP) then bm.Assign(Clipboard);
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:

Select allOpen in new window

 

by: alkisgPosted on 2008-02-25 at 11:40:46ID: 20978518

That was my first thought, but then I thought it would be unacceptable because it messes the clipboard! :-)
Anyway, I'm glad you solved it!

 

by: Vee_ModPosted on 2008-02-29 at 16:31:41ID: 21018939

Closed, 500 points refunded.
Vee_Mod
Community Support Moderator

 

by: etkingPosted on 2009-10-15 at 19:42:44ID: 25586673

If u use windows default printscreen button, then the app might only workable in specific OS. Try use BitBlt with CAPTUREBLT flags together with SRCCOPY.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...