Results 1 to 29 of 29

Thread: [RESOLVED] how do i show an image when mouse is over a menu item?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    B.C. Canada
    Posts
    206

    Resolved [RESOLVED] how do i show an image when mouse is over a menu item?

    i would like to show a seperate image for each menu item in a menu when the mouse is over the menu item (not clicking it). the images will appear on the form next to the menu and will be on the same form as the menu. There are no mouse move events in the menu editor.

    Thanks in advance for any help

  2. #2
    Addicted Member Optional's Avatar
    Join Date
    Jan 2010
    Location
    Rudimentary Space
    Posts
    214

    Re: how do i show an image when mouse is over a menu item?

    You going to have to use API calls to catch windows messages and raise the events through windows for your application to catch the mouse_move event on a menu item.

    A quick search on google for "vb6 mousemove menu item" gave me this:
    http://p2p.wrox.com/vb-components/88...menu-item.html

    There is code showing how its done.



    Kind Regards,
    Optional



    If you feel this post has helped in answering your question please return the favour and Rate this post.
    If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.


    VB6 - (DataGrid) Get the Row selected with the right mouse button



  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: how do i show an image when mouse is over a menu item?

    How are you at subclassing? Subclassing is an advanced topic and until mastered expect many crashes of your VB application.

    As far as I know, there is no way to determine the mouse is over a specific menu item without subclassing the menu's form. The form receives messages to indicate which menu item is currently highlighted; those messages are not available without subclassing.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4
    gibra
    Guest

    Re: how do i show an image when mouse is over a menu item?

    Quote Originally Posted by daveinarmstrong View Post
    i would like to show a seperate image for each menu item in a menu when the mouse is over the menu item (not clicking it). the images will appear on the form next to the menu and will be on the same form as the menu. There are no mouse move events in the menu editor.

    Thanks in advance for any help

    Take a look to MenuExtended library (free) at
    http://www.vbcorner.net/eng/



    If you like, then I suggest to see MenuCreator VB6.0 add-in, too.



  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    B.C. Canada
    Posts
    206

    Re: how do i show an image when mouse is over a menu item?

    Quote Originally Posted by gibra View Post
    Take a look to MenuExtended library (free) at
    http://www.vbcorner.net/eng/



    If you like, then I suggest to see MenuCreator VB6.0 add-in, too.


    i tried MenuExtended but it is just for icon or smaller pictures, not exactly what i'm looking for.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    B.C. Canada
    Posts
    206

    Re: how do i show an image when mouse is over a menu item?

    i've no experience at subclassing but will give this a try.

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: how do i show an image when mouse is over a menu item?

    Quote Originally Posted by daveinarmstrong View Post
    i've no experience at subclassing but will give this a try.
    Once you learn subclassing and the new possibilities it presents itself to complete control over a window/control/application, you may become hooked (pun intended; you'll get it when you learn more about subclassing).

    Anyway, save your work often. Subclassing does result in immediate crashes of your application if you get an unhandled error or your subclass procedure generates an error. Subclassing is not something you learn in a day or week. The general idea/code is easy enough, but the practice/expertise is what takes time; and the frustration of crashing apps is just par for the course.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    B.C. Canada
    Posts
    206

    Re: how do i show an image when mouse is over a menu item?

    Quote Originally Posted by LaVolpe View Post
    Once you learn subclassing and the new possibilities it presents itself to complete control over a window/control/application, you may become hooked (pun intended; you'll get it when you learn more about subclassing).

    Anyway, save your work often. Subclassing does result in immediate crashes of your application if you get an unhandled error or your subclass procedure generates an error. Subclassing is not something you learn in a day or week. The general idea/code is easy enough, but the practice/expertise is what takes time; and the frustration of crashing apps is just par for the course.
    I agree, this is something worth learning.
    Is subclassing and windows API the same area of learning?

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: how do i show an image when mouse is over a menu item?

    Not really. You will use APIs in your subclassing endeavors.

    APIs (Application Program Interface) is a set of routines, data structures, object classes and/or protocols provided by libraries and/or operating system services in order to support the building of applications... blah, blah, blah.

    For most purposes, it is simply a set of functions/subs (routines) that exist in Windows DLLs and other 3rd party DLLs which enable you to do things that otherwise may not be possible with just VB. Many times an API may include a function you can write yourself, but many times it is just as simple to use the API function than recreate the wheel. APIs extend your coding power and thus, the capabilities of your applications.

    Here is a great tool that contains many of the most common API declarations, their constants, and structures. Nearly every serious VBer out there has a copy of this thing.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: how do i show an image when mouse is over a menu item?

    This may be a low grade solution but the GetCursorPos API will return your mouse X-Y coordinates anywhere on your screen. You can then use an If -Then block similar to this example to select your image.

    Code:
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Dim z As POINTAPI                ' Declare variable
    Private Type POINTAPI            ' Declare Types
        X As Long
        Y As Long
    End Type
    
    Private Sub Form_Load()
       Timer1.Interval = 100
    End Sub
    
    Private Sub Timer1_Timer()
       GetCursorPos z                              ' Get coordinates
       Label1 = "X: " & z.X                        ' Get X coordinates
       Label2 = "Y: " & z.Y                        ' Get Y coordinates
          If z.X > 383 Then Beep        ' Beep if X is greater than 383
          If z.Y > 243 Then Beep        ' Beep if Y is greater than 243
    End Sub
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    B.C. Canada
    Posts
    206

    Re: how do i show an image when mouse is over a menu item?

    Quote Originally Posted by CDRIVE View Post
    This may be a low grade solution but the GetCursorPos API will return your mouse X-Y coordinates anywhere on your screen. You can then use an If -Then block similar to this example to select your image.

    Code:
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Dim z As POINTAPI                ' Declare variable
    Private Type POINTAPI            ' Declare Types
        X As Long
        Y As Long
    End Type
    
    Private Sub Form_Load()
       Timer1.Interval = 100
    End Sub
    
    Private Sub Timer1_Timer()
       GetCursorPos z                              ' Get coordinates
       Label1 = "X: " & z.X                        ' Get X coordinates
       Label2 = "Y: " & z.Y                        ' Get Y coordinates
          If z.X > 383 Then Beep        ' Beep if X is greater than 383
          If z.Y > 243 Then Beep        ' Beep if Y is greater than 243
    End Sub
    is there a way to change this so i gets the mouse position relative to the form instead of the screen (mouse coordinates are 0,0 a top left corner of form).
    In case the form is not maximized.

  12. #12
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: how do i show an image when mouse is over a menu item?

    Expanding on CDrive's idea, here is a partial solution read the comments completely
    Code:
    Option Explicit
    Private Declare Function GetCursorPos Lib "user32.dll" (ByRef lpPoint As POINTAPI) As Long
    Private Declare Function WindowFromPoint Lib "user32.dll" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
    Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT) As Long
    Private Declare Function ScreenToClient Lib "user32.dll" (ByVal hwnd As Long, ByRef lpPoint As POINTAPI) As Long
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    
    
    Private Sub mnuMain_Click()
        ' when menu opens, start timer
        Timer1.Tag = "-1" ' will use this to identify if menuitem selection changed
        Timer1.Interval = 100
        Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
        Dim mPT As POINTAPI, mWnd As Long, sBuffer As String
        Dim wRect As RECT
        Dim nrMenuItems As Long, mIndex As Long
        
        GetCursorPos mPT
        mWnd = WindowFromPoint(mPT.X, mPT.Y)
        sBuffer = String$(6, vbNullChar)
        Call GetClassName(mWnd, sBuffer, 7)
        If sBuffer = "#32768" Then ' you have a menu window
            ' however, there are still isses to resolve
            ' 1. You can get the size of the menu window with GetWindowRect API
            GetWindowRect mWnd, wRect
            ' 2. Now you need to convert the screen coords to menu window coords: ScreenToClient API
            ScreenToClient mWnd, mPT
            ' 3. Since you know how many menu items exist (assuming no scrolling menu),
            '       you can calculate how many pixels high for each menu item & determine menu index
            nrMenuItems = 3 ' I only used 3 for my test
            mIndex = mPT.Y \ ((wRect.Bottom - wRect.Top) \ nrMenuItems)
            If mIndex <> Val(Timer1.Tag) Then 
                   Timer1.Tag = mIndex
                   Me.Caption = "over menu item " mIndex+1
            End If
            ' -- issues
            ' 1. You won't know when the menu closed if no menu item was selected (i.e., Esc pressed);
            '    so how do you stop the timer? You dont' really want it to go on forever. Thoughts?
            ' 2. If any other menu item (submenu opens or another top level menu opens), you should
            '   stop the timer if it is enabled
        End If
    End Sub
    Last edited by LaVolpe; Jan 26th, 2010 at 10:27 AM. Reason: fixed: Timer1.Tag = mIndex
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    B.C. Canada
    Posts
    206

    Re: how do i show an image when mouse is over a menu item?

    i can work with this.
    Thank you for your help!

  14. #14
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: how do i show an image when mouse is over a menu item?

    I had a typo in the code & updated it.

    Also note that the menu closing, without a selection (i.e., click event on one of the menu items) can happen under a few scenarios. And I think not being able to control when the timer stops is a bad idea that may lead to more headaches. Here are a few scenarios:
    1. User presses Esc, Tab, Alt, and potentially other keys
    2. User clicks anywhere else on the screen
    3. Another window, any window, pops up
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  15. #15
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: how do i show an image when mouse is over a menu item?

    Just because I love puzzles, this is a good solution, but has one drawback addressed at bottom of this post.

    The fix is to locate the menu immediately, test whether the mouse X,Y coords are within the window bounds, and testing if the menu is visible or not. Seems to work really well for mouse "hover" over a menu selection.
    Code:
    Option Explicit
    Private Declare Function GetCursorPos Lib "user32.dll" (ByRef lpPoint As POINTAPI) As Long
    Private Declare Function WindowFromPoint Lib "user32.dll" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
    Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hWnd As Long, ByRef lpRect As RECT) As Long
    Private Declare Function ScreenToClient Lib "user32.dll" (ByVal hWnd As Long, ByRef lpPoint As POINTAPI) As Long
    Private Declare Function IsWindowVisible Lib "user32.dll" (ByVal hWnd As Long) As Long
    Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    
    Private myMenuHwnd As Long
    
    Private Sub mnuMain_Click()
        ' when menu opens, start timer
        Me.Caption = "Waiting for menu selection" ' testing purposes
        DoEvents ' should allow menu to appear
        myMenuHwnd = FindWindow("#32768", vbNullString)
        Timer1.Tag = "-1"
        Timer1.Interval = 100
        Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
        Dim mPT As POINTAPI, sBuffer As String
        Dim wRect As RECT, mIndex As Long
        Dim nrMenuItems As Long
        
        GetCursorPos mPT
        If myMenuHwnd = 0& Then
            myMenuHwnd = WindowFromPoint(mPT.X, mPT.Y)
            sBuffer = String$(6, vbNullChar)
            Call GetClassName(myMenuHwnd, sBuffer, 7)
            If sBuffer <> "#32768" Then myMenuHwnd = 0&
        ElseIf IsWindowVisible(myMenuHwnd) = 0& Then
            Me.Caption = "Menu closed" ' testing purposes
            Timer1.Enabled = False
            myMenuHwnd = 0&
        End If
        If myMenuHwnd Then
            GetWindowRect myMenuHwnd, wRect
            If mPT.Y > wRect.Top And mPT.Y < wRect.Bottom Then
                If mPT.X > wRect.Left And mPT.X < wRect.Right Then
                    ScreenToClient myMenuHwnd, mPT
                    nrMenuItems = 3 ' I only used 3 for my test
                    mIndex = mPT.Y \ ((wRect.Bottom - wRect.Top) \ nrMenuItems)
                    If mIndex <> Val(Timer1.Tag) Then
                        Timer1.Tag = mIndex
                        Me.Caption = "over menu item " & mIndex + 1 ' testing purposes
                    End If
                End If
            End If
        End If
    End Sub
    Downside. Does not deal with user moving up/down menu items via the keyboard. Can be overcome with a keybd hook (like subclassing) or another timer testing keyboard for strokes (GetAsyncKeyState API for example)
    Edited:
    Other potential issues if they apply:
    1. If menu is large and eventually scrolls; all bets are off and will require a lot more work
    2. If menu opens any contained submenus; needs more work to stop timer when submenu opens & restart timer when submenu closes

    Subclassing is the correct way to do what you want and all issues will be overcome; but as mentioned before, subclassing requires some practice and has zero-tolerance for errors. Makeshift workarounds rarely work as well, can be buggy, and often are less efficient than the "correct" way. Just FYI.
    Last edited by LaVolpe; Jan 26th, 2010 at 12:17 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    B.C. Canada
    Posts
    206

    Re: how do i show an image when mouse is over a menu item?

    Quote Originally Posted by LaVolpe View Post
    Just because I love puzzles, this is a good solution, but has one drawback addressed at bottom of this post.

    The fix is to locate the menu immediately, test whether the mouse X,Y coords are within the window bounds, and testing if the menu is visible or not. Seems to work really well for mouse "hover" over a menu selection.
    Code:
    Option Explicit
    Private Declare Function GetCursorPos Lib "user32.dll" (ByRef lpPoint As POINTAPI) As Long
    Private Declare Function WindowFromPoint Lib "user32.dll" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
    Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hWnd As Long, ByRef lpRect As RECT) As Long
    Private Declare Function ScreenToClient Lib "user32.dll" (ByVal hWnd As Long, ByRef lpPoint As POINTAPI) As Long
    Private Declare Function IsWindowVisible Lib "user32.dll" (ByVal hWnd As Long) As Long
    Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    
    Private myMenuHwnd As Long
    
    Private Sub mnuMain_Click()
        ' when menu opens, start timer
        Me.Caption = "Waiting for menu selection" ' testing purposes
        DoEvents ' should allow menu to appear
        myMenuHwnd = FindWindow("#32768", vbNullString)
        Timer1.Tag = "-1"
        Timer1.Interval = 100
        Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
        Dim mPT As POINTAPI, sBuffer As String
        Dim wRect As RECT, mIndex As Long
        Dim nrMenuItems As Long
        
        GetCursorPos mPT
        If myMenuHwnd = 0& Then
            myMenuHwnd = WindowFromPoint(mPT.X, mPT.Y)
            sBuffer = String$(6, vbNullChar)
            Call GetClassName(myMenuHwnd, sBuffer, 7)
            If sBuffer <> "#32768" Then myMenuHwnd = 0&
        ElseIf IsWindowVisible(myMenuHwnd) = 0& Then
            Me.Caption = "Menu closed" ' testing purposes
            Timer1.Enabled = False
            myMenuHwnd = 0&
        End If
        If myMenuHwnd Then
            GetWindowRect myMenuHwnd, wRect
            If mPT.Y > wRect.Top And mPT.Y < wRect.Bottom Then
                If mPT.X > wRect.Left And mPT.X < wRect.Right Then
                    ScreenToClient myMenuHwnd, mPT
                    nrMenuItems = 3 ' I only used 3 for my test
                    mIndex = mPT.Y \ ((wRect.Bottom - wRect.Top) \ nrMenuItems)
                    If mIndex <> Val(Timer1.Tag) Then
                        Timer1.Tag = mIndex
                        Me.Caption = "over menu item " & mIndex + 1 ' testing purposes
                    End If
                End If
            End If
        End If
    End Sub
    Downside. Does not deal with user moving up/down menu items via the keyboard. Can be overcome with a keybd hook (like subclassing) or another timer testing keyboard for strokes (GetAsyncKeyState API for example)
    Edited:
    Other potential issues if they apply:
    1. If menu is large and eventually scrolls; all bets are off and will require a lot more work
    2. If menu opens any contained submenus; needs more work to stop timer when submenu opens & restart timer when submenu closes

    Subclassing is the correct way to do what you want and all issues will be overcome; but as mentioned before, subclassing requires some practice and has zero-tolerance for errors. Makeshift workarounds rarely work as well, can be buggy, and often are less efficient than the "correct" way. Just FYI.
    I do have submenus, but for now i am showing a picture only when hovering over the main menu items. I can post the form with the images if you would like to see.

    Many Thanks for your help and every one elses help.

    Code:
    If mIndex <> Val(Timer1.Tag) Then
                        Timer1.Tag = mIndex
                        Me.Caption = "over menu item " & mIndex + 1 ' testing purposes
                        If mIndex = 0 Then
                        Image1.Visible = True
                        Else: Image1.Visible = False
                        End If
                        If mIndex = 1 Then
                        Image2.Visible = True
                        Else: Image2.Visible = False
                        End If
                    End If

  17. #17
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: how do i show an image when mouse is over a menu item?

    By submenus, I am referring to within the same menu level and may be moot.
    In the image below "File" is one level, "Edit" is another level.
    So if "File" had submenus in it, the latest code will probably still work and won't get false positives on the submenu; after second thoughts.
    Name:  untitled.GIF
