systray question


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: systray question

  1. #1
    Join Date
    Jun 2004
    Posts
    16

    systray question

    i want to make it so that when the user MINIMIZE the form..it goes on the systray(a icon next to the clock on lower right)

    and doesn't show in taskbar....

    but...i also wanna make it so that user can RIGHT click on the icon and select things...

    i can do al that so far....
    but the problem i am having is


    being able to have SUB MENU's in the systray icon..for example...user right click's on the icon and gets a menu...how do i have a sub menu on the menu like..

    Menu = open or exit

    how do i make it so that when they click on OPEN it opens another menu whcih lets them pick other options...

    so to sum up..how to have SUB MENU in systray icons...

    please help...thanks

  2. #2
    Join Date
    Apr 2004
    Posts
    50
    In order to have a menu on systray you should create a ContextMenu component, use it as usual menu e.g. you can add as many menu items or submenus as you want
    After that use contextMenu property of your NotifyIcon like this

    NotifyIcon1.contextMenu = ContextMenu1

    and then simply write handlers for appropriate menu items of your context menus

  3. #3
    Join Date
    Dec 2003
    Posts
    2,750

  4. #4
    Join Date
    Feb 2004
    Location
    Colton, CA
    Posts
    550
    This code in a module:

    '************************************************
    Public Type NOTIFYICONDATA
    cbSize As Long
    hwnd As Long
    uId As Long
    uFlags As Long
    uCallBackMessage As Long
    hIcon As Long
    szTip As String * 64
    End Type
    '************************************************
    'constants required by Shell_NotifyIcon API call:
    '************************************************
    Public Const NIM_ADD = &H0
    Public Const NIM_MODIFY = &H1
    Public Const NIM_DELETE = &H2
    Public Const NIF_MESSAGE = &H1
    Public Const NIF_ICON = &H2
    Public Const NIF_TIP = &H4
    Public Const WM_MOUSEMOVE = &H200
    Public Const WM_LBUTTONDOWN = &H201 'Button down
    Public Const WM_LBUTTONUP = &H202 'Button up
    Public Const WM_LBUTTONDBLCLK = &H203 'Double-click
    Public Const WM_RBUTTONDOWN = &H204 'Button down
    Public Const WM_RBUTTONUP = &H205 'Button up
    Public Const WM_RBUTTONDBLCLK = &H206 'Double-click

    Public nid As NOTIFYICONDATA
    '************************************************

    Code in main form load event:

    With nid
    .cbSize = Len(nid)
    .hwnd = Me.hwnd
    .uId = vbNull
    .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    .uCallBackMessage = WM_MOUSEMOVE
    .hIcon = Me.Icon
    .szTip = PM_log2.Caption & vbNullChar *** Change this bit ***
    End With
    Shell_NotifyIcon NIM_ADD, nid

    In form_mousemove:

    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 WM_LBUTTONUP
    Me.WindowState = vbNormal
    Result = SetForegroundWindow(Me.hwnd)
    Me.Show
    Case WM_LBUTTONDBLCLK
    Me.WindowState = vbNormal
    Result = SetForegroundWindow(Me.hwnd)
    Me.Show
    Case WM_RBUTTONUP
    Result = SetForegroundWindow(Me.hwnd)
    Me.PopupMenu Me.mPopupSys
    End Select

    End Sub

    in form_resize

    Private Sub Form_Resize()
    If Me.WindowState = vbMinimized Then Me.Hide
    End Sub

    in 'Terminate'

    Shell_NotifyIcon NIM_DELETE, nid

    and a menu which is hidden

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center