⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getrop2u.pas

📁 DelphiWin32核心API参考光盘内容.是学习书籍中的源码,便于学习.
💻 PAS
字号:
unit GetRop2U;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormPaint(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  RectDragging: Boolean;     // indicates if a dragging operation has begun
  OldRect: TRect;            // holds the old rectangular coordinates

implementation

{$R *.DFM}

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  {indicate that a dragging operation has begun}
  RectDragging := TRUE;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  {if we are dragging a rectangle...}
  if RectDragging then
  begin
    {initialize the canvas's pen}
    Canvas.Pen.Width := 5;

    {if the foreground mix mode is not R2_NOT, make it so}
    if GetRop2(Canvas.Handle)<>R2_NOT then
      SetRop2(Canvas.Handle, R2_NOT);

    {set the brush to be clear so only the lines show}
    Canvas.Brush.Style := bsClear;

    {draw a rectangle over the previous one to erase it}
    Canvas.Rectangle(OldRect.Left, OldRect.Top, OldRect.Right, OldRect.Bottom);

    {draw a rectangle at the new position}
    Canvas.Rectangle(X-20, Y-20, X+20, Y+20);

    {store the current rectangle coordinates for next time}
    OldRect := Rect(X-20, Y-20, X+20, Y+20);
  end;
end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  {dragging has stopped}
  RectDragging := FALSE;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  {draw the bitmap in Image1 to the form canvas}
  Canvas.Draw(0, 0, Image1.Picture.Bitmap);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -