Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

System tray balloon tips

130 views
Skip to first unread message

Lindsay

unread,
Jun 16, 2004, 4:52:42 AM6/16/04
to
I'm using the shell_notifyicon API in VB6:

Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * 128
dwState As Long
dwStateMask As Long
szInfo As String * 256
uTimeOutOrVersion As Long
szInfoTitle As String * 64
dwInfoFlags As Long
guidItem As GUID
End Type

...but have 2 questions.
1- How does the uTimeOutOrVersion work? I would like the tooltip to
disappear after a while.

2. Using this structure, will it work on versions of Windows prior to XP? I
understand there is one version that works on ME or better.


With best regards, Lindsay. E-mail: lin...@home.com


Wesley Long

unread,
Jun 16, 2004, 6:36:31 PM6/16/04
to
There is a very good examply of how to do balloon tips at:

http://vbnet.mvps.org/code/subclass/shellnotifyballoontip.htm

that answers all these questions.

In particular, look at the

Private Sub SetShellVersion()

Method, as it adjusts the NOTIFYICONDATA structure to what is proper for
that OS.

Hope this helps.

"Lindsay" <lin...@home.com> wrote in message
news:_UTzc.15727$NK4.2...@stones.force9.net...

Lindsay

unread,
Jun 17, 2004, 10:20:38 AM6/17/04
to
It seems the function I want isn't supported in VB6 anyway.

You wrote on Wed, 16 Jun 2004 16:36:31 -0600:

WL> http://vbnet.mvps.org/code/subclass/shellnotifyballoontip.htm

WL> that answers all these questions.

WL> In particular, look at the

WL> Private Sub SetShellVersion()

WL> Method, as it adjusts the NOTIFYICONDATA structure to what is proper
WL> for that OS.

WL> Hope this helps.

WL> "Lindsay" <lin...@home.com> wrote in message
WL> news:_UTzc.15727$NK4.2...@stones.force9.net...
??>> I'm using the shell_notifyicon API in VB6:
??>>
??>> Private Type NOTIFYICONDATA
??>> cbSize As Long
??>> hwnd As Long
??>> uID As Long
??>> uFlags As Long
??>> uCallbackMessage As Long
??>> hIcon As Long
??>> szTip As String * 128
??>> dwState As Long
??>> dwStateMask As Long
??>> szInfo As String * 256
??>> uTimeOutOrVersion As Long
??>> szInfoTitle As String * 64
??>> dwInfoFlags As Long
??>> guidItem As GUID
??>> End Type
??>>
??>> ...but have 2 questions.
??>> 1- How does the uTimeOutOrVersion work? I would like the tooltip to
??>> disappear after a while.
??>>
??>> 2. Using this structure, will it work on versions of Windows prior to
??>> XP?
WL> I
??>> understand there is one version that works on ME or better.
??>>
??>> With best regards, Lindsay. E-mail: lin...@home.com
??>>

Randy Birch

unread,
Jun 17, 2004, 6:37:29 PM6/17/04
to
The balloontip will *eventually* disappear once the system's timeout value
has been reached -- it looks like that's around 30-40 seconds on my system.
There is a subclassing demo of the same basic code that shows how to detect
and respond to clicks -- and the timeout occurring -- located at
http://vbnet.mvps.org/code/subclass/shellnotifyballoontipclick.htm.

Heck... give me a few minutes and I'll post a complete demo to display/hide
a balloontip that also SetTimer to automagically close the balloon at a
pre-defined time. This should workaround the system timeout value. As long
as you specify a time shorter than the timeout (the MSDN states this is
typically 30 seconds) it will work. If you specify a time longer than the
system timeout the system will close the balloon as it normally would.

Look for this new demo listed on my site's main welcome page (and the new
code section) sometime around 8pm tonight.

--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.


"Lindsay" <lin...@home.com> wrote in message

news:NOhAc.16152$NK4.2...@stones.force9.net...
: It seems the function I want isn't supported in VB6 anyway.

:
:

Gale Green

unread,
Jun 17, 2004, 6:55:58 PM6/17/04
to
On Thu, 17 Jun 2004 18:37:29 -0400, "Randy Birch"
<rgb_rem...@mvps.org> wrote:

> Look for this new demo listed on my site's main welcome page (and the new
> code section) sometime around 8pm tonight.

Come on then Randy - it's 23:55 already! <g>

Gale.

Randy Birch

unread,
Jun 17, 2004, 7:40:34 PM6/17/04
to
<g> I've got it working if the demo is supposed to close the tip and icon
together (such as an update app might do), but not for just the tip -- yet.
I've got to eat ... I'm chewing on the mousepad as it is. Let's make it 11
tonight instead - my time.

--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.


"Gale Green" <ga...@databeat.fsnet.co.uk> wrote in message
news:ia84d0tl08oa0eo0i...@4ax.com...
: On Thu, 17 Jun 2004 18:37:29 -0400, "Randy Birch"

:

MikeD

unread,
Jun 17, 2004, 8:15:14 PM6/17/04
to

"Lindsay" <lin...@home.com> wrote in message
news:_UTzc.15727$NK4.2...@stones.force9.net...

> I'm using the shell_notifyicon API in VB6:
>
> Private Type NOTIFYICONDATA
> cbSize As Long
> hwnd As Long
> uID As Long
> uFlags As Long
> uCallbackMessage As Long
> hIcon As Long
> szTip As String * 128
> dwState As Long
> dwStateMask As Long
> szInfo As String * 256
> uTimeOutOrVersion As Long
> szInfoTitle As String * 64
> dwInfoFlags As Long
> guidItem As GUID
> End Type
>
> ...but have 2 questions.
> 1- How does the uTimeOutOrVersion work? I would like the tooltip to
> disappear after a while.
>

