Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to detect a mouse click in a polygon region Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
03-Oct-02
Category
Win API
Language
Delphi 2.x
Views
154
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius 

I create several regions using CreatePolygonRgn function, passing an array of 
several points (ex. 4). After that, under some condition, I have to test if the 
user has clicked inside that region using PtInRegion. Now there are some problems: 
Sometimes CreatePolygonRgn returns 0 (no region created). Why is that? Under any 
circumstances I can not get any hits when passing points to PtInRegion.

Answer:

Here is a sample using a dynamic TPoint array:
1   
2   procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
3     Shift: TShiftState; X, Y: Integer);
4   type
5     PPointArray = ^TPointArray;
6     TPointArray = array[0..MaxInt div SizeOf(TPoint) - 1] of TPoint;
7   var
8     Rgn: HRGN;
9     P: PPointArray;
10  begin
11    GetMem(P, SizeOf(TPoint) * 3);
12    P[0] := Point(0, 0);
13    P[1] := Point(50, 100);
14    P[2] := Point(100, 50);
15    Rgn := CreatePolygonRgn(P[0], 3, WINDING);
16    Canvas.Brush.Color := clRed;
17    FillRgn(Canvas.Handle, Rgn, Canvas.Brush.Handle);
18    if PtInRegion(Rgn, X, Y) then
19      Beep;
20    DeleteObject(Rgn);
21    FreeMem(P);
22  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC