PC Review


Reply
Thread Tools Rate Thread

Balloon Tip Custom Icon

 
 
Kevin Cochran
Guest
Posts: n/a
 
      24th Feb 2008
Greetings,

I am using .NET 2.0, and I would like to specify a custom icon for the
balloon tip using NotifyIcon. I've noticed in the platform SDK that a custom
icon can be specified for a balloon tip using TTM_SETTITLE, but I can't
figure out how to get it to work.

Any help is appreciated.

Thanks,
Kevin


 
Reply With Quote
 
 
 
 
Jeroen Mostert
Guest
Posts: n/a
 
      24th Feb 2008
Kevin Cochran wrote:
> I am using .NET 2.0, and I would like to specify a custom icon for the
> balloon tip using NotifyIcon. I've noticed in the platform SDK that a custom
> icon can be specified for a balloon tip using TTM_SETTITLE, but I can't
> figure out how to get it to work.
>

For notify icons, there's already NotifyIcon.BalloonTipIcon. For general
tooltips, you can use ToolTip.IsBalloon and ToolTip.ToolTipIcon. The latter
does require you to draw the tooltip yourself if the icon isn't a standard
icon, but arguably, this is not a bad thing, because using TTM_SETTITLE to
specify an icon is only supported from XP SP2 onward.

That said, if you don't mind saddling your users with a requirement just to
display nice graphics and you're too lazy to draw the tooltip from scratch,
this should do the trick. I'm assuming you've already got an icon and a
tooltip laying around somewhere.

[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr
wParam, IntPtr lParam);

const uint TTM_SETTITLEW = 1057;

IntPtr tmpStr = null;
try {
tmpStr = Marshal.StringToHGlobalUni(toolTip.ToolTipTitle);
SendMessage(toolTip.Handle, TTM_SETTITLEW, icon.Handle, tmpStr);
} finally {
Marshal.FreeHGlobal(tmpStr);
}

Warning: untested.

--
J.
 
Reply With Quote
 
Kevin Cochran
Guest
Posts: n/a
 
      24th Feb 2008
Hi Jeroen,

Thanks for the advice. Oh, I'm lazy for sure, but in this case, I think I'd
prefer to draw the icon myself. It's just what's needed in this case. My app
is build around the NotifyIcon class because it's windowless, and the
NotifyIcon.BalloonTipIcon does not appear to let you do custom icons, you can
only choose from one of four predefined ones.

That said, how can I use the ToolTip class in place of the built-in one that
NotifyIcon uses?

Thanks again,
Kevin

"Jeroen Mostert" wrote:

> Kevin Cochran wrote:
> > I am using .NET 2.0, and I would like to specify a custom icon for the
> > balloon tip using NotifyIcon. I've noticed in the platform SDK that a custom
> > icon can be specified for a balloon tip using TTM_SETTITLE, but I can't
> > figure out how to get it to work.
> >

> For notify icons, there's already NotifyIcon.BalloonTipIcon. For general
> tooltips, you can use ToolTip.IsBalloon and ToolTip.ToolTipIcon. The latter
> does require you to draw the tooltip yourself if the icon isn't a standard
> icon, but arguably, this is not a bad thing, because using TTM_SETTITLE to
> specify an icon is only supported from XP SP2 onward.
>
> That said, if you don't mind saddling your users with a requirement just to
> display nice graphics and you're too lazy to draw the tooltip from scratch,
> this should do the trick. I'm assuming you've already got an icon and a
> tooltip laying around somewhere.
>
> [DllImport("user32.dll")]
> private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr
> wParam, IntPtr lParam);
>
> const uint TTM_SETTITLEW = 1057;
>
> IntPtr tmpStr = null;
> try {
> tmpStr = Marshal.StringToHGlobalUni(toolTip.ToolTipTitle);
> SendMessage(toolTip.Handle, TTM_SETTITLEW, icon.Handle, tmpStr);
> } finally {
> Marshal.FreeHGlobal(tmpStr);
> }
>
> Warning: untested.
>
> --
> J.
>

 
Reply With Quote
 
