Jump to content
Sign in to follow this  
victorlus

CreateRectRgn Someone knows how to solve ?

Recommended Posts

Hello everyone
Well, I have a question, I hope you can help me,
Next, I have 2 forms
Form2, Form1
Form2 cuts the screen well
What I wanted to do was when you cut out form 2, open form 1,
cut it and move it over the cut of shape 2
if possible, cut form 2 is inside panel 1 of form 

Image -> Error Matched form1

 

type
  TForm2 = class(TForm)
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
    var
    x1, y1, x2, y2: Integer;
    ptnd: Boolean;
    AnchorX, AnchorY, CurX, CurY: Integer;
  public
    { Public declarations }
  end;
  
var
  Form2: TForm2;

implementation

const
  vH: Byte = 10;
  vV: Byte = 30;

procedure TForm2.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  x1 := x + vH;
  y1 := y + vV;
  ptnd := True;
  AnchorX := X;
  CurX := X;
  AnchorY := Y;
  CurY := Y;
end;

procedure TForm2.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  Caption := 'x1: ' + IntToStr(x1) + '; y1 ' + IntToStr(y1) + '; x2 ' + IntToStr(x2) + '; y2 ' + IntToStr(y2) + ';';
  if ptnd then
  begin
    Canvas.Pen.Mode := pmNot;
    Canvas.Pen.Width := 2;
    Canvas.Brush.Style := bsClear;
    Canvas.Rectangle(AnchorX, AnchorY, CurX, CurY);
    CurX := X;
    CurY := Y;
    Canvas.Rectangle(AnchorX, AnchorY, CurX, CurY);
  end;
end;

procedure TForm2.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  region1, region2, rg2, rg1: hrgn;
  RECT : TRECT;
begin
  x2 := x + vH;
  y2 := y + vV;
  //if Shift = [ssCtrl] then
  begin
    region1 := CreateRectRgn(0, 0, Self.Width, Self.Height);
    region2 := CreateRectRgn(x1, y1, x2, y2);
    CombineRgn(region1, region1, region2, RGN_DIFF);
    SetWindowRgn(Handle, region1, True);


    getwindowrect(form1.Panel1.Handle,rect);

    form1.Top := Round((x1 + y1)/2);
    Form1.Left := Round((x2 + y2)/2);
    form1.Show;

    region1 := CreateRectRgn(0, 0, self.Width, self.Height);
    region2 := CreateRectRgn(x1, y1, x2, y2);
    CombineRgn(region1, region1, region2, RGN_DIFF);
    SetWindowRgn(form1.Handle, region1, True);

  end;
  if ptnd then
  begin
    ptnd := False;
    Canvas.Pen.Mode := pmNot;
    Canvas.Brush.Style := bsClear;
    Canvas.Rectangle(AnchorX, AnchorY, CurX, CurY);
  end;

end;

 

Share this post


Link to post

Some clues are clienttoscreen, windows.DrawFocusRect and  .boundsrect.  the form's mouse X is different than the screen's X.

Share this post


Link to post
7 hours ago, Pat Foley said:

Some clues are clienttoscreen, windows.DrawFocusRect and  .boundsrect.  the form's mouse X is different than the screen's X.

I tried that way not being able to measure an example?

Share this post


Link to post
Guest

hi @victorlus

 

FIRSTLY, you need to better develop your way of asking for help!
First, you should ask the question in detail closer to the real world, not the imaginary!
Give details on how you want something to be done, but don't skimp on words and examples.
If possible, draw a picture of how you would like the result of your question to be in practice!
Use MSPaint to draw, even if you are not a good draftsman ... do as you can! At least to help us understand your idea of:

Quote

"Form2 cuts the screen well
What I wanted to do was when you cut out form 2, open form 1,
cut it and move it over the cut of shape 2
if possible, cut form 2 is inside panel 1 of form "

 

Why didn't I understand any of that ...

 

NOTE: DO NOT USE CAPITAL LETTERS OR VERY LARGE SOURCES IN QUESTIONS, OK? - here a bad example, more was needed!

 

Do you see my sample for you - about other post ???

 

hug

Edited by Guest

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×