How to build an application in the taskbar.

  • Thread starter Thread starter Frank Rizzo
  • Start date Start date
F

Frank Rizzo

Not system tray. I want to build an app in the task bar. Like the
Windows Media Player applet (right click on taskbar/Toolbars/Windows
media Player.

Thanks.
 
Hello,

Option Explicit
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias
"Shell_NotifyIconA" _
(ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Private Declare Function SetForegroundWindow Lib "user32" _
(ByVal hwnd As Long) As Long

Private Type NOTIFYICONDATA
cbSize As Long '//size of this UDT
hwnd As Long '//handle of the app
uId As Long '//unused (set to vbNull)
uFlags As Long '//Flags needed for actions
uCallBackMessage As Long '//WM we are going to subclass
hIcon As Long '//Icon we're going to use for the systray
szTip As String * 64 '//ToolTip for the mouse_over of the icon.
End Type

Private Const NIM_ADD = &H0 '//Flag : "ALL NEW nid"
Private Const NIM_MODIFY = &H1 '//Flag : "ONLY MODIFYING nid"
Private Const NIM_DELETE = &H2 '//Flag : "DELETE THE CURRENT
nid"
Private Const NIF_MESSAGE = &H1 '//Flag : "Message in nid is
valid"
Private Const NIF_ICON = &H2 '//Flag : "Icon in nid is valid"
Private Const NIF_TIP = &H4 '//Flag : "Tip in nid is valid"
Private Const WM_MOUSEMOVE = &H200 '//This is our CallBack Message
Private Const WM_LBUTTONDOWN = &H201 '//LButton down
Private Const WM_LBUTTONUP = &H202 '//LButton up
Private Const WM_LBUTTONDBLCLK = &H203 '//LDouble-click
Private Const WM_RBUTTONDOWN = &H204 '//RButton down
Private Const WM_RBUTTONUP = &H205 '//RButton up
Private Const WM_RBUTTONDBLCLK = &H206 '//RDouble-click

Private nid As NOTIFYICONDATA '//global UDT for the systray
function


Private Sub mnuRestore_Click()
'Me.WindowState = vbNormal
MDIFrmmain.WindowState = vbNormal
Call SetForegroundWindow(Me.hwnd)
Me.Show
End Sub

Private Sub MDIForm_Resize()
If (Me.WindowState = vbMinimized) Then Me.Hide
End Sub

Private Sub MDIForm_Unload(Cancel As Integer)
Shell_NotifyIcon NIM_DELETE, nid
Set MDIFrmmain = Nothing
End
'Frmend.Show vbModal
End Sub

Private Sub MDIForm_Activate()
With nid
.cbSize = Len(nid)
.hwnd = Me.hwnd
.uId = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallBackMessage = WM_MOUSEMOVE
.hIcon = Me.Icon
.szTip = "Information Management System" & vbNullChar
End With

Shell_NotifyIcon NIM_ADD, nid

Call mnuFlash_Click
Fraloading.Visible = True
Call Timerloading_Timer

End Sub

Private Sub chkFlash_Click()
Dim nidflash As NOTIFYICONDATA

If (Timer1.Enabled) Then
chkFlash.Value = vbUnchecked
mnuFlash.Checked = False
Timer1.Enabled = False
With nidflash
.cbSize = Len(nidflash)
.hwnd = Me.hwnd
.uId = vbNull
.uFlags = NIF_ICON
.hIcon = Me.Icon
End With
Shell_NotifyIcon NIM_MODIFY, nidflash
Else
chkFlash.Value = vbChecked
mnuFlash.Checked = True
Timer1.Enabled = True
End If
End Sub
Private Sub cmdChangeTip_Click()
Dim nidNewTip As NOTIFYICONDATA '//New ToolTip nid
With nidNewTip
.cbSize = Len(nidNewTip)
.hwnd = Me.hwnd
.uId = vbNull
.uFlags = NIF_TIP '//Here the Tip is the only valid "new data"
.szTip = txtToolTip.Text & vbNullChar
End With

Shell_NotifyIcon NIM_MODIFY, nidNewTip
End Sub

Private Sub MDIForm_MouseMove(button As Integer, Shift As Integer, x As
Single, y As Single)
Dim msg As Long '//The callback value
If (frmmainmodule.ScaleMode = vbPixels) Then
msg = x
Else
msg = x / Screen.TwipsPerPixelX
End If

Select Case msg
Case WM_LBUTTONDBLCLK '515 restore form window
Me.WindowState = vbNormal
Call SetForegroundWindow(Me.hwnd)
Me.Show

Case WM_RBUTTONUP '517 display popup menu
Call SetForegroundWindow(Me.hwnd)
Me.PopupMenu Me.mnuSystray

Case WM_LBUTTONUP '514 restore form window
End Select
End Sub

Private Sub Timer1_Timer()
Dim nidflash As NOTIFYICONDATA '//New "Flashing" nid
Static SwitchIcons As Boolean '//Flag to decide whether to

With nidflash
.cbSize = Len(nidflash)
.hwnd = Me.hwnd
.uId = vbNull
.uFlags = NIF_ICON

If (SwitchIcons) Then
.hIcon = imgFlashIcon.Picture
SwitchIcons = False
Else
.hIcon = Me.Icon
SwitchIcons = True
End If
End With

Shell_NotifyIcon NIM_MODIFY, nidflash
End Sub



Warm Regards,

Ayaz Ahmed
Software Engineer & Web Developer
Creative Chaos (Pvt.) Ltd.
"Managing Your Digital Risk"
http://www.csquareonline.com
Karachi, Pakistan
Mobile +92 300 2280950
Office +92 21 455 2414
 
Back
Top