zachtk8702 0 Report post Posted February 10, 2005 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 - Form11 button - Command1Add 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 BooleanNow 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
iGuest 3 Report post Posted December 11, 2007 AWESOME MAN, thank you for the help. FAR simpler then any other examples.-Adam Share this post Link to post Share on other sites
iGuest 3 Report post Posted December 25, 2007 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
iGuest 3 Report post Posted April 8, 2008 Great! Thank you for wonderful code.-reply by Zoran MilobratoviÄ? Share this post Link to post Share on other sites
iGuest 3 Report post Posted July 4, 2008 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
iGuest 3 Report post Posted August 29, 2008 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
iGuest 3 Report post Posted August 29, 2008 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
iGuest 3 Report post Posted September 11, 2008 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
Evolix 1 Report post Posted October 18, 2008 What about the icon in the tray, can you change it or what? Share this post Link to post Share on other sites
jason8100 0 Report post Posted May 21, 2009 <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
iGuest 3 Report post Posted October 29, 2010 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
Papabear 0 Report post Posted May 28, 2011 hello, I tried your tutorial and worked fine, thank you for thatI'm really searching for this, It will help me in my vb subject Share this post Link to post Share on other sites
iGuest 3 Report post Posted November 22, 2011 Is it possible to use that code with a MDIForm?It works to hide but I am not able to UNHIDE it clicking on the tray-icon Share this post Link to post Share on other sites
iGuest 3 Report post Posted November 24, 2011 Ok,I have changed "Form_MouseMove" to "MDIForm_MouseMove" and it works with MDI too! Share this post Link to post Share on other sites