|
-
May 16th, 2003, 01:16 PM
#1
Thread Starter
Hyperactive Member
system tray icons\minimizing forms
don't slate me just yet, im not asking how to put an icon in the system tray.
but.. ive noticed on some programs when they are 'minimized to the system tray' the actual minimize animation points to your system tray; towards the far right of your taskbar instead of where the applications icon button resides on the taskbar. if your lost and have msn, try closing it (so it goes to the system tray) and you'll see what i mean 
anyway more to the point, i was wondering how you'd achieve this in vb? im guessing its with api or is it much simpler?
-cheers
-
May 16th, 2003, 01:41 PM
#2
Registered User
do you mean when you would click the close button on a program like kasaa
-
May 16th, 2003, 01:45 PM
#3
Registered User
put the following in a module
VB Code:
'Puts app icon in the system tray
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Public Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Type NOTIFYICONDATA
cbSize As Long
hWnd As Long
uId As Long
uFlags As Long
ucallbackMessage As Long
hIcon As Long
szTip As String * 17
End Type
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const WM_MOUSEMOVE = &H200
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_RBUTTONDBLCLK = &H206
Private Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205
Public Const WM_LBUTTONUP = &H202
Public Const SM_CXBORDER = 5 'Width of non-sizable borders
Public Const SM_CYBORDER = 6 'Height of non-sizable borders
Private SysTray As NOTIFYICONDATA
Public Sub StartInSysTray(f As Form)
SysTray.cbSize = Len(SysTray)
SysTray.hWnd = f.Picture1.hWnd
SysTray.uId = 1&
SysTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
SysTray.ucallbackMessage = WM_MOUSEMOVE
'change the below line to the desired icon
SysTray.hIcon = f.Icon
SysTray.szTip = Left$(App.Title, Len(App.Title))
Shell_NotifyIcon NIM_ADD, SysTray
End Sub
Public Sub RemoveFromSysTray(f As Form)
'Remove the icon from the system tray
SysTray.cbSize = Len(SysTray)
SysTray.hWnd = f.Picture1.hWnd
SysTray.uId = 1&
Shell_NotifyIcon NIM_DELETE, SysTray
End Sub
put the following in the form
VB Code:
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim lRet As Long
Dim lBut As Long
Dim i As Integer
'Get position of pointer.
lBut = x / Screen.TwipsPerPixelX
'Determine which mouse button clicked.
If lBut = WM_RBUTTONUP Then
'If right button determine if the app is visible.
If Me.Visible Then
'If the app is visible hide the restore option
With mnuFileSub
For i = .LBound To .UBound
If .Item(i).Caption = "&Restore" Then
.Item(i).Visible = False
Else
.Item(i).Visible = True
End If
Next i
End With
Else
'If the app isn't visible show the restore option.
With mnuFileSub
For i = .LBound To .UBound
Select Case .Item(i).Caption
Case "&Restore"
.Item(i).Visible = True
Case "&Quit"
.Item(i).Visible = True
Case "&About"
.Item(i).Visible = True
End Select
Next i
End With
End If
'Following API call is used for it mouse pointer is not
'over the icon in the system tray and the popup menu is
'displayed so that it will be hidden if the pointer is
'clicked anywhere else.
lRet = SetForegroundWindow(Me.hWnd)
'Display the popup menu for restoring or
'ending the app.
PopupMenu mnuFile
ElseIf lBut = WM_LBUTTONUP Then
'If a singl left mouse button click restore
'the app.
Call mnuFileSub_Click(1)
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Set to one so form can't close until bClose is True.
Cancel = 1
If bClose Then
'Remove the icon from the system tray.
Call RemoveFromSysTray(Me)
'Set to zero to end the app.
Cancel = 0
'Re-allocate memory.
Set frmRefresher = Nothing
Else
Me.WindowState = vbMinimized
DoEvents
'If the close button (X) is pressed.
Me.Hide
bClose = False
Exit Sub
End If
End Sub
Private Sub Form_Load()
'Put icon in system tray.
Call StartInSysTray(Me)
End Sub
hope this helps
-
May 16th, 2003, 01:57 PM
#4
Registered User
if you would like you can go to this thread i made two days ago and download that code and program that is there and take a look at to get an ideahttp://www.vbforums.com/showthread.p...hreadid=245058
-
May 17th, 2003, 05:47 AM
#5
Thread Starter
Hyperactive Member
cheers m8, but ive already got an icon in the system tray.
its when you minimize a window the menubar of the window actually floats down to the taskbar and on some programs it floats down towards the far right of the taskbar > over the system tray. i dont think you know what i mean lol, tis hard to explain
-
May 17th, 2003, 06:51 AM
#6
Hyperactive Member
Well
I think i got what u mean.
Well, what you're trying to do cannot be done in VB. I mean you cannot point the minimize animation to the tray. On the other hand, this is what you can do:
In the tray code, you'll find somewhere something like:
form1.WindowState = vbMinimized
form1.Hide or form1.Visible = False
Then elsewhere:
form1.Show or form1.Visible = True
form1.WindowState = vbNormal or vbMaximized.
Try removing the the (form1.WindowState = vbMinimized) and the (form1.WindowState = vbNormal or vbMaximized) statements.
This may sometimes cause a focus problem with the form. If so, use this code when showing it out of the tray:
form1.Show
form1.SetFocus
Well, this is what i do when i don't want animation into the taskbar. It's the minimze action that's casuing it.
And by the way, as far as MSN, i think they're using the same approach, because i didn't notice any animation at all (this is what the code i proposed do, it cancels the animation part).
HTH
"And Now I'm Lika Major Threat, Cause I Remind U Of The Things U Were Made To Forget!" - (2PAC)
"Now They Label Me a Lunatic, Couldn't Care Less, Death or Success is What I Quest, Cause I'm Fearless!" - (2PAC)
" There's a light at the end of every tunnel, just pray it's not a train!! "
I am 100% addicted to Tupac. What about you?
I am 24% addicted to Counterstrike. What about you?
The #1 Tupac Fans Web Site | The Official Tupac Web Site
-
Jun 4th, 2003, 12:00 AM
#7
Member
Virus, in your vb code, in the Form_Unload event, when is bClose set to True? Or is it never gonna be set to true?
And is calling the DoEvents() function really needeD?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|