Results 1 to 4 of 4

Thread: Grrrr... please help

  1. #1

    Thread Starter
    Member
    Join Date
    May 2000
    Posts
    43

    Angry

    I have been trying to learn from other peoples code, except whenever it is to do with puttin icons in the systray i always get errors!
    I have found the peice of code causing the problem (btw the error is with vb not the code!)


    MultiUse = -1 'True
    Persistable = 0 'NotPersistable
    DataBindingBehavior = 0 'vbNone
    DataSourceBehavior = 0 'vbNone"
    MTSTransactionMode = 0 'NotAnMTSObject"
    End

    This is the code that vb doesnt like, could it be to do with using vb5??? btw this code is in a class module!!! is there anything i can do about this, as it is REALLY buggin me! if it is about usin vb5 is there anthing that can be done about it, except buyin vb6 (i got no money :o(((( )
    Thanx
    Cease

  2. #2
    Registered User Lior's Avatar
    Join Date
    Jan 2000
    Posts
    307

    Talking search this site

    Man...
    I am sure I saw sometime ON THIS SITE an article about placing an icon on the system tray.
    I think I saw it in the Tips & Tricks section, and if I'm not mistaken, Sam Huggill wrote it.

    just search over the site, and I'm sure you'll finally find it. the key is really just behind your back.

  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    Without knowing what code you're using to do the whole procedure it's tough to know what is cusing the problem, here's some very simple code for adding an Icon to the System Tray, I even documented it for you:

    Add a Picturebox to a Form and setup an Invisible Menu called mnuPopup with 2 subitems called, mnuShow and mnuExit, then paste the following code into the Forms Code Module:
    Code:
    Private 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
    
    Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
    
    Private Const NIF_ICON = &H2
    Private Const NIF_MESSAGE = &H1
    Private Const NIF_TIP = &H4
    Private Const NIM_ADD = &H0
    Private Const NIM_DELETE = &H2
    Private Const WM_MOUSEMOVE = &H200
    Private Const WM_RBUTTONUP = &H205
    Private Const WM_LBUTTONDBLCLK = &H203
    Private Const WM_LBUTTONDOWN = &H201
    Private Const WM_LBUTTONUP = &H202
    
    Private tTrayIcon As NOTIFYICONDATA
    
    Private Sub Form_Load()
        Picture1.Visible = False
        'Create a System Tray Icon
        With tTrayIcon
            'Set the Handle to the Icon you want to Display
            'This could be any Icon, for this example I'm using
            'The Icon assigned to the "Icon" Property of the Form.
            .hIcon = Icon
            'Tray Icon Messages are ReRouted to a Window Handle of
            'Your choice, typically it's wise to use a Picturebox
            'For this purpose.
            .hwnd = Picture1.hwnd
            'Set the "ToolTip" Caption that will Appear
            .szTip = Caption & Chr(0)
            'Set the Message used when Redirecting to the Specified
            'Window Handle
            .uCallbackMessage = WM_MOUSEMOVE
            'Set the Flags to add an Icon, ToolTip and Callback Message
            .uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
            'Give the Icon a Unique ID, (This is unique to this Thread/App)
            .uID = 1
            'Set the Size of this Structure
            .cbSize = Len(tTrayIcon)
        End With
        'Add the Icon to the System Tray
        Shell_NotifyIcon NIM_ADD, tTrayIcon
    End Sub
    
    Private Sub Form_Resize()
        'Don't show the Form in the Taskbar when Minimized
        If WindowState = vbMinimized Then
            Hide
            WindowState = vbNormal
        End If
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        'Remove the System Tray Icon when the Form Unloads
        Shell_NotifyIcon NIM_DELETE, tTrayIcon
    End Sub
    
    Private Sub mnuExit_Click()
        'Unload the Form from the "Exit" PopupMenu Option
        Unload Me
    End Sub
    
    Private Sub mnuShow_Click()
        'Show the Form from the "Show" PopupMenu Option
        Show
    End Sub
    
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        'This is the Event that's passed the Callback Message Data
        'From the SystemTray Icon
        Select Case ScaleX(X, vbTwips, vbPixels)
        Case WM_LBUTTONDBLCLK
            'Double Click on SysTray Icon to Show Form
            Show
        Case WM_RBUTTONUP
            'Used for Displaying a Popup Menu
            Me.PopupMenu mnuPopup
        End Select
    End Sub

  4. #4

    Thread Starter
    Member
    Join Date
    May 2000
    Posts
    43

    Talking Thanx

    Thanx this has helped my understand using the system tray much more :o)
    Thanx
    Cease

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