Solved

VB5 API PtInRegion problem

Posted on 1997-06-30
6
300 Views
Last Modified: 2008-02-26
Having trouble understanding this.  Have a form with a picture box.  When form loads a line is draw in the pic box and used CreateRectRgn Api call.  Have a text box that is used to confirm if a point is in the region. When stepping through the code, everything seems to work, but when clicking the line, it always shows that there is no point in the region.  Have used the x1,y1,x2,y2 points of the line to create the region and am using the PtInRegion call to test for points.  No errors show out.  Have tried to make the code as simple as possible to avoid confusion.  Why do I get a negative response from this call?  Using code from a book API how to.
0
Comment
Question by:briant051897
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:y96andha
ID: 1427902
Please post your code, so I can try it.
0
 

Author Comment

by:briant051897
ID: 1427903
Option Explicit
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function PtInRegion Lib "gdi32" (ByVal hRgn As Long, ByVal X As Long, ByVal Y As Long) As Long
'Private Declare Function PtInRect Lib "user32" (lpRect As RECT, pt As POINTAPI) As Long
Dim rgn As Long
Const alternate = 1
Private Sub Command1_Click()
makeRgn Val(Text1.Text), Val(Text2.Text), Val(Text3.Text), Val(Text4.Text)
Pic.Line ((Text1.Text), (Text2.Text))-((Text3.Text), (Text4.Text))
End Sub
Private Sub Form_Load()
Text1.Text = 500
Text2.Text = 500
Text3.Text = 2500
Text4.Text = 2500
End Sub
Private Sub makeRgn(X1, Y1, X2, Y2)
rgn = CreateRectRgn(X1, Y1, X2, Y2)
End Sub
Private Function checkin(X, Y) As Long
checkin = PtInRegion(rgn, X, Y)
End Function
'private function checkin(
Private Sub Pic_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If checkin(X, Y) = 1 Then Text5.Text = "YES" Else Text5.Text = "NO"
End Sub

Comment:  Here's the code, I hope it is clear, thanks.
0
 
LVL 1

Accepted Solution

by:
lmarceau earned 50 total points
ID: 1427904
Your code worked fine once the Pic.Scalemode was setted to 3-Pixel.

Almost all API calls need coordinates in pixels.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:briant051897
ID: 1427905
When scalemode is changed to pixels the line no longer draws,
changing back to pixels, it draws?
0
 
LVL 1

Expert Comment

by:lmarceau
ID: 1427906
There are usually 15 twips for every pixels. (Check the picbox.TwipsPerPixel property to get the exact value)

Once in pixels, the coordinated of the line falls way out of the picture box. Even out of the screen if you have a 640 pixel per 480 screen.

When you change the Scalemode to 3-Pixels, reajust all coordinates for the picbox by dividing them by 15.

500 twips are equivalent to 35 pixels
and 2500 twips are equivalet 165 pixels

0
 

Author Comment

by:briant051897
ID: 1427907
That works! Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Macro which automatically sends attachment to Outlook 14 81
Adding to a VBA? 6 84
Access query that references subform 5 48
add criteria to query in VB, Access 2003 2 29
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question