Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
MINIMIZED APP TO SYSTEM TRAY
Author:
Dhrubajyoti Nath
E-mail:
Click to e-mail author
Submitted:
6/27/2009
Version:
VB6
Compatibility:
VB6
Category:
Windows API
Views:
13822
This example will "minimize" your program to the system tray when you click on a button, and restore it when you click the system tray icon.
Declarations:
'For this example you'll need: '1 .bas Module '1 Form - Form1 '1 button - Command1 'Add a Module to your project, and ad this code: ' Create an Icon in System Tray Needs 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 Public Const NIM_ADD = &H0 Public Const NIM_MODIFY = &H1 Public Const NIM_DELETE = &H2 Public Const WM_MOUSEMOVE = &H200 Public Const NIF_MESSAGE = &H1 Public Const NIF_ICON = &H2 Public Const NIF_TIP = &H4 Public Const WM_LBUTTONDBLCLK = &H203 'Double-click Public Const WM_LBUTTONDOWN = &H201 'Button down Public Const WM_LBUTTONUP = &H202 'Button up Public Const WM_RBUTTONDBLCLK = &H206 'Double-click Public Const WM_RBUTTONDOWN = &H204 'Button down Public Const WM_RBUTTONUP = &H205 'Button up Public Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Code:
'Now at Form1 add this: Dim nid As NOTIFYICONDATA ' trayicon variable '---------------------- '--- command1 click --- '---------------------- Private Sub Command1_Click() minimize_to_tray End Sub '------------------------ '--- create tray icon --- '------------------------ Sub minimize_to_tray() Me.Hide nid.cbSize = Len(nid) nid.hwnd = Me.hwnd nid.uId = vbNull nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE nid.uCallBackMessage = WM_MOUSEMOVE nid.hIcon = Me.Icon ' the icon will be your Form1 project icon nid.szTip = "blablabla text u want to show when mouse over tray iicon" & vbNullChar Shell_NotifyIcon NIM_ADD, nid End Sub '--------------------------------------------------- '-- Tray icon actions when mouse click on it, etc -- '--------------------------------------------------- Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single) Dim msg As Long Dim sFilter As String msg = x / Screen.TwipsPerPixelX Select Case msg Case WM_LBUTTONDOWN Me.Show ' show form Shell_NotifyIcon NIM_DELETE, nid ' del tray icon Case WM_LBUTTONUP Case WM_LBUTTONDBLCLK Case WM_RBUTTONDOWN Case WM_RBUTTONUP Me.Show Shell_NotifyIcon NIM_DELETE, nid Case WM_RBUTTONDBLCLK End Select End Sub '------------------------------ '--- form Actions On unload --- '------------------------------ Private Sub Form_Unload(Cancel As Integer) Shell_NotifyIcon NIM_DELETE, nid ' del tray icon end Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement