Solved

VB5 API PtInRegion problem

Posted on 1997-06-30
6
305 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
Independent Software Vendors: 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month3 days, 11 hours left to enroll

630 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