Add an icon to the systemtray

BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "clsSysTray"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
'
'clsSysTray
'
'WHO, WHAT, WHERE:
' provided 'as is', no warranty, no guarantees
'
'TACTICS:
' create object Dim systray as Object
' set systray = New clsSysTray
' set icon systray.Icon = frmMAIN.Icon
' set tooltip text systray.ToolTip = "My System Tray Icon !"
' set owner control systray.OwnerControl = frmMAIN.picAnimate
' activate it systray.Add
'...
' now, when the user clicks on the the created icon, the corresponding MOUSEMOVE event
' of the owning control is activated. Here a sample of such code: '
private Sub picAnimate_MouseMove(Button as Integer, _ '
Shift as Integer, X as Single, Y as Single) '
Select case Hex(X) ' case "1E3C" 'Right-Button-Down
' MsgBox "Right-Button-Down" '
case "1830" 'Right-Button-Down LARGE FONTS '
MsgBox "Right-Button-Down LARGE FONTS" ' Case
"1E0F" 'Left-Button-Down ' MsgBox
"Left-Button-Down" ' case "1E2D"
'Left-Button-Double-Click ' MsgBox
"Left-Button-Double-Click" ' case "1824"
'Left-Button-Double-Click LARGE FONTS ' MsgBox
"Left-Button-Double-Click LARGE FONTS" ' case "1E5A"
'Right-Button-Double-Click ' MsgBox
"Right-Button-Double-Click" ' end Select '
end Sub '... 'when active, you can do the following ' modify the icon
shown systray.Icon = frmSetup.Icon ' modify the tooltip text systray.ToolTip
= "Modified Text !" ' remove the icon systray.Remove ' (this is not
done automatic when your program ends !) ' ' Option Explicit private Type
NOTIFYICONDATA_TYPE
cbSize as Long
hWnd as Long
uID as Long
uFlags as Long
uCallbackMessage as Long
hIcon as Long
szTip as String * 64
End Type

Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" _
(ByVal dwMessage as Long, lpData as NOTIFYICONDATA_TYPE) as Long

Private mvarSysTray as NOTIFYICONDATA_TYPE
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const WM_MOUSEMOVE = &H200

Private blnIsActive as Boolean 'status flag
Private blnOwnerControlIsSet as Boolean 'status flag
Private blnIconIsSet as Boolean 'status flag
Private mvarOwnerControl as object 'local copy

Public Property Let OwnerControl(ByVal vData as Object)
'calling program should set owning control
If blnIsActive Then
MsgBox "WARNING: clsSysTray cannot change owner control for an icon when active",
vbExclamation
Else
set mvarOwnerControl = vData
blnOwnerControlIsSet = True
end If
End Property

Public Property Get OwnerControl() as Object
'if calling program wants to know it
set OwnerControl = mvarOwnerControl
End Property

Public Property Let ToolTip(ByVal vData as String)
'calling program can set ToolTip (optional)
If vData = "" Then
mvarSysTray.szTip = vbNullChar
Else
mvarSysTray.szTip = " " & vData & " " & vbNullChar
end If
'modify shown text if active
If blnIsActive Then Shell_NotifyIcon NIM_MODIFY, mvarSysTray
End Property

Public Property Get ToolTip() as String
Attribute ToolTip.VB_UserMemId = 0
'if calling program wants to know it
ToolTip = mvarSysTray.szTip
End Property

Public Property Let Icon(ByVal vData as Object)
'calling program should set icon
mvarSysTray.hIcon = vData
'set status
blnIconIsSet = True
'modify shown icon if active
If blnIsActive Then Shell_NotifyIcon NIM_MODIFY, mvarSysTray
End Property

Public Property Get Icon() as Object
'if calling program wants to know it
set Icon = mvarIcon
End Property

Public Function Remove() as Boolean
'to remove the icon from the system tray
'NOT done automatic if your program ends !
If blnIsActive = True Then
Shell_NotifyIcon NIM_DELETE, mvarSysTray
'set status
blnIsActive = False
end If
Remove = True
End Function

