Jump to content
xisto Community
zachtk8702

[tutorial] Visual Basic 6 Minimize To Tray Minimize to Tray

Recommended Posts

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:

' Create an Icon in System Tray NeedsPublic Type NOTIFYICONDATAcbSize As Longhwnd As LonguId As LonguFlags As LonguCallBackMessage As LonghIcon As LongszTip As String * 64End TypePublic Const NIM_ADD = &H0Public Const NIM_MODIFY = &H1Public Const NIM_DELETE = &H2Public Const WM_MOUSEMOVE = &H200Public Const NIF_MESSAGE = &H1Public Const NIF_ICON = &H2Public Const NIF_TIP = &H4Public Const WM_LBUTTONDBLCLK = &H203 'Double-clickPublic Const WM_LBUTTONDOWN = &H201 'Button downPublic Const WM_LBUTTONUP = &H202 'Button upPublic Const WM_RBUTTONDBLCLK = &H206 'Double-clickPublic Const WM_RBUTTONDOWN = &H204 'Button downPublic Const WM_RBUTTONUP = &H205 'Button upPublic Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Now at Form1 add this:
Code:Dim nid As NOTIFYICONDATA ' trayicon variable'----------------------'--- command1 click ---'----------------------Private Sub Command1_Click()minimize_to_trayEnd Sub'------------------------'--- create tray icon ---'------------------------Sub minimize_to_tray()Me.Hidenid.cbSize = Len(nid)nid.hwnd = Me.hwndnid.uId = vbNullnid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGEnid.uCallBackMessage = WM_MOUSEMOVEnid.hIcon = Me.Icon ' the icon will be your Form1 project iconnid.szTip = "blablabla text u want to show when mouse over tray iicon" & vbNullCharShell_NotifyIcon NIM_ADD, nidEnd 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 LongDim sFilter As Stringmsg = x / Screen.TwipsPerPixelXSelect Case msgCase WM_LBUTTONDOWNMe.Show ' show formShell_NotifyIcon NIM_DELETE, nid ' del tray iconCase WM_LBUTTONUPCase WM_LBUTTONDBLCLKCase WM_RBUTTONDOWNCase WM_RBUTTONUPMe.ShowShell_NotifyIcon NIM_DELETE, nidCase WM_RBUTTONDBLCLKEnd SelectEnd Sub'------------------------------'--- form Actions On unload ---'------------------------------Private Sub Form_Unload(Cancel As Integer)Shell_NotifyIcon NIM_DELETE, nid ' del tray iconend 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!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Great Work

[tutorial] Visual Basic 6 Minimize To Tray

 

This was exactly what I was looking for. Works great

 

-reply by fourtwunty

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

<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

Share this post


Link to post
Share on other sites

Nice tutorialThis works fine with me.@allYou will NOT just copy paste the codes, you need to understand in order to suite it in your project...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.