After much searching I have found the code to display balloon tips (XP style) But unforunately its in c# ...would some one convert it into VB.NET...Thanks
I have attached it as well
Code:
public class NotifyIcon
{
[StructLayout(LayoutKind.Sequential)]
public struct NotifyIconData
{
public System.UInt32 cbSize; // DWORD
public System.IntPtr hWnd; // HWND
public System.UInt32 uID; // UINT
public NotifyFlags uFlags; // UINT
public System.UInt32 uCallbackMessage; // UINT
public System.IntPtr hIcon; // HICON
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=128)]
public System.String szTip; // char[128]
public System.UInt32 dwState; // DWORD
public System.UInt32 dwStateMask; // DWORD
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public System.String szInfo; // char[256]
public System.UInt32 uTimeoutOrVersion; // UINT
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=64)]
public System.String szInfoTitle; // char[64]
public System.UInt32 dwInfoFlags; // DWORD
//GUID guidItem; > IE 6
}
public enum NotifyCommand {Add = 0, Modify = 1, Delete = 2, SetFocus = 3,
SetVersion = 4}
public enum NotifyFlags {Message = 1, Icon = 2, Tip = 4, State = 8, Info = 16,
Guid = 32}
[DllImport("shell32.Dll")]
public static extern System.Int32 Shell_NotifyIcon(NotifyCommand cmd,
ref NotifyIconData data);
[DllImport("Kernel32.Dll")]
public static extern System.UInt32 GetCurrentThreadId();
public delegate System.Int32 EnumThreadWndProc(System.IntPtr hWnd,
System.UInt32 lParam);
[DllImport("user32.Dll")]
public static extern System.Int32 EnumThreadWindows(System.UInt32 threadId,
EnumThreadWndProc callback,
System.UInt32 param);
[DllImport("user32.Dll")]
public static extern System.Int32 GetClassName(System.IntPtr hWnd,
System.Text.StringBuilder className,
System.Int32 maxCount);
private System.IntPtr m_notifyWindow;
private bool m_foundNotifyWindow;
// Win32 Callback Function
private System.Int32 FindNotifyWindowCallback(System.IntPtr hWnd,
System.UInt32 lParam)
{
System.Text.StringBuilder buffer = new System.Text.StringBuilder(256);
GetClassName(hWnd, buffer, buffer.Capacity);
// but what if this changes? - anybody got a better idea?
if(buffer.ToString() == "WindowsForms10.Window.0.app1")
{
m_notifyWindow = hWnd;
m_foundNotifyWindow = true;
return 0; // stop searching
}
return 1;
}
public void ShowBalloon(uint iconId, string title, string text, uint timeout)
{
// find notify window
uint threadId = GetCurrentThreadId();
EnumThreadWndProc cb = new EnumThreadWndProc(FindNotifyWindowCallback);
m_foundNotifyWindow = false;
EnumThreadWindows(threadId, cb, 0);
if(m_foundNotifyWindow)
{
// show the balloon
NotifyIconData data = new NotifyIconData();
data.cbSize = (System.UInt32)
System.Runtime.InteropServices.Marshal.SizeOf(
typeof(NotifyIconData));
data.hWnd = m_notifyWindow;
data.uID = iconId;
data.uFlags = NotifyFlags.Info;
data.uTimeoutOrVersion = 15000;
data.szInfo = text;
data.szInfoTitle = title;
Shell_NotifyIcon(NotifyCommand.Modify, ref data);
}
}
}
Here is the code that shows the usage of the class.
private void OnShowBalloon(object sender, System.EventArgs e)
{
NotifyBalloonDemo.NotifyIcon notifyIcon = new NotifyBalloonDemo.NotifyIcon();
notifyIcon.ShowBalloon(1, "My Title", "My Text", 15000);
}
Think I found something more simple along these lines. If you add Imports Microsoft.Office.Core
Then there is balloon object which might be of help. DOn't know how it works though!
Though using Microsoft agent I can show a balloon (ie making the agent speak), but just the balloon, VB says something about interfaces which I yet to understand.
You don't need to convert it to VB, just use the class as you would any VB.NET class. Make the call to the ShowBallon method, passing in the correct arguments, and it will work.
Just save the class in C#, then add the class to your project. This is the beauty of the language interop in .NET.
I have an app that i am trying to integrate this with.
1) how would i go about making the balloon show from an existing notifyicon
2) What happens if this is called in a windows 98 environment? will it cause an error, or simply not show. What is the best way of determining what OS version the program is running in?
Edneeis:
I have been trying to implement this code in my project, but it doesnt want to work. I think it has something to do with the fact that i am using multiple threads, and the thread that i am calling this from is not the one that contains the form that contains the notifyicon. How do i specify what notifyicon i want the ballook to show up on manually?
I fixed the threadig problem by simply invoking the method on the form that has the notuifyicon.
I now have another question in reference to the vb version edneeis posted...
In windows xp/2k, when the system uses the balloons, it knows when you click on the balloon, because it will allow an action to occur when you click on it (i.e. adding a new hardware if it fails, it says click this balloon to see hardware). I would like to integrate this into my program, both capturing a click on the close button and a click on the actual window.