Solved

VB5 API PtInRegion problem

Posted on 1997-06-30
6
282 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
Comment Utility
Please post your code, so I can try it.
0
 

Author Comment

by:briant051897
Comment Utility
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
Comment Utility
Your code worked fine once the Pic.Scalemode was setted to 3-Pixel.

Almost all API calls need coordinates in pixels.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

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

Expert Comment

by:lmarceau
Comment Utility
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
Comment Utility
That works! Thanks!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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

11 Experts available now in Live!

Get 1:1 Help Now