[VB6][Help] Minimizing Icon to SysTray - Icon Missing?

Evil Scottish Overlord
Legend
Joined
May 18, 2007
Messages
5,847
Reaction score
5,254
Hey,

I saw the Tutorial on this and I followed it but my brother told me it's VB.Net and Im using Visual Basic 6. I found a code from elsewhere but when I minimize the program into the SysTray the icon doesn't appear. I'll post both the Module code and form code...

Module code:

Code:
Declare Function Shell_NotifyIcon Lib "shell32.dll" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
'If you get an error message at the beginning of the program,
'use the declaration below:
'Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias " Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long

'These three constants specify what you want to do
Public Const NIM_ADD = &H0
Public Const NIM_DELETE = &H2
Public Const NIM_MODIFY = &H1

Public Const NIF_ICON = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_TIP = &H4

Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_MOUSEMOVE = &H200
Public Const WM_RBUTTONDBLCLK = &H206
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205

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

Form code:

Code:
Private Sub frmMain_Activate()
Call Shell_NotifyIcon(NIM_ADD, IconData)
'this is an option to show icon without minimizing the form
End Sub

Private Sub Form_Resize()
'this is the option to show icon on minimizing the form
If Me.WindowState = 1 Then
'The user has minimized his window

'Call Shell_NotifyIcon(NIM_ADD, IconData)

' Add the form's icon to the tray

Me.Hide

' Hide the button at the taskbar

End If

End Sub

Private Sub frmMain_Load()

With IconData

.cbSize = Len(IconData)
' The length of the NOTIFYICONDATA type

.hIcon = Me.Icon
' A reference to the form's icon

.hwnd = Me.hwnd
' hWnd of the form

.szTip = "My Tooltip" & Chr(0)
' Tooltip string delimited with a null character

.uCallbackMessage = WM_MOUSEMOVE
' The icon we're placing will send messages to the MouseMove event

.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
' It will have message handling and a tooltip

.uID = vbNull
' uID is not used by VB, so it's set to a Null value

End With

End Sub

Private Sub mnuExit_Click()

Unload Me
' Unload the form

End
' Just to be sure the program has ended

End Sub

Private Sub mnuShow_Click()

Me.WindowState = vbNormal
Shell_NotifyIcon NIM_DELETE, IconData
Me.Show

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim Msg As Long

Msg = X
' The message is passed to the X value

' You must set your form's ScaleMode property to pixels in order to get the correct message

If Msg = WM_LBUTTONDBLCLK Then
' The user has double-clicked your icon

Call mnuShow_Click
' Show the window

ElseIf Msg = WM_RBUTTONDOWN Then
' Right-click

PopupMenu mnuPopup
' Popup the menu

End If

End Sub

Private Sub frmMain_Unload(Cancel As Integer)

Shell_NotifyIcon NIM_DELETE, IconData

End Sub

Can you help me find the problem?

Thanks :)

Shizzle,
Laz-low
 
Back