Solved

VB5 API PtInRegion problem

Posted on 1997-06-30
6
291 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…

839 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