Solved

Snapshot of desktop

Posted on 2000-04-25
2
301 Views
Last Modified: 2010-04-04
How can I make a snapshot of the desktop with Delphi?
0
Comment
Question by:dluedi
2 Comments
 
LVL 6

Expert Comment

by:DrDelphi
ID: 2748933
This is getting to be my favorite question! <g>

You could download my TScreenGrab component from www.drdelphi.com OR

procedure TForm1.Button1Click(Sender: TObject);
begin
grabdesktoprect(rect(0,0,Screen.width,Screen.height),'C:\windows\desktop\test.bmp');
end;

function TForm1.GrabDesktopRect(rect: Trect; Fname: string): Boolean;
var tempbmp:Tbitmap;
    tempcanvas:Tcanvas;
begin
    tempbmp:=TBitmap.create;
    with tempbmp do
    begin
      height:=rect.bottom-rect.top;
      width:=rect.right-rect.left;
    end;
    tempcanvas:=TCanvas.create;
    TempCanvas.handle:= GetWindowDc(GetDeskTopwindow);
    tempbmp.Canvas.CopyRect(rect,tempcanvas,rect);
    tempbmp.savetofile(fname);
    tempbmp.Free;
    TempCanvas.free;
end;

end.


Your choice.

Good luck!!

0
 
LVL 3

Accepted Solution

by:
f15iaf earned 50 total points
ID: 2749485
 An application can simulate a press of the PRINTSCREEN key in order to obtain a screen snapshot and save it to the Windows  clipboard. To do this, call  keybd_event  with the  bVk  parameter set to VK_SNAPSHOT, and the  bScan  parameter set to 0 for a  snapshot of the full screen or set  bScan  to 1 for a snapshot of the active window.  



keybd_event          
 
 The  keybd_event  function synthesizes a keystroke. The system can use such a synthesized keystroke to generate a  WM_KEYUP   or  WM_KEYDOWN  message. The keyboard driver's interrupt handler calls the  keybd_event  function.  
 
 VOID keybd_event(
 
      BYTE   bVk ,           // virtual-key code    
     BYTE   bScan ,           // hardware scan code    
     DWORD   dwFlags ,           // flags specifying various function options    
     DWORD   dwExtraInfo             // additional data associated with keystroke    
    );             
   
 
 Parameters
 
 bVk
 
 Specifies a virtual-key code. The code must be a value in the range 1 to 254.  
 
 bScan
 
 Specifies a hardware scan code for the key.  
 
 dwFlags
 
 A set of flag bits that specify various aspects of function operation. An application can use any combination of the following  predefined constant values to set the flags:  
 
  Value           Meaning    
 KEYEVENTF_EXTENDEDKEY           If specified, the scan code was preceded by a prefix byte having the  value 0xE0 (224).    
 KEYEVENTF_KEYUP           If specified, the key is being released. If not specified, the key is  being depressed.    
   
 
 dwExtraInfo
 
 Specifies an additional 32-bit value associated with the key stroke.  
 
   
 
 Return Values
 
 This function has no return value.  
 
 Remarks
 
 Although  keybd_event  passes an OEM-dependent hardware scan code to Windows, applications should not use the scan code.  Windows converts scan codes to virtual-key codes internally and clears the up/down bit in the scan code before passing it to  applications.  
  An application can simulate a press of the PRINTSCREEN key in order to obtain a screen snapshot and save it to the Windows  clipboard. To do this, call  keybd_event  with the  bVk  parameter set to VK_SNAPSHOT, and the  bScan  parameter set to 0 for a  snapshot of the full screen or set  bScan  to 1 for a snapshot of the active window.  
 
 See Also
 
 GetAsyncKeyState ,  GetKeyState ,  MapVirtualKey ,  SetKeyboardState  
 
 
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now