Jeroen Mostert
Guest
Posts: n/a
 
      24th Feb 2008
Kevin Cochran wrote:
> "Jeroen Mostert" wrote:
>
>> Kevin Cochran wrote:
>>> I am using .NET 2.0, and I would like to specify a custom icon for the
>>> balloon tip using NotifyIcon. I've noticed in the platform SDK that a custom
>>> icon can be specified for a balloon tip using TTM_SETTITLE, but I can't
>>> figure out how to get it to work.
>>>

>> For notify icons, there's already NotifyIcon.BalloonTipIcon. For general
>> tooltips, you can use ToolTip.IsBalloon and ToolTip.ToolTipIcon. The latter
>> does require you to draw the tooltip yourself if the icon isn't a standard
>> icon, but arguably, this is not a bad thing, because using TTM_SETTITLE to
>> specify an icon is only supported from XP SP2 onward.
>>
>> That said, if you don't mind saddling your users with a requirement just to
>> display nice graphics and you're too lazy to draw the tooltip from scratch,
>> this should do the trick. I'm assuming you've already got an icon and a
>> tooltip laying around somewhere.
>>
>> [DllImport("user32.dll")]
>> private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr
>> wParam, IntPtr lParam);
>>
>> const uint TTM_SETTITLEW = 1057;
>>
>> IntPtr tmpStr = null;
>> try {
>> tmpStr = Marshal.StringToHGlobalUni(toolTip.ToolTipTitle);
>> SendMessage(toolTip.Handle, TTM_SETTITLEW, icon.Handle, tmpStr);
>> } finally {
>> Marshal.FreeHGlobal(tmpStr);
>> }
>>
>> Warning: untested.
>>

> Thanks for the advice. Oh, I'm lazy for sure, but in this case, I think I'd
> prefer to draw the icon myself. It's just what's needed in this case. My app
> is build around the NotifyIcon class because it's windowless, and the
> NotifyIcon.BalloonTipIcon does not appear to let you do custom icons, you can
> only choose from one of four predefined ones.
>
> That said, how can I use the ToolTip class in place of the built-in one that
> NotifyIcon uses?
>

Silly me, I didn't notice that NotifyIcon.BalloonTipIcon is *also*
restricted to the default icons! Now look who's lazy.

Alright, yes, getting NotifyIcon to do a custom icon happens to be a *lot*
harder. The shell unfortunately does not use the tool tip control for notify
icons, so TTM_SETTITLE will not avail you here (and custom drawing is not
possible, the best you can do is a custom icon). NotifyIcon does not expose
its notification window handle or id, so you cannot call Shell_NotifyIcon
yourself either. Finally, you cannot determine the position of a notify
icon, so you cannot draw the balloon tip yourself either!

When do you need the balloon tip to appear? If it has to occur as a result
of the user clicking, you can still make it work by handling the MouseClick
event and drawing around that position. Here's a post where that solution is
used: http://forums.microsoft.com/MSDN/Sho...51783&SiteID=1

If you really need the balloon tip to appear with a custom icon when you
want it, not when the user does something, then start reading up on
Shell_NotifyIcon and good luck writing your own class...

--
J.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is this a bug: Intead of custom icon location, custom web pageshortcuts in Favoroites > Properties > Change icon... > always show %SystemRoot%\system32\SHELL32.dll c627627 Windows XP Help 1 26th Mar 2011 08:35 PM
Custom Balloon Tip? Jon Berry Microsoft Dot NET Framework Forms 0 6th Oct 2009 03:28 PM
Custom Balloon Tip? Jon Berry Microsoft C# .NET 0 6th Oct 2009 01:20 AM
Tray icon balloon Peter Larsen [CPH] Microsoft Dot NET Framework 5 29th Apr 2009 04:14 PM
Hide balloon tip icon =?Utf-8?B?RGF2ZSBCb29rZXI=?= Microsoft C# .NET 2 20th Jan 2006 02:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:53 AM.