|
|
|
|
![]() ![]() |
Feb 10 2005, 04:53 PM
Post
#1
|
|
|
Member [Level 2] ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 81 Joined: 3-August 04 Member No.: 609 |
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.
For this example you'll need: 1 Form - Form1 1 button - Command1 Add a Module to your project, and ad this code: 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 Now at Form1 add this: CODE Code: 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 Instead of restore it when you click the tray icon, you can make it show a popup with some actions: maximize/close//about//etc! |
|
|
|
Dec 11 2007, 04:26 AM
Post
#2
|
|
|
Trap Double Mocha Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 2,360 Joined: 21-September 07 Member No.: 50,369 |
AWESOME MAN, thank you for the help. FAR simpler then any other examples.
-Adam |
|
|
|
Dec 25 2007, 05:14 PM
Post
#3
|
|
|
Trap Double Mocha Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 2,360 Joined: 21-September 07 Member No.: 50,369 |
Error%20%5C%22Invalid%20use%20of%20property%5C%22
[tutorial] Visual Basic 6 Minimize To Tray Hello, When I try this solution, I have error "Invalid use of property" on instruction minimize_to_tray. Do you have a solution ? Thanks & regards. -Marcel |
|
|
|
Apr 8 2008, 06:49 PM
Post
#4
|
|
|
Trap Double Mocha Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 2,360 Joined: 21-September 07 Member No.: 50,369 |
Great! Thank you for wonderful code.
-reply by Zoran Milobratović |
|
|
|
Jul 4 2008, 07:04 AM
Post
#5
|
|
|
Trap Double Mocha Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 2,360 Joined: 21-September 07 Member No.: 50,369 |
Great Work
[tutorial] Visual Basic 6 Minimize To Tray This was exactly what I was looking for. Works great -reply by fourtwunty |
|
|
|
Aug 29 2008, 08:14 PM
Post
#6
|
|
|
Trap Double Mocha Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 2,360 Joined: 21-September 07 Member No.: 50,369 |
some problems
[tutorial] Visual Basic 6 Minimize To Tray Hello.. If this script is nice.. But if I make a new project with simple button and a form for the testing of that code.. It works great, but if I integrate it to my project.. It doesn't work.. Any one would try to help me... Thx.. -reply by pols_1226 |
|
|
|
Aug 29 2008, 08:17 PM
Post
#7
|
|
|
Trap Double Mocha Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 2,360 Joined: 21-September 07 Member No.: 50,369 |
problem
[tutorial] Visual Basic 6 Minimize To Tray Replying to iGuest Hello.. If this script is nice.. But if I make a new project with simple button and a form for the testing of that code.. It works great, but if I integrate it to my project.. It doesn't work.. Any one would try to help me... Thx.. -reply by pols_1226 |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 8th September 2008 - 12:57 AM |