Solved

show icon on the right bottom of toolbar

Posted on 1998-08-10
3
172 Views
Last Modified: 2010-04-30
I want to write a program which icon will be showed on the right bottom of the toolbar(That's besides the clock) How can I do that using VB.
Thanks
0
Comment
Question by:Torus
3 Comments
 

Expert Comment

by:topol
ID: 1468443
This is called system tray. You need to use subclassing to do that. You can find an example of that on http://www.mvps.org/vbnet/code/shell/shellnotifybasic.htm.


0
 
LVL 3

Accepted Solution

by:
SPECIALIST earned 50 total points
ID: 1468444
This is the best one I know of:

Option Explicit

Private 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

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

Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const WM_RBUTTONDBLCLK = &H206
Private Const WM_RBUTTONDOWN = &H204
Private Const WM_RBUTTONUP = &H205

Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Dim t As NOTIFYICONDATA

Private Sub Form_Load()
Timer1.Interval = 1000
    t.cbSize = Len(t)
    t.hWnd = pichook.hWnd
    t.uId = 1&
    t.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    t.ucallbackMessage = WM_MOUSEMOVE
    t.hIcon = Me.Icon
    t.szTip = "Shell_NotifyIcon ..." & Chr$(0)
    Shell_NotifyIcon NIM_ADD, t
    Me.Hide
    App.TaskVisible = False
   
   
   
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    t.cbSize = Len(t)
    t.hWnd = pichook.hWnd
    t.uId = 1&
    Shell_NotifyIcon NIM_DELETE, t
End Sub


Private Sub mnuMain_Click(Index As Integer)
    Unload Me
End Sub

Private Sub pichook_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Static rec As Boolean, msg As Long
    msg = X / Screen.TwipsPerPixelX
    If rec = False Then
        rec = True
        Select Case msg
            Case WM_LBUTTONDBLCLK:
                MsgBox "Double click !"
            Case WM_LBUTTONDOWN:
            Case WM_LBUTTONUP:
            Case WM_RBUTTONDBLCLK:
            Case WM_RBUTTONDOWN:
            Case WM_RBUTTONUP:
                Me.PopupMenu mnuBar
        End Select
        rec = False
    End If
End Sub


You can customize it to fit your environment.

David
0
 
LVL 2

Author Comment

by:Torus
ID: 1468445
Hi Specialist,

Thanks for your solution.
However, I feel very ridiculous how the function pichook_mousemove function works.
Firstly, I thought you typed something wrongly at  "Msg = X /Screen.TwipsPerPixelX  ".
But after I tried it, it does works without needing subclass. Would you pls tell me the mechanism that how it works. Also, I know little about graphics. I don't understand why
Screen.TwipsPerPixelX is a constant even I change to any resolution since Twips is  screen-independent.

Thanks.
Also Thanks to topol. The sites seems very helpful

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Runtime error 76: path not found error VB6 program on Windows 7 3 336
DIR issue 7 51
Access 2003, my txt file export is running backwards 4 47
Problem to skip loop 6 55
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now