CopyScreenFrm.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. unit CopyScreenFrm;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, ExtCtrls, JPeg, AppEvnts, StdCtrls, Menus, ExtDlgs, StrUtils,
  6. IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP;
  7. type
  8. TScreenState = (msDefault,msDrag,msSelected);
  9. TDragState = (dsNone,
  10. dsLeftTop,
  11. dsTop,
  12. dsRightTop,
  13. dsRight,
  14. dsRightBottom,
  15. dsBottom,
  16. dsLeftBottom,
  17. dsLeft,
  18. dsClient);
  19. TCopyScreenForm = class(TForm)
  20. ImgScreen: TImage;
  21. PnlInfo: TPanel;
  22. LblRGB: TLabel;
  23. LblActionInfo: TLabel;
  24. LblCancelInfo: TLabel;
  25. ApplicationEvents1: TApplicationEvents;
  26. Label1: TLabel;
  27. SavePictureDialog: TSavePictureDialog;
  28. procedure FormDestroy(Sender: TObject);
  29. procedure FormShow(Sender: TObject);
  30. procedure FormCreate(Sender: TObject);
  31. procedure PnlInfoMouseMove(Sender: TObject; Shift: TShiftState; X,
  32. Y: Integer);
  33. procedure ImgScreenMouseMove(Sender: TObject; Shift: TShiftState; X,
  34. Y: Integer);
  35. procedure ImgScreenMouseDown(Sender: TObject; Button: TMouseButton;
  36. Shift: TShiftState; X, Y: Integer);
  37. procedure ImgScreenMouseUp(Sender: TObject; Button: TMouseButton;
  38. Shift: TShiftState; X, Y: Integer);
  39. procedure ApplicationEvents1Message(var Msg: tagMSG;
  40. var Handled: Boolean);
  41. procedure ImgScreenDblClick(Sender: TObject);
  42. procedure FormClose(Sender: TObject; var Action: TCloseAction);
  43. procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  44. private
  45. DX,DY,RectLeft,RectTop,RectBottom,RectRight:Integer;
  46. MouseIsDown,
  47. Trace:Boolean;
  48. ScreenState:TScreenState;
  49. FDragState: TDragState;
  50. procedure Cancel;
  51. procedure SendImg;
  52. procedure SaveImage;
  53. public
  54. end;
  55. procedure ShowCopyScreenForm;
  56. var
  57. CopyScreenForm: TCopyScreenForm;
  58. ScreenFileNO: Integer;
  59. ScreenFileName: String;
  60. implementation
  61. {$R *.dfm}
  62. procedure ShowCopyScreenForm;
  63. var
  64. FullScreen: Tbitmap;
  65. FullScreenCanvas: TCanvas;
  66. DC: HDC;
  67. begin
  68. FullScreen := TBitmap.Create; //创建一个BITMAP来存放图象
  69. try
  70. FullScreen.Width := Screen.width;
  71. FullScreen.Height := Screen.Height;
  72. DC := GetDC (0); //取得屏幕的 DC,参数0指的是屏幕
  73. FullScreenCanvas := TCanvas.Create; //创建一个CANVAS对象
  74. FullScreenCanvas.Handle := DC;
  75. FullScreen.Canvas.CopyRect
  76. (Rect (0, 0, Screen.Width, Screen.Height), FullScreenCanvas,
  77. Rect (0, 0, Screen.Width, Screen.Height));
  78. //把整个屏幕复制到BITMAP中
  79. FullScreenCanvas.Free; //释放CANVAS对象
  80. ReleaseDC (0, DC); //释放DC
  81. ScreenFileName := '';
  82. CopyScreenForm := TCopyScreenForm.Create(nil);
  83. try
  84. CopyScreenForm.ImgScreen.picture.Bitmap := fullscreen;//拷贝下的图象赋给IMAGE对象
  85. CopyScreenForm.Width := FullScreen.Width;
  86. CopyScreenForm.Height := FullScreen.Height;
  87. finally
  88. CopyScreenForm.ShowModal;
  89. end;
  90. finally
  91. FullScreen.free;
  92. CopyScreenForm.Free;
  93. end;
  94. end;
  95. //------------------------------------------------------------------------------
  96. procedure DrawBorder(Canvas: TCanvas; RectLeft, RectTop, RectRight, RectBottom: Integer);
  97. begin
  98. with Canvas do
  99. begin
  100. //左上角点
  101. Rectangle(RectLeft - 1, RectTop - 1, RectLeft + 2, RectTop + 2);
  102. Pixels[RectLeft, RectTop] := not Pixels[RectLeft, RectTop];
  103. //右上角点
  104. Rectangle(RectRight - 1, RectTop - 1, RectRight + 2, RectTop + 2);
  105. Pixels[RectRight, RectTop] := not Pixels[RectRight, RectTop];
  106. //左下角点
  107. Rectangle(RectLeft - 1, RectBottom - 1, RectLeft + 2, RectBottom + 2);
  108. Pixels[RectLeft, RectBottom] := not Pixels[RectLeft, RectBottom];
  109. //右下角点
  110. Rectangle(RectRight - 1, RectBottom - 1, RectRight + 2, RectBottom + 2);
  111. Pixels[RectRight, RectBottom] := not Pixels[RectRight, RectBottom];
  112. //上中点
  113. MoveTo(RectLeft + 2, RectTop);
  114. LineTo(RectLeft + (RectRight - RectLeft) div 2 - 1, RectTop);
  115. Rectangle(RectLeft + (RectRight - RectLeft) div 2 - 1, RectTop - 1, RectLeft + (RectRight - RectLeft) div 2 + 2, RectTop + 2);
  116. Pixels[RectLeft + (RectRight - RectLeft) div 2, RectTop] := not Pixels[RectLeft + (RectRight - RectLeft) div 2, RectTop];
  117. MoveTo(RectLeft + (RectRight - RectLeft) div 2 + 2, RectTop);
  118. LineTo(RectRight - 1, RectTop);
  119. //右中点
  120. MoveTo(RectRight, RectTop + 2);
  121. LineTo(RectRight, RectTop + (RectBottom - RectTop) div 2 - 1);
  122. Rectangle(RectRight - 1, RectTop + (RectBottom - RectTop) div 2 - 1, RectRight + 2, RectTop + (RectBottom - RectTop) div 2 + 2);
  123. Pixels[RectRight, RectTop + (RectBottom - RectTop) div 2] := not Pixels[RectRight, RectTop + (RectBottom - RectTop) div 2];
  124. MoveTo(RectRight, RectTop + (RectBottom - RectTop) div 2 + 2);
  125. LineTo(RectRight, RectBottom - 1);
  126. //下中点
  127. MoveTo(RectLeft + (RectRight - RectLeft) div 2 + 2, RectBottom);
  128. LineTo(RectRight - 1, RectBottom);
  129. Rectangle(RectLeft + (RectRight - RectLeft) div 2 - 1, RectBottom - 1, RectLeft + (RectRight - RectLeft) div 2 + 2, RectBottom + 2);
  130. Pixels[RectLeft + (RectRight - RectLeft) div 2, RectBottom] := not Pixels[RectLeft, RectBottom];
  131. MoveTo(RectLeft + (RectRight - RectLeft) div 2 - 2, RectBottom);
  132. LineTo(RectLeft + 1, RectBottom);
  133. //左中点
  134. MoveTo(RectLeft, RectTop + 2);
  135. LineTo(RectLeft, RectTop + (RectBottom - RectTop) div 2 - 1);
  136. Rectangle(RectLeft - 1, RectTop + (RectBottom - RectTop) div 2 - 1, RectLeft + 2, RectTop + (RectBottom - RectTop) div 2 + 2);
  137. Pixels[RectLeft, RectTop + (RectBottom - RectTop) div 2] := not Pixels[RectLeft, RectTop + (RectBottom - RectTop) div 2];
  138. MoveTo(RectLeft, RectTop + (RectBottom - RectTop) div 2 + 2);
  139. LineTo(RectLeft, RectBottom - 1);
  140. end;
  141. end;
  142. //------------------------------------------------------------------------------
  143. procedure TCopyScreenForm.SendImg;
  144. var
  145. newbitmap:TBitmap;
  146. newjpg:TJPegImage;
  147. TempInt:Integer;
  148. FileNameStart: String;
  149. TempJPegFile: array[0..MAX_PATH] of char;
  150. begin
  151. if ScreenState=msSelected then
  152. begin
  153. if RectLeft > RectRight then
  154. begin
  155. TempInt := RectLeft;
  156. RectLeft := RectRight;
  157. RectRight := TempInt;
  158. end;
  159. if RectTop > RectBottom then
  160. begin
  161. TempInt := RectTop;
  162. RectTop := RectBottom;
  163. RectBottom := TempInt;
  164. end;
  165. newbitmap := Tbitmap.create;
  166. newbitmap.width := RectRight-RectLeft;
  167. newbitmap.height := RectBottom-RectTop;
  168. if Trace then DrawBorder(ImgScreen.Canvas, RectLeft,RectTop,RectRight,RectBottom);
  169. newbitmap.Canvas.CopyRect(Rect(0, 0, newbitmap.width, newbitmap.height),ImgScreen.canvas,Rect (RectLeft, RectTop,RectRight,RectBottom)); //拷贝
  170. newjpg:=TJPegImage.Create;
  171. newjpg.Assign(newbitmap);
  172. newjpg.CompressionQuality := 90;
  173. newjpg.Compress;
  174. GetTempPath(MAX_PATH, TempJPegFile);
  175. GetTempFileName(TempJPegFile,
  176. PChar(Copy(FileNameStart, Length(FileNameStart) - 3, 3)),
  177. GetTickCount,
  178. TempJPegFile);
  179. ScreenFileNO := GetTickCount();
  180. ScreenFileName := ExtractFilePath(TempJPegFile) + IntToStr(ScreenFileNO) + '.JPG';
  181. newjpg.SaveToFile(ScreenFileName);
  182. newjpg.Free;
  183. newbitmap.free;
  184. Close;
  185. end;
  186. end;
  187. //------------------------------------------------------------------------------
  188. procedure TCopyScreenForm.FormShow(Sender: TObject);
  189. begin
  190. ScreenState := msDefault;
  191. MouseIsDown := False;
  192. Trace := False;
  193. RectLeft := -1;
  194. RectTop := -1;
  195. RectBottom := -1;
  196. RectRight := -1;
  197. ImgScreen.Canvas.Pen.mode := pmnot; //笔的模式为取反
  198. ImgScreen.canvas.pen.color := clBlue;
  199. ImgScreen.canvas.pen.Width := 1;
  200. ImgScreen.canvas.brush.Style := bsclear; //空白刷子end;
  201. end;
  202. //------------------------------------------------------------------------------
  203. procedure TCopyScreenForm.FormCreate(Sender: TObject);
  204. begin
  205. DoubleBuffered := True;
  206. FDragState := dsNone;
  207. end;
  208. //------------------------------------------------------------------------------
  209. procedure TCopyScreenForm.FormDestroy(Sender: TObject);
  210. begin
  211. end;
  212. //------------------------------------------------------------------------------
  213. procedure TCopyScreenForm.Cancel;
  214. begin
  215. if ScreenState = msDefault then
  216. Close
  217. else
  218. begin
  219. if Trace then DrawBorder(ImgScreen.Canvas, RectLeft,RectTop,RectRight,RectBottom);
  220. Trace := False;
  221. ScreenState := msDefault;
  222. LblActionInfo.Caption := '按住鼠标左键不放选择截取范围';
  223. LblCancelInfo.Caption := '按鼠标右键退出';
  224. exit;
  225. end;
  226. end;
  227. //------------------------------------------------------------------------------
  228. procedure TCopyScreenForm.PnlInfoMouseMove(Sender: TObject;
  229. Shift: TShiftState; X, Y: Integer);
  230. begin
  231. if PnlInfo.Left = 8 then
  232. PnlInfo.Left := Screen.Width - 8 - PnlInfo.Width
  233. else
  234. PnlInfo.Left := 8;
  235. end;
  236. //------------------------------------------------------------------------------
  237. procedure TCopyScreenForm.ImgScreenMouseMove(Sender: TObject;
  238. Shift: TShiftState; X, Y: Integer);
  239. var
  240. R,G,B:Integer;
  241. OldLeft, OldTop, OldRight, OldBottom: Integer;
  242. begin
  243. if (X > PnlInfo.Left) and ( X < PnlInfo.Left + PnlInfo.Width) and ( Y > PnlInfo.Top) and ( Y < PnlInfo.Top + PnlInfo.Height) then
  244. begin
  245. PnlInfoMouseMove(Sender, Shift, X, Y);
  246. end;
  247. if (ScreenState=msSelected) then
  248. begin
  249. if not MouseIsDown then
  250. begin
  251. if (X >= RectLeft - 3) and (X <= RectRight + 3) and (Y >= RectTop - 3) and (Y <= RectBottom + 3) then
  252. begin
  253. if (X < RectLeft + 3) and (Y < RectTop + 3) then
  254. begin
  255. ImgScreen.Cursor := crSizeNWSE; //左上角
  256. FDragState := dsLeftTop;
  257. end
  258. else if (X < RectLeft + 3) and (Y > RectBottom - 3) then
  259. begin
  260. ImgScreen.Cursor := crSizeNESW; //左下角
  261. FDragState := dsLeftBottom;
  262. end
  263. else if (X > RectRight - 3) and (Y < RectTop + 3) then
  264. begin
  265. ImgScreen.Cursor := crSizeNESW; //右上角
  266. FDragState := dsRightTop;
  267. end
  268. else if (X > RectRight - 3) and (Y > RectBottom - 3) then
  269. begin
  270. ImgScreen.Cursor := crSizeNWSE; //右下角
  271. FDragState := dsRightBottom;
  272. end
  273. else if (X < RectLeft + 3)then
  274. begin
  275. ImgScreen.Cursor := crSizeWE; // 左边
  276. FDragState := dsLeft;
  277. end
  278. else if (X > RectRight - 3)then
  279. begin
  280. ImgScreen.Cursor := crSizeWE; //右边
  281. FDragState := dsRight;
  282. end
  283. else if (Y < RectTop + 3)then
  284. begin
  285. ImgScreen.Cursor := crSizeNS; // 上边
  286. FDragState := dsTop;
  287. end
  288. else if (Y > RectBottom - 3)then
  289. begin
  290. ImgScreen.Cursor := crSizeNS; //下边
  291. FDragState := dsBottom;
  292. end
  293. else
  294. begin
  295. ImgScreen.Cursor := crSizeAll;
  296. FDragState := dsClient;
  297. end;
  298. end
  299. else
  300. begin
  301. FDragState := dsNone;
  302. ImgScreen.Cursor := crDefault;
  303. end;
  304. end
  305. else
  306. begin
  307. if FDragState <> dsNone then
  308. begin
  309. DrawBorder(ImgScreen.Canvas, RectLeft, RectTop, RectRight, RectBottom);
  310. OldLeft := RectLeft;
  311. OldTop := RectTop;
  312. OldRight := RectRight;
  313. OldBottom := RectBottom;
  314. case FDragState of
  315. dsLeftTop:
  316. begin
  317. RectLeft := RectLeft + (X - DX);
  318. RectTop := RectTop + (Y - DY);
  319. end;
  320. dsTop:
  321. begin
  322. RectTop := RectTop + (Y - DY);
  323. end;
  324. dsRightTop:
  325. begin
  326. RectRight := RectRight + (X - DX);
  327. RectTop := RectTop + (Y - DY);
  328. end;
  329. dsRight:
  330. begin
  331. RectRight := RectRight + (X - DX);
  332. end;
  333. dsRightBottom:
  334. begin
  335. RectRight := RectRight + (X - DX);
  336. RectBottom := RectBottom + (Y - DY);
  337. end;
  338. dsBottom:
  339. begin
  340. RectBottom := RectBottom + (Y - DY);
  341. end;
  342. dsLeftBottom:
  343. begin
  344. RectLeft := RectLeft + (X - DX);
  345. RectBottom := RectBottom + (Y - DY);
  346. end;
  347. dsLeft:
  348. begin
  349. RectLeft := RectLeft + (X - DX);
  350. end;
  351. dsClient:
  352. begin
  353. RectLeft := RectLeft + (X - DX);
  354. RectRight := RectRight + (X - DX);
  355. RectTop := RectTop + (Y - DY);
  356. RectBottom := RectBottom + (Y - DY);
  357. end;
  358. end;
  359. if RectLeft < 0 then RectLeft := 0;
  360. if RectTop < 0 then RectTop := 0;
  361. if RectRight > Width then RectRight := Width;
  362. if RectBottom > Height then RectBottom := Height;
  363. if RectLeft + 10 > RectRight then
  364. begin
  365. if (FDragState = dsLeft) or
  366. (FDragState = dsLeftBottom) or
  367. (FDragState = dsLeftTop) then
  368. begin
  369. RectLeft := RectRight - 10;
  370. RectRight := OldRight;
  371. end
  372. else
  373. begin
  374. RectRight := RectLeft + 10;
  375. RectLeft := OldLeft;
  376. end;
  377. X := DX;
  378. end;
  379. if RectTop + 10 > RectBottom then
  380. begin
  381. if (FDragState = dsTop) or
  382. (FDragState = dsLeftTop) or
  383. (FDragState = dsRightTop) then
  384. begin
  385. RectTop := RectBottom - 10;
  386. RectBottom := OldBottom;
  387. end
  388. else
  389. begin
  390. RectBottom := RectTop + 10;
  391. RectTop := OldTop;
  392. end;
  393. Y := DY;
  394. end;
  395. DrawBorder(ImgScreen.Canvas, RectLeft, RectTop, RectRight, RectBottom);
  396. DX := X;
  397. DY := Y;
  398. end;
  399. end;
  400. end
  401. else
  402. begin
  403. ImgScreen.Cursor := crCross;
  404. end;
  405. if (ScreenState = msDrag) and MouseIsDown then
  406. begin
  407. if Trace then DrawBorder(ImgScreen.Canvas, RectLeft, RectTop, RectRight, RectBottom);
  408. RectRight := X;
  409. RectBottom := Y;
  410. DrawBorder(ImgScreen.Canvas, RectLeft, RectTop, RectRight, RectBottom);
  411. Trace := True;
  412. end;
  413. if ((ImgScreen.Cursor = crCross) or (ImgScreen.Cursor = crDefault)) and (ScreenState <> msDrag) then
  414. begin
  415. R:=getRvalue(ImgScreen.Canvas.Pixels[X, Y]);
  416. G:=getGvalue(ImgScreen.Canvas.Pixels[X, Y]);
  417. B:=getBvalue(ImgScreen.Canvas.Pixels[X, Y]);
  418. LblRGB.Caption:='当前像素RGB值('+IntToStr(R)+'、'+IntToStr(G)+'、'+IntToStr(B)+')';
  419. end
  420. else
  421. begin
  422. LblRGB.Caption := Format('当前范围[%d,%d,%d,%d], 大小: %d*%d', [RectLeft, RectTop, RectRight, RectBottom, RectRight - RectLeft, RectBottom - RectTop]);
  423. end;
  424. LblRGB.Update;
  425. end;
  426. //------------------------------------------------------------------------------
  427. procedure TCopyScreenForm.ImgScreenMouseDown(Sender: TObject;
  428. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  429. begin
  430. if Button = mbRight then
  431. begin
  432. Cancel;
  433. Exit;
  434. end;
  435. if (ScreenState = msSelected) and (ImgScreen.Cursor <> crDefault) then
  436. begin
  437. MouseIsDown:=True;
  438. DX:=X;
  439. DY:=Y;
  440. end;
  441. if ScreenState <> msDefault then exit;
  442. if Trace then DrawBorder(ImgScreen.Canvas, RectLeft,RectTop,RectRight,RectBottom);
  443. MouseIsDown:=True;
  444. Trace:=False;
  445. ScreenState:=msDrag;
  446. RectLeft:=X;
  447. RectTop:=Y;
  448. RectRight:=X;
  449. RectBottom:=Y;
  450. LblActionInfo.Caption:='松开鼠标左键以确定最终截取范围';
  451. LblCancelInfo.Caption:='按鼠标右键取消当前选区';
  452. end;
  453. //------------------------------------------------------------------------------
  454. procedure TCopyScreenForm.ImgScreenMouseUp(Sender: TObject;
  455. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  456. var
  457. iTemp: Integer;
  458. begin
  459. MouseIsDown:=False;
  460. if ScreenState = msDrag then
  461. begin
  462. LblActionInfo.Caption := '按空格/回车/双击左键确定当前选区的图像';
  463. LblCancelInfo.Caption := '按鼠标右键取消当前选区,F5 = 另存为图像文件...';
  464. ScreenState := msSelected;
  465. DrawBorder(ImgScreen.Canvas, RectLeft, RectTop, RectRight, RectBottom);
  466. if RectLeft > RectRight then
  467. begin
  468. iTemp := RectLeft;
  469. RectLeft := RectRight;
  470. RectRight := iTemp;
  471. end;
  472. if RectTop > RectBottom then
  473. begin
  474. iTemp := RectTop;
  475. RectTop := RectBottom;
  476. RectBottom := iTemp;
  477. end;
  478. DrawBorder(ImgScreen.Canvas, RectLeft, RectTop, RectRight, RectBottom);
  479. end;
  480. end;
  481. //------------------------------------------------------------------------------
  482. procedure TCopyScreenForm.SaveImage;
  483. var
  484. newbitmap:TBitmap;
  485. begin
  486. newbitmap := Tbitmap.create;
  487. try
  488. newbitmap.width := RectRight-RectLeft;
  489. newbitmap.height := RectBottom-RectTop;
  490. if Trace then DrawBorder(ImgScreen.Canvas, RectLeft,RectTop,RectRight,RectBottom);
  491. newbitmap.Canvas.CopyRect(Rect(0, 0, newbitmap.width, newbitmap.height),
  492. ImgScreen.canvas,
  493. Rect(RectLeft, RectTop,RectRight,RectBottom)); //拷贝
  494. SavePictureDialog.FileName := 'SC' + IntToStr(GetTickCount) + '.BMP';
  495. if SavePictureDialog.Execute then
  496. begin
  497. if FileExists(SavePictureDialog.FileName) then
  498. begin
  499. DeleteFile(SavePictureDialog.FileName);
  500. end;
  501. newbitmap.SaveToFile(SavePictureDialog.FileName);
  502. end;
  503. finally
  504. newbitmap.Free;
  505. if Trace then DrawBorder(ImgScreen.Canvas, RectLeft,RectTop,RectRight,RectBottom);
  506. end;
  507. end;
  508. //------------------------------------------------------------------------------
  509. procedure TCopyScreenForm.ApplicationEvents1Message(var Msg: tagMSG;
  510. var Handled: Boolean);
  511. begin
  512. if Msg.message = WM_KEYDOWN then
  513. begin
  514. if Msg.wParam = 27 then
  515. begin
  516. Cancel;
  517. end;
  518. if (Msg.wParam = 32) or (Msg.wParam = 13) then
  519. begin
  520. if ScreenState = msSelected then
  521. begin
  522. if ((RectRight - RectLeft) > 5) or ((RectBottom - RectTop) > 5) then
  523. SendImg
  524. else
  525. begin
  526. Trace := False;
  527. Cancel;
  528. end;
  529. end;
  530. Handled := True;
  531. end;
  532. if (Msg.wParam = 116) then
  533. begin
  534. if ScreenState = msSelected then
  535. begin
  536. if ((RectRight - RectLeft) > 5) or ((RectBottom - RectTop) > 5) then
  537. SaveImage;
  538. end;
  539. Handled := True;
  540. end;
  541. end;
  542. end;
  543. //------------------------------------------------------------------------------
  544. procedure TCopyScreenForm.ImgScreenDblClick(Sender: TObject);
  545. begin
  546. if ScreenState = msSelected then
  547. begin
  548. if ((RectRight - RectLeft) > 5) or ((RectBottom - RectTop) > 5) then
  549. SendImg
  550. else
  551. begin
  552. Trace := False;
  553. Cancel;
  554. end;
  555. end;
  556. end;
  557. //------------------------------------------------------------------------------
  558. procedure TCopyScreenForm.FormClose(Sender: TObject;
  559. var Action: TCloseAction);
  560. begin
  561. Action := caFree;
  562. CopyScreenForm := nil;
  563. end;
  564. //------------------------------------------------------------------------------
  565. procedure TCopyScreenForm.FormCloseQuery(Sender: TObject;
  566. var CanClose: Boolean);
  567. begin
  568. Hide;
  569. end;
  570. end.