I'm guessing your confusion comes from that fact that in the C definition of
the structure, uTimeOutOrVersion is actually a union of two unsigned
integers. VB doesn't support unions so these two unsigned integers must be
combined into a Long. However, I don't think there could ever be a time when
you'd need (or even could) specify both. Therefore, it's really not an
issue. You would only specify a Version value when you send the NIM_VERSION
message for Shell_NotifyIcon. You would only specify a TimeOut value when
sending a NIM_MODIFY or NIM_ADD message to Shell_NotifyIcon. IOW, the two
are mutually exclusive. To specify the timout value, just assign the number
of milliseconds to uTimeOutOrVersion (and set value for other members of
this structure as appropriate) and then call Shell_NotifyIcon (sending
NIM_MODIFY or NIM_ADD).


> 2. Using this structure, will it work on versions of Windows prior to XP?
I
> understand there is one version that works on ME or better.

Different versions of Windows support different versions of this structure.
This is why one of the members of this structure is its size. You can define
the structure once and use that UDT for all versions of Windows. But you
need to determine the version of Windows under which the app is running in
order to specify the correct value for the cbSize member of the structure.
Unfortunately, this has gotten a little complicated because the structure
has changed a couple times with different versions of Windows. dwState to
dwInfoFlags are only supported under Windows 2000 and later (actually,
version 5 or later of shell32.dll). guidItem is only supported under
Windows XP (and it's reserved, meaning it's not even currently used under
WinXP; one can only guess that a future version of Windows after XP [or an
SP to WinXP] will use it). Also, under Win2000 and greater, szTip can be
128 bytes (or characters). Under Win95/98, szTip can only be 64 bytes. MS
really made this structure a little confusing.

Anyway, as I said, you need to determine the version of Windows and then
specify the proper structure size. Here's some multiple fragments of code to
get you started on that.

Public Type NOTIFYICONDATA
cbSize As Long
hWnd As Long


uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * 128
dwState As Long
dwStateMask As Long
szInfo As String * 256

'We have to take some liberties because VB doesn't support unions.
'We must therefore combine uTimeOut and uVersion into one element
'of the structure. This will work out fine, however, because the
'only time uVersion would be assigned is when sending the NIM_SETVERSION
'message, and for that message, you would not assign a value for
uTimeOut.
'IOW, uTimeOut and uVersion are used exclusively of one another.
uTimeOutAndVersion As Long


szInfoTitle As String * 64
dwInfoFlags As Long

guidItem As GUID 'WinXP only
End Type

Public Const NOTIFYICONDATA_V1_SIZE As Long = 88 'this includes elements
thru szTip with that being 64 chars
Public Const NOTIFYICONDATA_V2_SIZE As Long = 488 'this includes all
elements except guidItem.

Private m_nid As NOTIFYICONDATA

With m_nid
'We need to determine which "version" of the NOTIFYICONDATA
'structure to use. This depends on the version of Shell32.dll
Select Case g_lShell32Ver
Case Is < 500
.cbSize = NOTIFYICONDATA_V1_SIZE
.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP ' Or NIF_INFO
Or NIF_STATE Or NIF_GUID
Case Is < 600
.cbSize = NOTIFYICONDATA_V2_SIZE
.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP Or NIF_INFO Or
NIF_STATE 'Or NIF_GUID
Case Is >= 600
.cbSize = Len(m_nid)
.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP Or NIF_INFO Or
NIF_STATE Or NIF_GUID
End Select
.uCallbackMessage = WM_NOTIFYICON

End With

Private Type DLLVERSIONINFO
cbSize As Long
dwMajor As Long
dwMinor As Long
dwBuildNumber As Long
dwPlatformID As Long
End Type

Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA"
(ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As
Long) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As
Long, ByVal lpProcName As String) As Long
Private Declare Function DllGetVersion Lib "Shell32" (pdvi As
DLLVERSIONINFO) As Long

Public Function GetShell32Version() As Long

Dim hModule As Long
Dim lDllGetVersionAddress As Long
Dim dvi As DLLVERSIONINFO
Dim lRet As Long

hModule = LoadLibrary("shell32.dll")

If hModule Then
'See if the DllGetVersion function is exported by shell32.dll
lDllGetVersionAddress = GetProcAddress(hModule, "DllGetVersion")
If lDllGetVersionAddress = 0 Then
'The function is not exported which means the version
'of shell32.dll is earlier than 4.71
GetShell32Version = 400
Else
'It is, so let's get the version of it
With dvi
.cbSize = Len(dvi)
lRet = DllGetVersion(dvi)
If lRet = 0 Then
GetShell32Version = (.dwMajor * 100) + (.dwMinor)
End If
End With
End If

'Make sure we free the library
FreeLibrary hModule

End If

End Function

g_lShell32Ver = GetShell32Version


REMEMBER, the above code is bits and pieces. I mentioned determining the
version of Windows. It's really better to determine the version of
shell32.dll. What the above fragments of code actually do is determine the
version of shell32.dll and then asssigns a value to cbSize based on the
version of shell32.dll. The version of shell32.dll can usually be
associated to a particular version of Windows, but that's not always the
case, so it's better to check the version of shell32.dll. More work is
involved, but it's safer.

Mike


Ken Halter

unread,
Jun 18, 2004, 10:16:25 AM6/18/04
to
Randy Birch wrote:
> I'm chewing on the mousepad as it is

I find that if you add a little bit of butter and some maple syrup,
they're not all bad <g>


--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..

0 new messages