Results 1 to 24 of 24

Thread: popup menus

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    UK
    Posts
    205

    popup menus

    I remember an article i posted ages and ages ago. It was about popup menus in VB. I just wondered if anyone has figured out a way to get it to dissappear when it loses focus. Because i have to stick a cancel button on them to make them dissappear when i change my mind. It bugs me!

  2. #2
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Create a menu using the menu editor, but set the top element's visibility to hidden.

    Then, use the following to open the menu:

    popupMenu mnuTheMenuName, vbPopupMenuLeftAlign
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Lord_Rat. Do you EVER actually read the posts?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Umm yeah. Do you EVER try implementing my suggestions?

    I am sometimes wrong, but not usually. This is a case of not usually.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  5. #5
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    In this instance, if he creates the pop up menu as I described, closing it is handled by VB automatically, which still solves his issue.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    UK
    Posts
    205
    when i meant lose focus, i mean lose focus to another application, and this popup menu pops up from a task bar icon. So it cant lose focus to itself.

    Any ideas? I posted this a while ago to the API guys and they couldnt come up with anything either. I thought there might be an API call for it.

  7. #7
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Could you give me a screen-shot?
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    UK
    Posts
    205

    screen shot

    Attached Images Attached Images  

  9. #9
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    You're using a system tray icon, then?

    Here is a wrapper I wrote for system tray icons; you can use it for your app, I won't mind.

    To use it:

    On your form, make a non-visible menu titled:
    trayPopup

    (no mnu prefix).

    Then, to add the form to the system tray, call:
    GotoTray Me

    The first time (like on form load)

    And then to actually show it in the system tray any time other than the first (although doing it again does not hurt):
    ShowInTray Me, True

    And to hide it from the tray (like in the form_queryUnload function):
    ShowInTray Me, False

    Also, make sure that you unload the tray icon before exiting the program or a ghost will remain in the tray.

    Also, on the form, you need:

    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Static lngMsg As Long
    Static blnFlag As Boolean
    Dim result As Long
    lngMsg = X / Screen.TwipsPerPixelX
    If lngMsg = WM_LBUTTONDBLCLICK Or lngMsg = WM_RBUTTONUP Then
    ' tmp = tmp
    End If
    CheckTray Me, lngMsg, blnFlag, result
    End Sub
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  10. #10
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    I'm apparently horrible with attaching files. (attached this time)
    Attached Files Attached Files
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    UK
    Posts
    205
    thats pretty neet. Not tried it yet mind you. One problem with it i can see is i will have to modify it a lot suppose, just looking at a glance. The reason is I have customised my system tray bas file to handle animated system tray icons. Well heres mine anyways, take a look, not as advanced as your though
    Attached Files Attached Files

  12. #12
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    If you change the icon for the form, it will change the icon for the tray. Thus, if you want to have an animated icon, you can change the icon to the next frame on a timer event.

    I downloaded your code, but I cannot see how you are currently implementing animated icons.

    If you could give me some code, I could probably figure out what you are doing and then add that functionality to mine (which I agree, could be handy)
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    UK
    Posts
    205
    you just need to add a timer for the animation you want to present. For me, i am building a real simple email notification program that doesnt use much memory, and sits in the systray (it beats having outlook open 24 7).
    VB Code:
    1. Private Sub tmrAnimateFull_Timer()
    2.     Static i As Integer
    3.    
    4.     If i < 0 Then i = 0
    5.     If i > 1 Then i = 0
    6.     ModSysTrayIco imgFull(i).Picture.Handle
    7.     i = i + 1
    8. End Sub

    that one just makes the mail box icon flash different colours. You have to have the images in a resource or as image arrays on the form. Unless there is an easier way. I mean, i like to embed them because it makes porting the program onto other computers a whole lot easier.

    This snippet does the same, but for a more complex animation sequence.
    VB Code:
    1. Private Sub tmrAnimateCheck_Timer()
    2.     Static i As Integer
    3.    
    4.     If i < 0 Then i = 0
    5.     If i > 7 Then i = 0
    6.     ModSysTrayIco imgCheck(i).Picture.Handle
    7.     i = i + 1
    8. End Sub

    Notice there are 8 frames in this animation as opposed to 2 in the last one. Still uses the same code though

  14. #14
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Yeah that is an annoying thing, to fix it call SetForegroundWindow API before showing the PopUp, just pass it the hwnd of the owner form or i guess just one from your app.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    UK
    Posts
    205
    im not quite sure i know what you mean Edneeis? Can you explain with some sample code please? Cheers.

  16. #16
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    OK

    Using a combination of your icon change code and my systray code, I give you the NEW and UPDATED animated tray icon project!

    I modified my code and wrote a sample app for you.

    Check it out!
    Attached Files Attached Files
    Last edited by Lord_Rat; Mar 26th, 2002 at 07:49 PM.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  17. #17
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    I forgot to put
    Unload Me

    In the exit on the menu.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  18. #18
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    OK, it's fixed now.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  19. #19
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    ok:

    VB Code:
    1. 'oh and here is the declares for the SetForegroundWindow API
    2. Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
    3.  
    4.     'I use a class for working with the tray and Ownerform is the form I used in Set_NotifyIcon or the form that I dimmed the object in
    5.     SetForegroundWindow OwnerForm.hwnd
    6.     OwnerForm.PopUpMenu Menu, flags


    I forgot where I found this, but like 3 of us at the forum went on a quest to find how to fix that and it finally came to this.

    Here is the link to the thread:

    http://www.vbforums.com/showthread.p...regroundWindow

  20. #20
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    I mean no disrespect, Edneeis, but do try the code I uploaded
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  21. #21
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I apologize Lord_Rat but I didn't mean any disrespect either. I was just answering the original question. I'm happy with the class I use and I used to have the same problem using the NotifyIcon bit until I did what I posted, so it worked for me and I'm just spreading the wealth, same as you. Although I like learning new things so I'll check out your code.

  22. #22
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Hey that is pretty cool! Thanks!

  23. #23

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    UK
    Posts
    205
    I have created a new version of the mdlSysTray.bas file. I hope you dont mind Lord_Rat. I have incorperated everything into this module, so the module can:

    -Save the systray entries
    -Restore the systray entries
    -Add to the systray
    -Modify the entire systray entry
    -Modify the icon for the systray entry
    -Modify the TTT (Tool Tip Text) for the systray entry
    -Generate a Popup menu for the systray entry
    -Dock a form to the systray
    -Restore a form from the systray

    If you think of anything else that might be usefull stick it in there too. Oh, i removed the "On Error Goto" 's because i couldnt see a use for them. If we display errors about the program crashing, the programmer will think the module caused it. I cant see how the module will cause an error, and goto's are bad practice anyways. If you can argue them back into the module go ahead and I will accept another modification.

    If you do modify the module, please re-post so I can see what benefits it gives you, and to see if i can make the module more reuseable.
    Attached Files Attached Files

  24. #24
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    I never mind better code.

    As for the on errors, I use them when debugging, but remove them before the final build.

    It's fine to remove them.

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