I don't know if that is the correct name for them, but does anyone know how to create those (yellow) XP balloons that pop up when new hardware is installed, etc.?
Thanks,
JoshK
Printable View
I don't know if that is the correct name for them, but does anyone know how to create those (yellow) XP balloons that pop up when new hardware is installed, etc.?
Thanks,
JoshK
Umm, they're called ToolTips :D
I knew how to do it in VB6. check the tooltip thingie on msdn for vb.net, maybe there is a way to do it with the tooltip control
bump bump bump, someone answer plz. I like to know how :D
There is a ToolTip control in my toolbox. Don't know if it will work, but it is there.
I found some help on the Microsoft NGs. Here is the post:
I asked this questiona couple months ago, received the
same answers, try this, check this, wel, all of this gave
me a good idea on how to do it and where to start, so
here is the code for you.... it works fine,it is on some
app I'm developing right now, if you have anything,
please contact me at [email protected],
remember, put the imports declaration before the class or
module declaration
Regards
Code:Imports System.Runtime.InteropServices
' This claas provides some usefull shell extentions to
use with Windows systems
Public Result As Boolean
<StructLayout(LayoutKind.Sequential)> Public Structure
NOTIFYICONDATA
Dim cbSize As Int32
Dim hwnd As IntPtr
Dim uID As Int32
Dim uFlags As Int32
Dim uCallbackMessage As IntPtr
Dim hIcon As IntPtr
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)>
Dim szTip As String
Dim dwState As Int32
Dim dwStateMask As Int32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)>
Dim szInfo As String
Dim uVersion As Int32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=64)>
Dim szInfoTitle As String
Dim dwInfoFlags As Int32
End Structure
Public Const NIF_MESSAGE As Int32 = &H1
Public Const NIF_ICON As Int32 = &H2
Public Const NIF_STATE As Int32 = &H8
Public Const NIF_INFO As Int32 = &H10
Public Const NIF_TIP As Int32 = &H4
Public Const NIM_ADD As Int32 = &H0
Public Const NIM_MODIFY As Int32 = &H1
Public Const NIM_DELETE As Int32 = &H2
Public Const NIM_SETVERSION As Int32 = &H4
Public Const NOTIFYICON_VERSION As Int32 = &H5
Public Const NIS_HIDDEN = &H1
Public Const NIS_SHAREDICON = &H2
Public Const NIIF_ERROR = &H3
Public Const NIIF_INFO = &H1
Public Const NIIF_NONE = &H0
Public Const NIIF_WARNING = &H2
Public Const NIM_SETFOCUS = &H4
Public Const NIIF_GUID = &H5
Public Declare Function Shell_NotifyIcon
Lib "shell32.dll" _
Alias "Shell_NotifyIconA" (ByVal dwMessage As Int32, _
ByRef lpData As NOTIFYICONDATA) As Boolean
Public uNIF As NOTIFYICONDATA
' Displays a balloon info notification
Public Sub SendBalloonInfoNotification(ByVal strInfo As
String)
With uNIF
.uFlags = NIF_INFO
.uVersion = 2000
.szInfoTitle = "Info"
.szInfo = strInfo
.dwInfoFlags = NIIF_INFO
End With
Result = Shell_NotifyIcon(NIM_MODIFY, uNIF)
End Sub
' Displays a balloon warning notification
Public Sub SendBalloonWarningNotification(ByVal
strWarning As String)
With uNIF
.uFlags = NIF_INFO
.uVersion = 2000
.szInfoTitle = "Warning"
.szInfo = strWarning
.dwInfoFlags = NIIF_WARNING
End With
Result = Shell_NotifyIcon(NIM_MODIFY, uNIF)
End Sub
' Displays a balloon error notification
Public Sub SendBalloonErrorNotification(ByVal strError As
String)
With uNIF
.uFlags = NIF_INFO
.uVersion = 2000
.szInfoTitle = "Error"
.szInfo = strError
.dwInfoFlags = NIIF_ERROR
End With
Result = Shell_NotifyIcon(NIM_MODIFY, uNIF)
End Sub
' Removes the application icon from the system tray
Public Sub RemoveIconFromTray(ByRef frmForm As
System.Windows.Forms.Form)
With uNIF
.cbSize = Marshal.SizeOf(uNIF)
.hwnd = frmForm.Handle()
.uID = 1
End With
With Shell_NotifyIcon(NIM_DELETE, uNIF)
End With
End Sub
' Adds a application icon to system tray
Public Sub AddIconToTray(ByRef frmForm As
System.Windows.Forms.Form)
With uNIF
.cbSize = Marshal.SizeOf(uNIF)
.hwnd = frmForm.Handle
.uID = 1
.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
.uCallbackMessage = New IntPtr(&H500)
.uVersion = NOTIFYICON_VERSION
.hIcon = frmForm.Icon.Handle
End With
Result = Shell_NotifyIcon(NIM_ADD, uNIF)
End Sub
umm since you're using APIs it's called unmanaged code?:confused:
I think there should be a way to do the whole thing with the framework:rolleyes:
you write a managed c++ assembly that uses the unmanged api and it's ok to use the api then :)
the framework has problems. namely as usual Microsoft forgot to include full access to the windows programming model. you would think that after all the work they putt into it the would have provided at least a limetted WIN32 API wrapper assembly.... but sometimes vb6 is just better or you have to make wrapper classes with managged c++
the ballon tips are supports in win 2k as well. it just isn't used all over the place.
I've never seen a way to invoke the factory built in OS balloon tooltips, but i have seen quite a few code samples of ways to make it happen.
Try this example: Balloon Window
Really, all you need to do is:
1) inherit a form
2) In its onpaint event, create a graphics path that draws an outline of a balloon, fills it, and then clips the form region by setting its region property to a new region that encompasses only the graphics path.
3) put a timer on the form, and Me.Dispose in timer_tick event
4) set the form border style = none
5) almost forgot : set the backcolor of the form to some odd color, and use that color for the transparency key.
i tried the code from above. it dosnt do anything at all, not even give me an error. any ideas?
i copied the code into a new module. then i made a form with a button and this code: SendBalloonInfoNotification("test")
...?
can someone verify that the code above actually works?
thanks.
I just ran the demo project but that works fine on my machine.
by demo project, you mean that you implemented the code posted by joshK? that is what i'm interested in.
No I meant the code in the link from MrGTI.
can you check the other one?
i've posted the balloon tooltip that i made in the vb.net section of the codebank :) Full Color Balloon ToolTips with Icon / Title
enjoy ;)
this is the kind of thing to expect...
http://homepage.ntlworld.com/dennis....%20tooltip.gif
thats cool. i like it...
but what i really want is to use the notify balloons included in windows XP that pop up from the tray icons, like when a network connection or new hardware is found.
thanks...
ah , you mean like this then ...
http://homepage.ntlworld.com/dennis.hughes3/ni.jpg
i've been busy trying to work it out most of the day ( between feeding / changing babies :p )
first add a reference to Imports System.Runtime.InteropServices at the top of your form , then bung this code in your form ....
that should get you started :)VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load With NotifyIcon1 .Icon = DirectCast(Me.Icon, Icon) .Visible = True End With End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim notifyballoon As New ClsNotifyBalloon() notifyballoon.DisplayBalloon(Me.Text, "the tooltip text", NotifyIcon1, ClsNotifyBalloon.ToolTipIcon.TTI_INFO) End Sub '/// in either a seperate Class , or below your form's End Class statement ..... Public Class ClsNotifyBalloon <StructLayout(LayoutKind.Sequential)> _ Public Structure NOTIFYICONDATA Public cbSize As Integer Public hwnd As IntPtr Public uID As Integer Public uFlags As Integer Public uCallbackMessage As Integer Public hIcon As IntPtr <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> _ Public szTip As String Public dwState As Integer Public dwStateMask As Integer <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> _ Public szInfo As String Public uTimeout As Integer <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=64)> _ Public szInfoTitle As String Public dwInfoFlags As Integer End Structure <DllImport("Shell32")> _ Private Shared Function Shell_NotifyIconA(ByVal Msg As Integer, ByRef Nd As NOTIFYICONDATA) As IntPtr End Function Public Enum ToolTipIcon TTI_INFO = 1 TTI_WARNING = 2 TTI_ERROR = 3 End Enum Public Sub DisplayBalloon(ByVal Caption As String, ByVal strText As String, ByVal Ni As NotifyIcon, ByVal ico As ToolTipIcon, Optional ByVal timeout As Integer = 1000) Dim notifystruct As NOTIFYICONDATA Dim nWindow As NativeWindow = DirectCast(Ni.GetType.GetField("window", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance).GetValue(Ni), NativeWindow) With notifystruct .cbSize = 0 .dwInfoFlags = 0 .dwState = 0 .dwStateMask = 0 .hIcon = New IntPtr(0) .szTip = String.Empty .uCallbackMessage = &H200 .szInfoTitle = Caption .uTimeout = timeout .hwnd = nWindow.Handle .uID = Convert.ToInt32(Ni.GetType.GetField("id", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance).GetValue(Ni)) .dwInfoFlags = Convert.ToInt32(ico) .uTimeout = Environment.OSVersion.Version.Major .szInfo = strText .uFlags = &H10 .cbSize = Marshal.SizeOf(notifystruct) Shell_NotifyIconA(&H1, notifystruct) End With End Sub End Class
Thats some good stuff dynamic_sysop!
And there is nothing wrong with using the api either. It's only a mistake to use api if it is limeted to one version of windows and most api works on everything but win95 and there are only a few that don't work 95. Now if you were going to try to run it on a mac.....
very cool
very very nice. thanks so much dynamic_sysop.
no problem :)
cheers btw Ed :wave:
dynamic_sysop
I have used your code in a project of mine and it works great. Thanks! I do have a few XP clients however that for one reason or another it doesn't work on.
Is there a setting somewhere that can be set to disable or enable them?
Thanks in advance.
Do you know what difference in these machines are from the machines that it does work on?
I don't think there is any place to specifically disable them. A good test would be to unplug the NIC cable or something that you know causes a balloon tip to popup, and see if it does on the machine that is having the issue. If it does, you know it can be isolated to your code. If it doesn't then it could be isolated to the machines themselves.Quote:
Originally Posted by cpatzer
Is this project a .NET 1.1 project? If it is 2.0, then (you probably know) but balloon tips are build right in to the tooltip class in 2.0.
Also just as a side test, I had a .NET 1.1 project that I used this free balloon tip component on. Might be worth giving it a shot.
http://www.gotdotnet.com/Community/U...5-C9F36B18A8FC
Well, I just figured it out. VS 2003 in setup project told me exclude Shell32.dll because it was under Windows file protection. That file was needed on those XP Pro machines in order to show the popup as it is called from the API. I still get an error however the first time it pops up.
"The procedure entry point _ftol2_see could not be located in the dynamic link library msvcrt.dll"
Probably a different version of the file will fix the problem. I will keep you updated.
you certainly should NOT be distributing Shell32.dll....
that is a main windows dll (since maybe as far back as windows 3.11), and there is no way these machines are running without it...
So there is no possible way those XP machines do not have shell32 on them
Well for some reason when I distribute it with the application, it starts working on those machines. I didn't have time to check for the file first as they are busy at work and I can only disturb them so much. I have other XP pro machines that the application runs perfectly on, just not those unless I include that file. ???
BTW I have had this occur on XP more than one with .NET 1.1 files. I am not sure exactly what causes it, but the applications start working when I include the files VS tells me not to.
Okay, so I have a little more information for the puzzle.
If Shell32.dll is in the install directory, the application works, minus the error mentioned above. If it is just left in the system32 directory, it doesn't.
Could it be that I need to patch their .NET 1.1 framework? Maybe it isn't looking in the correct paths for these files on those machines? But then if you include the problem of the error above, something more sinister seems to be at work on those CPUs.:confused:
Change your API dec to this and see if it has any different result?
where you actually call this function, you will have to take the A off the end...Code:<DllImport("shell32.dll")> _
Shared Function Shell_NotifyIcon(ByVal dwMessage As Integer, ByRef pnid As NOTIFYICONDATA) As Boolean
End Function
kleinma,
As always, you are a fricken genius! Thank you!!! That worked perfectly.
sounds good. I bet not specifying Shell32.dll, and only specifying shell32 was causing the problem.
I also bet it may be an issue on some machines, but not others based on a few factors (environment variables, specifically the path varaible). That is just a guess, but I can't really think of any other reason why it would map correctly to the API function on some but not on others.