How can I minimize a Form to the systemtray by
clicking on a command button ?
[Edited by Kars Lensen on 07-11-2000 at 01:36 PM]
Printable View
How can I minimize a Form to the systemtray by
clicking on a command button ?
[Edited by Kars Lensen on 07-11-2000 at 01:36 PM]
See..the post above you..re: system icon bla bla
Change the mouse event to this..
you could put it into a cmdButton as well but
you need all except for the popup menu junk
and the msgbox...I'm sure you get the drift
Code:minimze by clicking the icon in the system tray.
Private Sub picSysTray_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'You can use the Hex of the X coord to findout if
'there was any MouseButton activity
'2D represents a Left Button Double Click
'0F represents mouse down (zero)
'1E represents mouse up
If Right(Hex(x), 2) = "0F" Then
'System tray Icon Double Clicked
'If the Window is Minimized, Restore it,
'Else Minimize it.
WindowState = IIf(WindowState = vbNormal, vbMinimized, vbNormal)
Text1.SetFocus
End If
End Sub
here is the complete thing..sorry the boss was coming
around the corner so I rushed my last post...Code:
Option Explicit
' Constants required by Shell_NotifyIcon API call
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const WM_MOUSEMOVE = &H200
Private Const WM_LBUTTONDOWN = &H201 'Button down
Private Const WM_LBUTTONUP = &H202 'Button up
Private Const WM_LBUTTONDBLCLK = &H203 'Double-click
Private Const WM_RBUTTONDOWN = &H204 'Button down
Private Const WM_RBUTTONUP = &H205 'Button up
Private Const WM_RBUTTONDBLCLK = &H206 'Double-click
'API call
Private Declare Function SetForegroundWindow Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function Shell_NotifyIcon Lib "shell32" _
Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2
'variable declaration
Private nid As NOTIFYICONDATA
'Show form icon in system tray
' User defined type required by Shell_NotifyIcon API call
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 Sub Form_Load()
Me.Show
Me.Refresh
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 = App.ProductName & " " & App.Major & "." & App.Minor & ", Build " & App.Revision & vbNullChar
End With
Shell_NotifyIcon NIM_ADD, nid
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'You can use the Hex of the X coord to findout if
'there was any MouseButton activity
'2D represents a Left Button Double Click
'0F represents mouse down (zero)
'1E represents mouse up
If Right(Hex(X), 2) = "0F" Then
'System tray Icon Double Clicked
'If the Window is Minimized, Restore it,
'Else Minimize it.
WindowState = IIf(WindowState = vbNormal, vbMinimized, vbNormal)
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
' Remove Icon from System Tray
'if you use another unload put this there as well
Shell_NotifyIcon NIM_DELETE, nid
End Sub
Thanks, but how do i this with me commandbutton ?
You can not minimize anything to system tray, if you say minimize it will probably go under the taskbar, in your command button, put
where yourform is your forms nameCode:yourform.windowstate=vbminimized
Thanks Kedeman, thats what I want.. (of course, it would be nice if it was just a small icon in the system tray but I am satisfied this far)Quote:
Originally posted by kedaman
You can not minimize anything to system tray, if you say minimize it will probably go under the taskbar, in your command button, put
where yourform is your forms nameCode:yourform.windowstate=vbminimized
THANKS to ALL of you !! It works fine now.
i do the samething. that the code i put.
Private Sub Form_Resize()
If Me.WindowState = vbMinimized Then
Me.Visible = False
End If
End Sub
and when i click on my icontray
Private Sub Tray1_DblClick(ByVal Button As Long)
Me.Visible = True
End Sub
But the problem is when i dblClik on the icon my form appear like 1 sec in the windowsBar and dessapear after...I cant see my form.
What is the problem?
Sorry for my english.
Im not exactly sure what's happening but I think something similar has happened to me before. If you double click, I think your form gains focus and then loses focus again to the icon. That's what I've been assuming but I really don't know how to fix it. Try, adding me.setfocus in the tray doubleclick event.
Ok, i gonna try something else. if i found the answer i come back to post it. thanksQuote:
Originally posted by Jimlin41
Im not exactly sure what's happening but I think something similar has happened to me before. If you double click, I think your form gains focus and then loses focus again to the icon. That's what I've been assuming but I really don't know how to fix it. Try, adding me.socus in the tray doubleclick event.
dear mags,
simple question simple answer ...
When you maximize the form, it also runs the resize code ...
Maximazing is also a way of resizing !!!