CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2000
    Posts
    9

    System tray menu

    I've created a test application that sits in the system tray, when the icon in the tray is right-clicked a menu will pop up.

    But the problem is .. the menu responds to mouse events but not keypress ... like 'Esc'.

    Btw, the main form(menu owner is set to invisible)


    The code portion is as below :


    private Sub Form_Load()
    With nid
    .cbSize = len(nid)
    .hwnd = frmMain.hwnd
    .uId = vbNull
    .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    .uCallBackMessage = WM_MOUSEMOVE
    .szTip = "Right click to display menu" & vbNullChar
    .hIcon = frmMain.Icon
    End With

    Shell_NotifyIcon NIM_ADD, nid
    End Sub

    private Sub Form_MouseMove(Button as Integer, Shift as Integer, X as Single, Y as Single)
    Dim Result as Long
    Dim msg as Long

    If me.ScaleMode = vbPixels then
    msg = X
    else
    msg = X / Screen.TwipsPerPixelX
    End If

    Select Case msg

    Case 517 'display menu
    SetForegroundWindow (me.hwnd)'set window as top, still cant respond to key
    me.PopupMenu menuMyMenu

    Case 514
    'Some code
    End Select
    End Sub







    Pls help. Thank you.
    Vincent



  2. #2
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: System tray menu

    i don't think it is possible to trap key press when you app is sitting on the systray without any of it's form visible.

    The only way that I can think of is to HOOK to WM_ messages especially the keyboard state. I've seen a lot of codes regarding the HOOK in this forum. You should be able to search for it.

    Just an idea-
    Cool Bizs

    Good Luck,
    -Cool Bizs

  3. #3
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: System tray menu

    I have written a DLL that implements low level hooks (like keyboard, mouse etc.) in a safe and easy to use wrapper.
    Drop me a "private message" with your email and I'll send it to you.

    There is also a little "fudge" which is to have a form in your app which is one pixel big and set that to be the foreground window before showng the menu...it will then get keyboard events if you have its "KeyPreview" set to True.

    HTH,
    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

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

Featured