Public Function Add() as Boolean
'verify environment
If blnIsActive Then MsgBox "ERROR: clsSysTray is already acive", vbExclamation
If Not blnIconIsSet Then MsgBox "ERROR: clsSysTray cannot activate when the icon has
not been set", vbExclamation If Not blnOwnerControlIsSet Then MsgBox "ERROR:
clsSysTray cannot activate when the owner control has not been set", vbExclamation
'set other variables mvarSysTray.cbSize = Len(mvarSysTray) mvarSysTray.hWnd =
mvarOwnerControl.hWnd mvarSysTray.uID = 1& mvarSysTray.uFlags = NIF_MESSAGE Or
NIF_ICON Or NIF_TIP mvarSysTray.uCallbackMessage = WM_MOUSEMOVE Shell_NotifyIcon
NIM_ADD, mvarSysTray 'set status blnIsActive = True Add = True
End Function


Return

No comments:

Visual Basic-6 has emerged as one of the standard Windows Programming Language and it has become a must for all Software people for developing Applications in Visual Environment. So it is, one must learn Visual Basic-6.

What is our Objective in this Courseware?


The Overall Objective in this Courseware is to give a Hands-on Approach to develop different projects in Visual Basic-6.0 using intrinsic, professional and user–created ActiveX controls and also develop projects using databases, DAO’s, ADO’s, DLL’s, Documents, Crystal Reports etc. covering almost all the essential features of VB-6 Professional Edition. After reading one lesson any interested reader will be able to get complete hands-on experience with the VB project and get a sense of fulfilment and achievement. Learning by doing is the motto with which this courseware is written. After giving a short introduction about VB-6 we will explain how to create and execute a project in VB using some intrinsic ActiveX controls. Creating and executing projects will be the central theme of all the lessons which we will be giving in this courseware.

What is Visual Basic-6?


Visual Basic-6 has its origin in Basic which was developed round about the year 1960, when high level languages were just being introduced to the computer community. Microsoft has made it extremely powerful by gearing all its good features to the Windows environment. Starting with the version 3 and then with 4, and then with 6, Visual Basic is now at version 6. Basic is a Procedure Oriented Language intended to implement single tasks in text based environment whereas Visual Basic is an Event Driven Language intended to implement Projects or Applications containing multiple tasks in Windows Environment.

What can Visual Basic do for you?

Visual Basic can serve as an ideal front end tool for the clients to interact. It has got connectivity mechanisms for all types of databases situated far and wide in a network and so it can cater to the needs of a large body of clients. Using the latest ActiveX technologies, it can integrate the functionalities provided by other applications like Word Excel and other Windows. Its internet capabilities provide easy access to documents and applications across the internet. Above all it embodies the Object Oriented Technology, which is the cutting edge technology for all the present day developments in the Software World. The final application is a true EXE file and so can be freely distributed.


Structure of VB-6 Projects:


We said earlier that VB-6 implements projects or applications. A project is developed using one or more Forms. A Form is simply a window containing one or more Controls. Controls in VB consist of labels, text boxes, list boxes, combo boxes, scroll bars etc. which are the constituents of windows environment. It is only the controls that give VB, its immense power and so there is a lot of interest in creating more and more powerful controls. ActiveX controls mark a significant development in controls technology. In fact all controls in VB-6 are ActiveX controls, which have the extension .ocx. These controls have properties whose values can be initialized at design time and also varied during run time. The properties are something like variables. The controls are activated by codes written in a high level language. By associating our problem variables with the properties of the controls, our problem variables can be manipulated to give the problem solution. In summary we can say that a VB project is made of forms, controls and their properties and codes.

Integrated Development Environment:

The working environment in VB is often referred to as the Integrated Development Environment or IDE, because it integrates many different functions such as design, editing, compiling and debugging within a common environment. Since all our projects are developed only in the IDE, let us now have a brief look at its features. You will be able to understand their uses at the time of building projects. The VB IDE looks as shown in the figure.