Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System Tray

Status
Not open for further replies.

Vec

IS-IT--Management
Jan 29, 2002
418
US
I need to make a form minimize to the sys tray and disappear from the task bar, when the user double or single clicks (either one) on the sys tray icon, the form shows and the sys tray icon disappears.

It is for an mp3 player I am working on, it is only one form so hopefully it isn't to hard to do this. The form name is frmPlayer -
radium.gif

Looking Toward The Future
 
DO the following steps:

'Insert one Form And Menu Named mPopupSys


'IN FORM Load Event


Private Sub Form_Load()

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 = "Smaller one" & vbNullChar
End With

Shell_NotifyIcon NIM_MODIFY, nid

End Sub

'---------------------------------------------------------------------------------------------------------------

'In Form Mouse_Move event insert following code

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'this procedure receives the callbacks from the System Tray icon.
Dim result As Long
Dim msg As Long
'the value of X will vary depending upon the scalemode setting
If Me.WindowState <> vbMinimized Then Exit Sub
msg = X / Screen.TwipsPerPixelX

Select Case msg
' Case WM_LBUTTONUP '514 restore form window
' Me.WindowState = vbNormal
' Result = SetForegroundWindow(Me.hwnd)
' Me.Show
Case WM_LBUTTONDBLCLK '515 restore form window
Me.WindowState = vbNormal
result = SetForegroundWindow(Me.Hwnd)
Me.Show
Case WM_RBUTTONUP '517 display popup menu
result = SetForegroundWindow(Me.Hwnd)
Me.PopupMenu Me.mPopupSys
End Select
End Sub

'---------------------------------------------------------------------------------------------------------------

'Define One Module Named as modData and Insert Following code in it

'user defined type required by Shell_NotifyIcon API call

Option Explicit

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 Declare Function SetForegroundWindow Lib &quot;user32&quot; _
(ByVal Hwnd As Long) As Long
Public Declare Function Shell_NotifyIcon Lib &quot;shell32&quot; _
Alias &quot;Shell_NotifyIconA&quot; _
(ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean

Public nid As NOTIFYICONDATA

Public Const GW_HWNDPREV = 3
Public Declare Function SendMessage Lib &quot;user32&quot; Alias &quot;SendMessageA&quot; (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Declare Function OpenIcon Lib &quot;user32&quot; (ByVal Hwnd As Long) As Long
Declare Function FindWindow Lib &quot;user32&quot; Alias &quot;FindWindowA&quot; _
(ByVal lpClassName As String, ByVal lpWindowName As String) _
As Long
Declare Function GetWindow Lib &quot;user32&quot; _
(ByVal Hwnd As Long, ByVal wCmd As Long) As Long


Sub ActivatePrevInstance()
Dim OldTitle As String
Dim PrevHndl As Long
Dim result As Long

'Save the title of the application.
OldTitle = App.Title

'Rename the title of this application so FindWindow
'will not find this application instance.
App.Title = &quot;unwanted instance&quot;

'Attempt to get window handle using VB4 class name.
PrevHndl = FindWindow(&quot;ThunderRTMain&quot;, OldTitle)

'Check for no success.
If PrevHndl = 0 Then
'Attempt to get window handle using VB5 class name.
PrevHndl = FindWindow(&quot;ThunderRT5Main&quot;, OldTitle)
End If

'Check if found
If PrevHndl = 0 Then
'Attempt to get window handle using VB6 class name
PrevHndl = FindWindow(&quot;ThunderRT6Main&quot;, OldTitle)
End If

'Check if found
If PrevHndl = 0 Then
'No previous instance found.
Exit Sub
End If

'Get handle to previous window.
PrevHndl = GetWindow(PrevHndl, GW_HWNDPREV)

'Restore the program.
result = OpenIcon(PrevHndl)

'Activate the application.
result = SetForegroundWindow(PrevHndl)

'End the application.
End
End Sub

'If this doesn't work mail me at dhiraj_patil@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top