首先要获得设备环境的句柄,可以通过GetDC函数来获得,对于这个函数,MSDN上是这样说明的

The GetDC function retrieves a handle to a device context (DC) for the client area of a specified window or for the entire screen. You can use the returned handle in subsequent GDI functions to draw in the DC. The device context is an opaque data structure, whose values are used internally by GDI.
The GetDCEx function is an extension to GetDC, which gives an application more control over how and whether clipping occurs in the client area.
Syntax

HDC GetDC(
__in HWND hWnd
);
Parameters
hWnd [in]
A handle to the window whose DC is to be retrieved. If this value is NULL, GetDC retrieves the DC for the entire screen.
Return value
If the function succeeds, the return value is a handle to the DC for the specified window's client area.
If the function fails, the return value is NULL.

1.申明一全变量存储GetDC方法得到的句柄,HDC类型
?
1
2
var
dc:HDC;
2.在适当时候调用GetDC,將得到的句柄赋值给变量dc,并將得到的句柄赋值给Canvas的句柄(fullCanvas是变量)

1 dc:=GetDC(0);
2 fullCanvas:=TCanvas.Create;
3 fullCanvas.Handle:=dc;
3.然后就是对fullCanvas进行操作,这里也要用到CopyRect函数

procedure CopyRect(const Dest: TRect; Canvas: TCanvas; const Source: TRect);

Copies part of an image from another canvas into the canvas.Use CopyRect to transfer part of the image on another canvas to the image of the TCanvas object.

Dest specifies the rectangle on the canvas where the source image will be copied. The Canvas parameter specifies the canvas with the source image.

Source specifies a rectangle bounding the portion of the source canvas that will be copied.The portion of the source canvas is copied using the mode specified by CopyMode.

一句话就是,将Canvas中的Source大小的区域拷贝到目标canvas中的Dest區域中,如果这二个面积不相等,会有缩放效果,如果不想有此效果,这二个区域的长宽相等

复制代码
1 if SavePictureDialog1.Execute then
2 begin
3 bm:=TBitmap.Create;
4 try
5 bm.Width:=abs(x2-x1);
6 bm.Height:=abs(y2-y1);
7 bm.Canvas.CopyRect(Rect(0,0,bm.Width,bm.Height),fullCanvas,Rect(x1,y1,x2,y2));
8 bm.SaveToFile(SavePictureDialog1.FileName+'.bmp');
9 finally
10 bm.Free;
11 end;
复制代码
其中bm.width:=ABS(x2-x1),bm.heigth:=ABS(y2-y1),如果要全屏截图,则将二个RECT都设置为Rect(0,0,Screen.Width,Screen.heigth)

程序运行如下

要实现有背景的黑层行是这样操作的

(1).设置窗体 AlphaBlend为True,AlphaBlendVaue为150,BorderStyle:=bsNone;

(2).在窗体创建时写如下语句

1 SetWindowPos(0,HWND_TOP,0,0,Screen.Width,Screen.Height,SWP_DRAWFRAME);
2 ClientHeight:=Screen.Height;
3 ClientWidth:=Screen.Width;

最新文章

  1. [Sass]局部变量和全局变量
  2. 面向对象(五)super
  3. codeforces Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)// 二分的题目硬生生想出来ON的算法
  4. \boot 空间不足解决方法
  5. C#编程总结 dynamic(转)
  6. NAT123 解决80端口被封的问题
  7. 【shell】变量的配置文件
  8. java面试资料总结
  9. CentOS安装中文输入法:ibus
  10. poj3694Network(tarjan+lca)
  11. MYSQL 存储过程1、SQL存储过程的基础知识
  12. Cordova环境搭建与hello word
  13. centos rabbitmq 安装
  14. Python beautifulsoup 选择器 select 选择<meta/>等不需要成对结尾标签未写‘/’
  15. Delphi 的内存操作函数(2): 给数组指针分配内存
  16. [转帖]SQL Server 索引中include的魅力(具有包含性列的索引)
  17. 实际用户ID和有效用户ID (二)
  18. Android源码博客目录
  19. [Cxf] spring-cxf 配置
  20. C/C++——库函数strcpy和strdup比较

热门文章

  1. 一.Python特点
  2. jq容易混淆点
  3. 从零开始搭建系统1.7——FTP安装及配置
  4. JS自运行函数的写法和MVVM框架数据驱动的底层逻辑
  5. dubbo入门之服务消费
  6. 6361. 【NOIP2019模拟2019.9.18】鲳数
  7. ASCII 对应表
  8. 为什么要使用动态链接库(DLL)
  9. bzoj1003题解
  10. flume注意的事项