AllExperts > Experts 
Search      

Visual Basic

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Visual Basic Answers
Question Library

Ask a question about Visual Basic
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Ravindra
Expertise
visual basic application programming from design to access information, sql, engineering and commercial applications. access databases, excel. Optional: 1)a large number of people want me to do work which takes some time and effort. Pl.note that i would like to be paid for such work. 2) if you want me to spend quality time and do special work, i expect to be paid a reasonable price for my time. 3) if you are pleased with my reply you could consider a donation of 1$. 4) you can visit my website http://ravindra.coolpage.biz (under constrn)

Experience

Past/Present clients
project work for a Norway company, and a Canadian company completed. Freelance Project work and Teaching
teaching vb

 
   

You are here:  Experts > Computing/Technology > Basic > Visual Basic > Minimize app to tray

Topic: Visual Basic



Expert: Ravindra
Date: 1/23/2006
Subject: Minimize app to tray

Question
In VB6, is there a way to minimize the app into tray instead of to the bottom bar? or alternatively by clicking a command button on the form to do that?

Thank you in advance if you have any ideas on coding in VB6 or using API or any third party plugins.

I write apps using VB6 (VS6). I want to write an application which should be running all the time (some machines are 98 and some are XP). Preferably, it can be minimized to the system tray when it is started (as an option).

Many thanks!

Answer
this is for advanced programmers only. do not attempt it if you are new.
in a .bas module

'------------------------------------------------------
' VB CENTER
'
' Tutorial: Using the system tray
' 09/26/98
'
' You may distribute this file as long as all the credits
' Are given to VB Center
'
' For more tutorials and a detailed explanation of this
' tutorial, visit our page: http://vbcenter.cjb.net
'
'------------------------------------------------------

Declare Function Shell_NotifyIcon Lib "shell32.dll" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
'If you get an error message at the beginning of the program,
'use the declaration below:
'Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias " Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long

'These three constants specify what you want to do
Public Const NIM_ADD = &H0
Public Const NIM_DELETE = &H2
Public Const NIM_MODIFY = &H1

Public Const NIF_ICON = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_TIP = &H4

Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_MOUSEMOVE = &H200
Public Const WM_RBUTTONDBLCLK = &H206
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205

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 IconData As NOTIFYICONDATA

_______
in the form

Private Sub Form_Activate()
Call Shell_NotifyIcon(NIM_ADD, IconData)
'this is an option to show icon without minimizing the form

End Sub

Private Sub Form_Resize()
'this is the option to show icon on minimizing the form
If Me.WindowState = 1 Then
'The user has minimized his window

'Call Shell_NotifyIcon(NIM_ADD, IconData)

' Add the form's icon to the tray

Me.Hide

' Hide the button at the taskbar

End If

End Sub

Private Sub Form_Load()

With IconData

.cbSize = Len(IconData)
' The length of the NOTIFYICONDATA type

.hIcon = Me.Icon
' A reference to the form's icon

.hwnd = Me.hwnd
' hWnd of the form

.szTip = "My Tooltip" & Chr(0)
' Tooltip string delimited with a null character

.uCallbackMessage = WM_MOUSEMOVE
' The icon we're placing will send messages to the MouseMove event

.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
' It will have message handling and a tooltip

.uID = vbNull
' uID is not used by VB, so it's set to a Null value

End With

End Sub

Private Sub mnuExit_Click()

Unload Me
' Unload the form

End
' Just to be sure the program has ended

End Sub

Private Sub mnuShow_Click()

Me.WindowState = vbNormal
Shell_NotifyIcon NIM_DELETE, IconData
Me.Show

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim Msg As Long

Msg = X
' The message is passed to the X value

' You must set your form's ScaleMode property to pixels in order to get the correct message

If Msg = WM_LBUTTONDBLCLK Then
' The user has double-clicked your icon

Call mnuShow_Click
' Show the window

ElseIf Msg = WM_RBUTTONDOWN Then
' Right-click

PopupMenu mnuPopup
' Popup the menu

End If

End Sub

Private Sub Form_Unload(Cancel As Integer)

Shell_NotifyIcon NIM_DELETE, IconData

End Sub




Ravindra M.G.

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.