Views: 262
Size:  3.6 KB
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  18. #18
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: how do i show an image when mouse is over a menu item?

    Nice work LV.
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    B.C. Canada
    Posts
    206

    Re: how do i show an image when mouse is over a menu item?

    Quote Originally Posted by LaVolpe View Post
    By submenus, I am referring to within the same menu level and may be moot.
    In the image below "File" is one level, "Edit" is another level.
    So if "File" had submenus in it, the latest code will probably still work and won't get false positives on the submenu; after second thoughts.
    Name:  untitled.GIF
Views: 262
Size:  3.6 KB
    i have submenus under "project planner" please see below.
    when i am over laundry, the picture shows up. do you think this will work while over small laundry?

    Your help is greatly appreciated.
    Attached Images Attached Images  

  20. #20
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: how do i show an image when mouse is over a menu item?

    No, you will have to tweak the routines. The reason it won't work is that the timer is only checking the parent menu panel, not the submenu panel.

    I will give it some thought, but no promises in posting something really soon (I mean tonight). A question, how many submenus deep do you plan on going, or is it dynamic where you really have no control?

    P.S. I still stand by my original suggestion: Use subclassing, which will allow user to navigate with keyboard too (i.e., up/down arrows). Because you only need to subclass when the project planner menu is "clicked" and subclassing can be immediately terminated when menus close; crashes should be few and far between.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    B.C. Canada
    Posts
    206

    Re: how do i show an image when mouse is over a menu item?

    Quote Originally Posted by LaVolpe View Post
    No, you will have to tweak the routines. The reason it won't work is that the timer is only checking the parent menu panel, not the submenu panel.

    I will give it some thought, but no promises in posting something really soon (I mean tonight). A question, how many submenus deep do you plan on going, or is it dynamic where you really have no control?
    it will be one level of sub menu for each item in project planner (garage, pantry, closet, laundry, office, entertainment) having 3 sizes each small medium large.
    Attached Images Attached Images  

  22. #22
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: how do i show an image when mouse is over a menu item?

    Another idea should you be interested. A treeview control (like Window's Explorer's leftside pane) on the left side of the form may be perfect for this. Your main level pics would be listed and any sublevel pics would be leafs on that node. And you can go as deep as you like. No timers, no hacking, no subclassing. Just an idea.

    But if you want to stay with your current plan, one level deep is easy enough; 2 timers and some tweaking. Though keyboard selection is still not an option.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  23. #23
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: how do i show an image when mouse is over a menu item?

    Oh one last thing and if you still want to go with timers I can post an update for you using the current methodolgy.

    Disadvantages of this method:
    1. No keyboard navigation in menus
    2. Potential of scrolling menubar. Depending on user's screen resolution, less menu items will fit in a panel before it scrolls.
    3. No scalability. If you need to add more items to your menu, you'll have to add more menu items, more pictures, potentially more code, and then recompile your app and send it out.
    4. Other shortfalls I'm sure, but maybe not as major.

    Advantages of treeview control or similar method.
    1. No workarounds
    2. Scalability. For example, you can distribute a zip file containing the images, an index of items for your treeview. Your users can unzip it into a new folder and you can offer a menu item/function that will import that index. You don't have to recompile if you decide to change images or add/subtract images. Just supply a new/updated zip or other package format.
    3. No worries about scrolling either. Treeviews have a scrollbar.

    Disadvantage of treeview. Need form space to display it in, but that isn't necessarily a given because you can popup up another form with the treeview in it instead.

    Your thoughts.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  24. #24

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    B.C. Canada
    Posts
    206

    Re: how do i show an image when mouse is over a menu item?

    tree view might be a better idea. i'll work on this tonight. i will keep your menu hover code for future use if i go with the tree view. Thanks LaVolpe.

  25. #25
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: how do i show an image when mouse is over a menu item?

    Oh, you are welcome. After seeing what you were using this for, I thought brainstorming options for future change/updates with minimal impact to potential customers was worth it. I did not intend to persuade you either way.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  26. #26
    gibra
    Guest

    Re: how do i show an image when mouse is over a menu item?

    Just another idea:
    you can use a ListBox with 3 options
    In this way the user simply select item and choose option size.
    I.e. the user choose Medium, each item selected will be shows Medium size.
    No extra OCX to deploy, too.
    Attached Images Attached Images  

  27. #27

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    B.C. Canada
    Posts
    206

    Re: how do i show an image when mouse is over a menu item?

    i am going to use LaVolpe's code "show an image when mouse is over a menu item".

    Thanks LaVolpe for your code.
    Thanks to all for your ideas.

  28. #28

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    B.C. Canada
    Posts
    206

    Re: how do i show an image when mouse is over a menu item?

    Having problem with accuracy of mIndex, sometimes off by mPT.Y = 4. This causes the previous menu image to stay while the mouse pionter is part way over the next menu item. This seams to be a rounding issue and even though i Dim mIndex As Single or double i still only get a whole number for mIndex.


    Code:
    Dim mPT As POINTAPI, sBuffer As String
        Dim wRect As RECT
        Dim mIndex As Single 'Long
        Dim nrMenuItems As Single 'Long
        
        GetCursorPos mPT
        If myMenuHwnd = 0& Then
            myMenuHwnd = WindowFromPoint(mPT.X, mPT.Y)
            sBuffer = String$(6, vbNullChar)
            Call GetClassName(myMenuHwnd, sBuffer, 7)
            If sBuffer <> "#32768" Then myMenuHwnd = 0&
        ElseIf IsWindowVisible(myMenuHwnd) = 0& Then
            'Me.Caption = "Menu closed" ' testing purposes
            Timer1.Enabled = False
            myMenuHwnd = 0&
            Dim i As Integer
            For i = Container().LBound To Container().UBound
            Container(i).Visible = False
            Scene(i).Visible = False
            Next
        End If
        If myMenuHwnd Then
            GetWindowRect myMenuHwnd, wRect
            If mPT.Y > wRect.Top And mPT.Y < wRect.Bottom Then
                If mPT.X > wRect.Left And mPT.X < wRect.Right Then
                    ScreenToClient myMenuHwnd, mPT
                    nrMenuItems = 6 ' number of menu items
                    mIndex = mPT.Y \ ((wRect.Bottom - wRect.Top) \ nrMenuItems) ' mIndex should result in a fractional number, but never does
                    Text1.ZOrder 0
                    Text1.Text = "mIndex" & mIndex & "  mPT.Y" & mPT.Y & _
                    "  wRect.Bottom" & wRect.Bottom & "  wRect.Top" & wRect.Top & "  nrMenuItems" & nrMenuItems
                    If mIndex <> Val(Timer1.Tag) Then
                        Timer1.Tag = mIndex
                        'Me.Caption = "over menu item " & mIndex + 1 ' testing purposes
                        If mIndex = 0 Then
                        Container(0).Move 5625, 1110
                        Scene(0).Move 0, 0
                        Container(0).Visible = True
                        Scene(0).Visible = True
                        Else
                        Container(0).Visible = False
                        Scene(0).Visible = False
                        End If
                        If mIndex = 1 Then
                        Container(1).Move 5625, 1110
                        Scene(1).Move 0, 0
                        Container(1).Visible = True
                        Scene(1).Visible = True
                        Else
                        Container(1).Visible = False
                        Scene(1).Visible = False
                        End If
                        If mIndex = 2 Then
                        Container(2).Move 5625, 1110
                        Scene(2).Move 0, 0
                        Container(2).Visible = True
                        Scene(2).Visible = True
                        Else
                        Container(2).Visible = False
                        Scene(2).Visible = False
                        End If
                        If mIndex = 3 Then
                        Container(3).Move 5625, 1110
                        Scene(3).Move 0, 0
                        Container(3).Visible = True
                        Scene(3).Visible = True
                        Else
                        Container(3).Visible = False
                        Scene(3).Visible = False
                        End If
                        If mIndex = 4 Then
                        Container(4).Move 5625, 1110
                        Scene(4).Move 0, 0
                        Container(4).Visible = True
                        Scene(4).Visible = True
                        Else
                        Container(4).Visible = False
                        Scene(4).Visible = False
                        End If
                        If mIndex = 5 Then
                        Container(5).Move 5625, 1110
                        Scene(5).Move 0, 0
                        Container(5).Visible = True
                        Scene(5).Visible = True
                        Else
                        Container(5).Visible = False
                        Scene(5).Visible = False
                        End If
                    End If
                End If
            End If
        End If
    [/QUOTE]

  29. #29
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [RESOLVED] how do i show an image when mouse is over a menu item?

    It is due to the border style/thickness of the menu window
    modify from:
    Code:
        If myMenuHwnd Then
            GetWindowRect myMenuHwnd, wRect
            If mPT.Y > wRect.Top And mPT.Y < wRect.Bottom Then
                If mPT.X > wRect.Left And mPT.X < wRect.Right Then
                    ScreenToClient myMenuHwnd, mPT
    to:
    Code:
        If myMenuHwnd Then
            GetClientRect myMenuHwnd, wRect
            ScreenToClient myMenuHwnd, mPT
            If mPT.Y => 0 And mPT.Y < wRect.Bottom Then
                If mPT.X => 0 And mPT.X < wRect.Right Then
    How now? Not tested as I'm on my way out the door.

    Oh, here's that API declaration
    Code:
    Private Declare Function GetClientRect Lib "user32.dll" (ByVal hWnd As Long, ByRef lpRect As RECT) As Long
    Edited: Regarding rounding/fractional numbers. Notice the angle of the division symbol. That angle means "Integer Division" which always results in dropping the decimal portion. You will want to leave it the way it is.
    Last edited by LaVolpe; Jan 29th, 2010 at 08:12 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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