Solved

VB5 API PtInRegion problem

Posted on 1997-06-30
6
287 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

914 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now