●●用 IntersectRect 获得矩形交集得不到正确结果●●(100分)

  • 主题发起人 主题发起人 vvyang
  • 开始时间 开始时间
V

vvyang

Unregistered / Unconfirmed
GUEST, unregistred user!
var<br> &nbsp;lprcDst: TRect;<br>begin<br> &nbsp;if IntersectRect(lprcDst, Rect(20, 10, 40, 60), Rect(80, 80, 30, 30)) then<br> &nbsp; &nbsp;ShowMessage('');<br>end;<br>显然 Rect(20, 10, 40, 60), Rect(80, 80, 30, 30) 这两个矩形有交集,可是结果呢,返回 False!包括 IsRectEmpty 函数在内。<br>在使用 IntersectRect &nbsp;必须把矩形正规化(left &lt; right, top &lt; bottom),否则得不到正确结果,妈的看来某些 API 函数也不怎么样。
 
帮顶!<br><br>╭=========================================╮<br><br> &nbsp; 80G海量源代码,控件,书籍全免费狂下不停!<br><br> &nbsp; http://www.source520.com<br> &nbsp;<br>╰=========================================╯
 
那位进来我把分分了。
 
那楼主为什么就不能先把矩形正式化呢,难道还一定要让人倒立了再来比较那个高呀
 
正规化也不是什么难题呀,写个函数变一下就行了
 
用RectInRegion判断看看<br>unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls, Buttons;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;btn1: TBitBtn;<br> &nbsp; &nbsp;procedure FormPaint(Sender: TObject);<br> &nbsp; &nbsp;procedure btn1Click(Sender: TObject);<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br> &nbsp;RGN: HRGN;<br> &nbsp;Rect: TRect;<br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.FormPaint(Sender: TObject);<br>begin<br> &nbsp;Canvas.Rectangle(10, 10, 100, 100);<br> &nbsp;Canvas.Ellipse(50, 50, 150, 150);<br>end;<br><br>procedure TForm1.btn1Click(Sender: TObject);<br>begin<br> &nbsp;if RectInRegion(RGN, rect) then<br> &nbsp; &nbsp;ShowMessage('in');<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> &nbsp;RGN := CreateEllipticRgn(50, 50, 150, 150);<br> &nbsp;SetRect(Rect, 10, 10, 100, 100);<br>end;<br><br>end.
 
帮顶!<br><br>╭=========================================╮<br><br> &nbsp; 80G海量源代码,控件,书籍全免费狂下不停!<br><br> &nbsp; http://www.source520.com<br> &nbsp; <br>╰=========================================╯
 
多人接受答案了。
 

Similar threads

后退
顶部