Results 1 to 14 of 14

Thread: How to create click spots?!!

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    15
    Hi all,

    Anyone know how to create click spots on background image (like mapping in HTML) please help. I am stuck on my project.

    Thanks in advance.

  2. #2

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You want to have rectangular areas that can be clicked on?

    Well here's a good sample for you:
    Code:
    Private Declare Function PtInRect Lib "user32" (lpRect As RECT, pt As POINTAPI) As Long
    Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type
    Private Type POINTAPI
            X As Long
            Y As Long
    End Type
    
    Private clickspots() As RECT
    
    Private Sub Form_Load()
        ReDim clickspots(1)
        With clickspots(0)
            .Left = 50
            .Right = 100
            .Top = 50
            .Bottom = 100
        End With
        With clickspots(1)
            .Left = 250
            .Right = 200
            .Top = 50
            .Bottom = 100
        End With
    End Sub
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim pt As POINTAPI, n&
        pt.X = X
        pt.Y = Y
        For n = 0 To UBound(clickspots)
            If PtInRect(clickspots(n), pt) Then
                Debug.Print "clicked at area " & n
            End If
        Next n
    End Sub
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    15
    Thanks for your help!

    Kedaman, where would I place the top part which is the Private funtions?!! Can you show me because it show me the error when I move it to module.

    Thanks for your help again.

  5. #5
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471

    Exclamation don't make this so difficult

    Don't make this more difficult than it should be.
    If you want "click spots" (commonly known as hotspots)
    then just create (as someone previously mentioned) a label
    that is either transparent or a text frame with nothing in it. This should require no code whatsoever.

    I do this in my applications when i'm planting my easter
    eggs :P


  6. #6
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    Just place everything that Kedaman posted in your form code. If you want to put the declarations in a module, make them Public.

    However, I tried the code and it bombs out VB with an application error.

    This line:

    If PtInRect(clickspots(n), pt) Then

    generates an Application Error that memory cannot be read.

    Any suggestions ?

    Thanks.

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    15
    I'm a slow learner here, please be patient with me
    I create a label but it's overlapped my background image?
    I would like to know do i miss to do something?!!

  8. #8
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471

    Lightbulb no problem

    no problem, everyone has to start somewhere

    anyways, in design mode, right click on the label and click
    on 'Send to Back'
    this moves it behind the picture or whatever else you want on top.

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    hmm ptinrect really crashed, i just picked up that api because it was missing, now i found there was another module with the same function, well was years ago so how could i know
    Code:
    Private Function ptinrect(rect As rect, pt As POINTAPI) As Boolean
        ptinrect = pt.X > rect.Left And pt.X < rect.Right And pt.Y > rect.Top And pt.Y < rect.Bottom
    End Function
    replace the api with this instead
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  10. #10

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    15
    Thank you so much!! I got it but I use the imagebox(none) instead of label
    Noble, I have to do one more step. Can I swap the image whenever I point the mouse to that location? (only change the image of that location)

    I create another same background image but in diff color, I want it cut the same section of the second image and replace to the first background when i move the mouse to the location? any ideas how to do it?!!

  11. #11
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471

    hmmm

    that sounds tricky

    first of all, do you want it to change when you move the
    mouse over it or when you actually click on it?

    if you want it to change when you click on it, you can
    have two pictures boxes, each one displays a different
    picture
    when you click on one, it sets it's visible property to
    false and the visible property of the other image to true
    and vice versa for the other picture.

    If you want it to change when you simply move the mouse
    over it, you're gonna have to experiment with the API
    as i'm not sure the best way to do that.
    I know there is an API that
    tells you the mouse's position on the screen but i don't
    know if that's the best way to go about it.

    I hope this helps.
    Bababooey
    Tatatoothy
    Mamamonkey

  12. #12

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    15
    Thanks Nobel

    Someone told me to use buffer to hold the images and select cases. It is too complicated for me.

  13. #13
    Addicted Member
    Join Date
    Apr 2000
    Location
    England
    Posts
    246
    in th top piece of code you don't need to redefine RECT, there is already a rect type:

    Type Rect
    x1 as long
    x2 as long
    y1 as long
    y2 as long
    end type

    That type already exists, as for getting mouse position, theres always the VB event Mouse_Event which passes the mouse co-ords as it moves over the object which you can code in, its not perfect thou if you move the mouse over it quickly.

  14. #14
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Where do you find that RECT Nirces? It's at least not in the typelib that comes with my version of vb.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width