IPB

Welcome Guest ( Log In | Register )



Tags
This content has not been tagged yet

[tutorial] Visual Basic 6 Minimize To Tray

, Minimize to Tray


Rating 4 V
zachtk8702
no avatar
Member [Level 2]
*****
Group: Members
Posts: 81
Joined: 3-August 04
Member No.: 609



Post #1 post Feb 10 2005, 04:53 PM
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!
Go to the top of the page
+Quote Post
 
Start new topic
Replies (1 - 9)
iGuest
no avatar
Hail Caesar!
*********************
Group: Members
Posts: 5,876
Joined: 21-September 07
Member No.: 50,369



Post #2 post Dec 11 2007, 04:26 AM
AWESOME MAN, thank you for the help. FAR simpler then any other examples.

-Adam
Go to the top of the page
+Quote Post
iGuest
no avatar
Hail Caesar!
*********************
Group: Members
Posts: 5,876
Joined: 21-September 07
Member No.: 50,369



Post #3 post Dec 25 2007, 05:14 PM
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
Go to the top of the page
+Quote Post
iGuest
no avatar
Hail Caesar!
*********************
Group: Members
Posts: 5,876
Joined: 21-September 07
Member No.: 50,369



Post #4 post Apr 8 2008, 06:49 PM
Great! Thank you for wonderful code.

-reply by Zoran Milobratović
Go to the top of the page
+Quote Post
iGuest
no avatar
Hail Caesar!
*********************
Group: Members
Posts: 5,876
Joined: 21-September 07
Member No.: 50,369



Post #5 post Jul 4 2008, 07:04 AM
Great Work
[tutorial] Visual Basic 6 Minimize To Tray

This was exactly what I was looking for. Works great

-reply by fourtwunty
Go to the top of the page
+Quote Post
iGuest
no avatar
Hail Caesar!
*********************
Group: Members
Posts: 5,876
Joined: 21-September 07
Member No.: 50,369



Post #6 post Aug 29 2008, 08:14 PM
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
Go to the top of the page
+Quote Post
iGuest
no avatar
Hail Caesar!
*********************
Group: Members
Posts: 5,876
Joined: 21-September 07
Member No.: 50,369



Post #7 post Aug 29 2008, 08:17 PM
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
Go to the top of the page
+Quote Post
iGuest
no avatar
Hail Caesar!
*********************
Group: Members
Posts: 5,876
Joined: 21-September 07
Member No.: 50,369



Post #8 post Sep 11 2008, 04:43 AM
Hi, I have a question~

I created a flash file and I connected in vb through shockwave flash.
What I did was, I put in a maximized state so that once I run it, it appears in a maximized state but when I click the restore down button, It only showed the half part of the form and there's no scrollbar to drag for me to be able to see the other contents of the from~What shall I do?Pleas, I need your help.~thanks in advance~

God Bless~

-reply by Harez
Go to the top of the page
+Quote Post
Evolix
no avatar
Advanced Member
*******
Group: [HOSTED]
Posts: 135
Joined: 14-October 08
Member No.: 69,728
myCENT:NEGATIVE[-57.75]



Post #9 post Oct 18 2008, 01:07 PM
What about the icon in the tray, can you change it or what?
Go to the top of the page
+Quote Post
jason8100
no avatar
Newbie
*
Group: Members
Posts: 1
Joined: 19-May 09
From: The Netherlands,Eibergen
Member No.: 82,125



Post #10 post May 21 2009, 06:12 PM
QUOTE (Evolix @ Oct 18 2008, 03:07 PM) *
<br />What about the icon in the tray, can you change it or what?<br />
the icon in the tray is the same as the icon on your form in the left corner, so if you change the icon of the form by selecting your form and select icon and choose one.
i hope i helped you and sorry for my bad english i am dutch and 13 years old
Go to the top of the page
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   0 Albus Dumbledore 2,769 18th June 2006 - 08:28 AM
Last post by: Albus Dumbledore
No New Posts   9 noxit 7,498 30th July 2004 - 02:57 PM
Last post by: templest
No new   32 ultrasmad 22,295 14th February 2005 - 11:01 AM
Last post by: Someone
No new   16 ultrasmad 12,293 21st May 2005 - 10:04 AM
Last post by: alexia
No New Posts   3 ultrasmad 6,548 30th July 2004 - 03:27 PM
Last post by: templest
No new   22 Shackman 37,780 27th October 2009 - 07:39 AM
Last post by: NxTGaming
No new   39 Bash 40,028 28th May 2009 - 01:47 AM
Last post by: nol
No New Posts   0 Jarlaxe 1,547 23rd June 2007 - 11:13 AM
Last post by: Jarlaxe
No New Posts   0 etycto 853 2nd September 2007 - 09:43 PM
Last post by: etycto
No New Posts   10 neeki4444 13,358 12th February 2009 - 08:32 AM
Last post by: iG-AeRo
No New Posts   7 truvu17 8,283 1st May 2006 - 03:20 PM
Last post by: shadowx
No New Posts   1 NeXDesigns 5,043 16th September 2004 - 07:46 PM
Last post by: ipunto21
No New Posts   7 NeXDesigns 4,664 30th September 2004 - 01:16 PM
Last post by: Amorphia
No New Posts   0 Zenchi 3,531 28th September 2004 - 03:35 AM
Last post by: Zenchi
No New Posts   3 X3r0X 5,336 28th September 2004 - 02:30 PM
Last post by: X3r0X


 



RSS Open Discussion Time is now: 26th November 2009 - 06:04 PM

Web Hosting Powered by ComputingHost.com. Xisto.com : Honesty ROCKS! Truth Rules.