Results 1 to 23 of 23

Thread: Strange popup menu with image

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Ottawa
    Posts
    155

    Strange popup menu with image

    Hay all,

    If you try to add images to a form menu using the common API calls to do that it works nicely. Now if I make another menu and I set it's visiblity to false so i use it only as a popup menu, the menu icons simply vanish!! they disapear. I think I understand what is going on. I think that whenever the menu is invisble and visble again it redraws itself, and thus erases the icons that were there (this is just my guess, i could be wrong about this)...

    I searched for long time on this forum and found nothing. How do you do this? How do you add menu items to a popup menu without problems? I am able to add menu images to my form's menu just fine, I need to do the same for the popup.

    I have tested that whenever you set the visbility of any menu item to false and back to true the menu image disapears.

    any help will be greatly appreciated

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Okay so the menu itself is invisible, and you have specified images from an imagelist?
    And you're using the PopupMenu method to display the popup ?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Ottawa
    Posts
    155

    Yes

    Yes,

    See it works perfectly as a normal form menu when I sent the visibility to true. As soon as I set it to false and back to true then the images are gone!

    Also, I tried keeping it always visbile, it works that way as expected as a popup menu! But that's not what I want, because the menu is not suppose to be part of my form (just a popup) and if i keep the visbility to true then it's part of my form

    I appreciate any help. I am sure if you try this yourself you will find the same thing!

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    I'm not sure if this will work and I'm sure there is probably a better way of doing it, but could you place your menu on a second form, leave it visible and call it from your first form?

  5. #5
    Addicted Member Xdream's Avatar
    Join Date
    Mar 2001
    Location
    Switzerland
    Posts
    194
    Hi Koya

    Well, I acctually had the same problem with the menu.
    I just set the caption of the root menu to "" or space (I don't remember ) and enabled=false. This will disable the menu for the form but you can use it as popupmenu.

    good luck

    regards,
    xdream

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Ottawa
    Posts
    155

    ...

    The problem is not how to display a popup menu, bu how to display one with images for it's menu items :|...

    There should be a way, or how else do other programs do it?

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Are you setting the visibility property on all the sub menu items or
    just the top level?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Ottawa
    Posts
    155

    ...

    Just the top one.

    The bug is (or the problem is) when you set the visibility to false for any menu item and it has an image associated with it, the next time you set the visbility of that same menu item to true, the image is gone (i think because Windows redraws the menu tiem whenever it appears again!). So how do you keep the image there!

    This problem occurs specially fi you are making popup menus where you set the visibility of the top level menu to false so it won't be part of your form menu and yet can be used as a popup menu.

    the menu still popups, i am getting the menu, just without the images. That is the problem.

    SO in conclusion, the Visible property for a menu item screwes things up if the menu has an image.

    That's all I am trying to say. Hope to get some suggestions.

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    I have some code at home that I draw the images on the menus using APIs and subclassing. I will see if I do the same as you if
    the issue occurs or not. If t works correctly I will post for you.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Ottawa
    Posts
    155

    Smile Thanks

    Thank you. I always put images on a menu using a few API calls, but never subclassing anything

    I will have a look at yours. Thank you again

  11. #11
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    Attached is a sample of what I suggested above. There should be a better way, but this seems to work.
    Attached Files Attached Files

  12. #12
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    did you look at Xdream's post (below) and tried what he said?

    Originally posted by Xdream
    Hi Koya

    Well, I acctually had the same problem with the menu.
    I just set the caption of the root menu to "" or space (I don't remember ) and enabled=false. This will disable the menu for the form but you can use it as popupmenu.

    good luck

    regards,
    xdream
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Ottawa
    Posts
    155

    ...

    That is what I have always done, I don't see his point.... I tried it anyways, I think he didn't understand my point. In either way, i tried it, no success

  14. #14
    Addicted Member Xdream's Avatar
    Join Date
    Mar 2001
    Location
    Switzerland
    Posts
    194
    Hi Koya

    I just checked how I "solved" the problem within my application (popupmenu on systemtrayicon with pictures).

    1. Create a normal menu with caption, visible=true, enabled=true
    2. Put this code to the Form_Load event:

    Code:
    mnuPopupTray.Caption = ""
    mnuPopupTray.Enabled = False
    3. set menu images

    this works for me. I'm using this code for the images:

    Code:
    'sub - set menu icons
    Public Sub subSetMenuIcons()
        On Error Resume Next
        
        Dim I As Byte
        Dim hMenu As Long
        Dim hSubMenu As Long
        Dim menuID As Long
        
        With frmMain
    
        'frmMain
            hMenu = GetMenu(.hwnd)
            
            'mnuMenu
                hSubMenu = GetSubMenu(hMenu, 0)
                
                'mnuMenuSettings
                menuID = GetMenuItemID(hSubMenu, 0)
                Call SetMenuItemBitmaps(hMenu, menuID, vbNull, .imgLst.ListImages(1).Picture, .imgLst.ListImages(1).Picture)
                
                'mnuMenuHide
                menuID = GetMenuItemID(hSubMenu, 2)
                Call SetMenuItemBitmaps(hMenu, menuID, vbNull, .imgLst.ListImages(2).Picture, .imgLst.ListImages(2).Picture)
                
                'mnuMenuExit
                menuID = GetMenuItemID(hSubMenu, 4)
                Call SetMenuItemBitmaps(hMenu, menuID, vbNull, .imgLst.ListImages(3).Picture, .imgLst.ListImages(3).Picture)
    ....
    tell me if it doesn't work.

    regards

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Ottawa
    Posts
    155

    ...

    hay,

    thank you for your reply. This is exactly what I am doing. Exactly, even the same code almost. But mine doesn't work.

    Where are you calling the "subSetMenuIcons()" method from? I am calling it from the form_load() maybe it should be somewhere else just for that!!

    thank you.

  16. #16
    Addicted Member Xdream's Avatar
    Join Date
    Mar 2001
    Location
    Switzerland
    Posts
    194
    Don't be so hard with your code it's working - but not for invisible popupmenus...

    well: I'm calling the subSetMenuIcons in form_load as well, just in the order of my latest post. It's working for my popupmenu:

    frmMain.PopupMenu mnuPopupTray, , , , mnuPopupTrayRestore

    did you try it this way round?

  17. #17
    Addicted Member Xdream's Avatar
    Join Date
    Mar 2001
    Location
    Switzerland
    Posts
    194
    ...here my form_load:

    Code:
    'frm - LOAD
    Private Sub Form_Load()
        On Error Resume Next
        
    'MOUSE
        Screen.MousePointer = vbHourglass
        
    'READ SETTINGS
        Call subReadSettings
        
    'INIT FORM
        Me.Caption = App.Title & "  -  by Xdream Production"
        mnuPopupTray.Caption = ""
        mnuPopupTray.Enabled = False
        
    'check for another instance
        If App.PrevInstance = True Then
            MsgBox App.Title & " is already running!", vbCritical + vbOKOnly + vbMsgBoxSetForeground + vbApplicationModal
            Call subUnloadAppl
            Exit Sub
        End If
        
    'LOOK
        Call AddOfficeBorder(cmdSetTime.hwnd)
        Call AddOfficeBorder(cmdSetTimer.hwnd)
        Call AddOfficeBorder(cmdReset.hwnd)
        Call AddOfficeBorder(cmdStart.hwnd)
        Call AddOfficeBorder(cmdStop.hwnd)
        Call AddOfficeBorder(cmdApply.hwnd)
        Call AddOfficeBorder(cmdExit.hwnd)
        Call AddOfficeBorder(txtTimer(0).hwnd)
        Call AddOfficeBorder(txtTimer(1).hwnd)
        Call AddOfficeBorder(txtTimer(2).hwnd)
        Call subSetMenuIcons
        
    'ADD SYSTRAY ICON
        With typNID
            .cbSize = Len(typNID)
            .hwnd = Me.hwnd
            .uId = vbNull
            .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
            .uCallBackMessage = WM_MOUSEMOVE
            .hIcon = Me.Icon
            .szTip = App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision & ", Build " & strBuilt & vbNullChar
        End With
        Call Shell_NotifyIcon(NIM_ADD, typNID)
        
    'APPLY SETTINGS
        Call subGenerateTopmostForm(frmMain.hwnd, True)
        Call subApplyFormPosition
        Call subApplyOptions
        Call subApplyActionImg(frmMain.imgIcon)
        
    'INIT VARS
        'form animation
        With typFrmMainFormAnim
            .bitVisible = True
            .lngFormMaxWidth = Me.Width
            .lngFormMaxHeight = Me.Height
            .lngFormMinWidth = 4200
            .lngFormMinHeight = 100
        End With
        
        'others
        bitInetCheck1 = True
        bitInetCheck2 = True
        bitInetCheck3 = True
        lngCounter = 0
        intNowCountDownHour = 0
        intLastCountDownHour = 0
        
        bitUdnHMSChange = False
        bitUdnMaxReached(0) = False
        bitUdnMaxReached(1) = False
        bitUdnMaxReached(2) = False
        bitUdnMinReached(0) = False
        bitUdnMinReached(1) = False
        bitUdnMinReached(2) = False
        
        bitLogbookErr = False
        bitInetWarning = False
        
    'LOGBOOK
        Call subWriteLog("****************************************", True, False)
        Call subWriteLog("Applikation initialised...", False, True)
        
    'INIT OBJECTS
        Call cmdStop_Click
        Call chkInet_Click
        
    'COMMAND
        Call subApplyCommand(Command)
        'Call subApplyCommand("reboot;time;10;10;10;0;1;1;")
        
    'MOUSE
        Screen.MousePointer = vbDefault
            
        If Err Then
            Call MsgBoxErr(Err.Number, Err.Description)
        End If
    End Sub

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Ottawa
    Posts
    155
    I thank you again.

    I have the same order of code, except:

    "mnuPopupTrayRestore" what is that? I ony supply one parameter for the popupmenu method. Do I need this extra parameter?

    thanks a again. You've been a great help

  19. #19
    Addicted Member Xdream's Avatar
    Join Date
    Mar 2001
    Location
    Switzerland
    Posts
    194
    you're welcome

    the additinal parameter is for defining a default menu item (viewed as bold) for the user. It's not neccessary for the popupmenu.

    is it working now?

    regards

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Ottawa
    Posts
    155

    Question :(

    no it isn't working. I don't know why. If I remove the enabled=false from my form_load, it shows up fine with the images, if i put it back then it shows the popup menu without the images! this is really strange!

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Ottawa
    Posts
    155
    Hay all,

    I dont know what the hell, the trick did it. I was initalizing something in the wrong order, i changed that last night because i was trying different things and i didn't set it back. now I noticed that and your trick actually worked! nice thank you I tried that before but I wasn't too sure it was going to work and it actually didn't, but since you told me that yours worked, I knew I could make it work somehow using the same idea, I kept at it until I got it

    thank you again.
    I wonder if there is another way out there, because I could still click on the "blank" menu but i can't see what's in it since it's disabled oh well. not very professionaly but works!

  22. #22
    Addicted Member Xdream's Avatar
    Join Date
    Mar 2001
    Location
    Switzerland
    Posts
    194
    Well that's great if it is working now! I was really wondering why it didn't before.

    I don't know how you could do it otherwise, maybe we find another (not cheated ) solution...
    btw: how do you solve the problem with the pictures background? As far as I remember you need to insert a static bitmap and everybody who has another windows-color setting will still see the bitmap background (just as a square).

    For everybody who likes to play around with menu pictures, here is an example.

    Regards,
    Xdream
    Attached Files Attached Files

  23. #23

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Ottawa
    Posts
    155

    ...

    hay,
    sorry, I have no idea. I never tried inserting an image in the background. I will play with it maybe next week and will let you know if I come up with anything functional

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