wxTaskBarIcon with Balloon tooltips!

If you have a cool piece of software to share, but you are not hosting it officially yet, please dump it in here. If you have code snippets that are useful, please donate!
iLBorro
In need of some credit
In need of some credit
Posts: 2
Joined: Tue Aug 02, 2005 6:53 am
Location: Italy
Contact:

Post by iLBorro »

hi @all guys
isn't there any way to use theese balloons under non-windows systems?

i'm new to wxwidgets, so i don't undestand if this is only windows-related...

tnx in advance :)

Marco
Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg »

The wxWidgets toolkit does not (always) custom draw the elements. It simply wraps the native components making it a familiar environment no matter where you develop your code. Windows, Unix, Mac. The downside only parts that can be shared (like the set of components all OS'es have in common) are limited. Some people would however like to use Windows only things like the balloon tooltips, so they are kind of added.

I do agree there needs to be a better distinquishing between Windows/Mac/Linux only components, and the set all OS'es share, and it might be confusing.

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
iLBorro
In need of some credit
In need of some credit
Posts: 2
Joined: Tue Aug 02, 2005 6:53 am
Location: Italy
Contact:

Post by iLBorro »

tnx for reply

very helpful :)
lowjoel
Part Of The Furniture
Part Of The Furniture
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel »

OK guys this is the latest patch. This version allows for event handling to be done (took me half a day to solve the mystery of the undefined symbol :P)

Code: Select all

Index: include/wx/taskbar.h
===================================================================
RCS file: /pack/cvsroots/wxwindows/wxWindows/include/wx/taskbar.h,v
retrieving revision 1.26
diff -u -r1.26 taskbar.h
--- include/wx/taskbar.h	2005/05/04 18:52:03	1.26
+++ include/wx/taskbar.h	2005/08/03 03:42:59
@@ -18,6 +18,13 @@
 
 #include "wx/event.h"
 
+//Balloon Tooltips messages sent by the shell for MSW
+#ifndef NIN_BALLOONSHOW
+	#define NIN_BALLOONSHOW 1026
+	#define NIN_BALLOONHIDE 1028
+	#define NIN_BALLOONUSERCLICK 1029
+#endif
+
 class WXDLLIMPEXP_ADV wxTaskBarIconEvent;
 
 // ----------------------------------------------------------------------------
@@ -93,6 +100,9 @@
     DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV,wxEVT_TASKBAR_RIGHT_UP,1554)
     DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV,wxEVT_TASKBAR_LEFT_DCLICK,1555)
     DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV,wxEVT_TASKBAR_RIGHT_DCLICK,1556)
+    DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV,wxEVT_TASKBAR_BALLOON_SHOW,1557)
+    DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV,wxEVT_TASKBAR_BALLOON_HIDE,1558)
+    DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV,wxEVT_TASKBAR_BALLOON_CLICK,1559)
 END_DECLARE_EVENT_TYPES()
 
 #define wxTaskBarIconEventHandler(func) \
@@ -108,6 +118,11 @@
 #define EVT_TASKBAR_RIGHT_UP(fn)     wx__DECLARE_TASKBAREVT(RIGHT_UP, fn)
 #define EVT_TASKBAR_LEFT_DCLICK(fn)  wx__DECLARE_TASKBAREVT(LEFT_DCLICK, fn)
 #define EVT_TASKBAR_RIGHT_DCLICK(fn) wx__DECLARE_TASKBAREVT(RIGHT_DCLICK, fn)
+
+//MSW only events
+#define EVT_TASKBAR_BALLOON_SHOW(fn)  wx__DECLARE_TASKBAREVT(BALLOON_SHOW, fn)
+#define EVT_TASKBAR_BALLOON_HIDE(fn)  wx__DECLARE_TASKBAREVT(BALLOON_HIDE, fn)
+#define EVT_TASKBAR_BALLOON_CLICK(fn) wx__DECLARE_TASKBAREVT(BALLOON_CLICK, fn)
 
 #endif
     // wxHAS_TASK_BAR_ICON

Index: include/wx/msw/taskbar.h
===================================================================
RCS file: /pack/cvsroots/wxwindows/wxWindows/include/wx/msw/taskbar.h,v
retrieving revision 1.24
diff -u -r1.24 taskbar.h
--- include/wx/msw/taskbar.h	2004/09/07 06:00:52	1.24
+++ include/wx/msw/taskbar.h	2005/08/03 04:56:17
@@ -17,6 +17,7 @@
 #pragma interface "taskbar.h"
 #endif
 
+#include <shellapi.h>
 #include "wx/icon.h"
 
 // private helper class:
@@ -37,6 +38,7 @@
     bool SetIcon(const wxIcon& icon, const wxString& tooltip = wxEmptyString);
     bool RemoveIcon(void);
     bool PopupMenu(wxMenu *menu); //, int x, int y);
+    bool ShowBalloon(wxString title, wxString message, unsigned int timeout = 10000, int icon = NIIF_INFO);
 
 #if WXWIN_COMPATIBILITY_2_4
     wxDEPRECATED( bool IsOK() const );

Index: src/common/taskbarcmn.cpp
===================================================================
RCS file: /pack/cvsroots/wxwindows/wxWindows/src/common/taskbarcmn.cpp,v
retrieving revision 1.10
diff -u -r1.10 taskbarcmn.cpp
--- src/common/taskbarcmn.cpp	2004/09/23 18:20:54	1.10
+++ src/common/taskbarcmn.cpp	2005/08/03 03:57:13
@@ -35,6 +35,9 @@
 DEFINE_EVENT_TYPE( wxEVT_TASKBAR_RIGHT_UP )
 DEFINE_EVENT_TYPE( wxEVT_TASKBAR_LEFT_DCLICK )
 DEFINE_EVENT_TYPE( wxEVT_TASKBAR_RIGHT_DCLICK )
+DEFINE_EVENT_TYPE( wxEVT_TASKBAR_BALLOON_CLICK )
+DEFINE_EVENT_TYPE( wxEVT_TASKBAR_BALLOON_HIDE )
+DEFINE_EVENT_TYPE( wxEVT_TASKBAR_BALLOON_SHOW )
 
 
 BEGIN_EVENT_TABLE(wxTaskBarIconBase, wxEvtHandler)

Index: src/msw/taskbar.cpp
===================================================================
RCS file: /pack/cvsroots/wxwindows/wxWindows/src/msw/taskbar.cpp,v
retrieving revision 1.46
diff -u -r1.46 taskbar.cpp
--- src/msw/taskbar.cpp	2005/05/31 09:20:33	1.46
+++ src/msw/taskbar.cpp	2005/08/03 04:56:05
@@ -165,7 +165,6 @@
     if ( !tooltip.empty() )
     {
         notifyData.uFlags |= NIF_TIP;
-//        lstrcpyn(notifyData.szTip, tooltip.c_str(), WXSIZEOF(notifyData.szTip));
         wxStrncpy(notifyData.szTip, tooltip.c_str(), WXSIZEOF(notifyData.szTip));
     }
 
@@ -315,9 +314,26 @@
         case WM_MOUSEMOVE:
             eventType = wxEVT_TASKBAR_MOVE;
             break;
-
+        
+        case NIN_BALLOONSHOW:
+			//NIN_BALLOONSHOW - Sent when the balloon is shown (balloons are queued).
+			eventType = wxEVT_TASKBAR_BALLOON_SHOW;
+			break;
+		
+		case NIN_BALLOONHIDE:
+			//NIN_BALLOONHIDE - Sent when the balloon disappears - for example, when the
+			//icon is deleted. This message is not sent if the balloon is dismissed
+			//because of a timeout or a mouse click.
+			eventType = wxEVT_TASKBAR_BALLOON_HIDE;
+			break;
+		
+		case NIN_BALLOONUSERCLICK:
+			//NIN_BALLOONUSERCLICK - Sent when the balloon is dismissed because of a mouse click.
+			eventType = wxEVT_TASKBAR_BALLOON_CLICK;
+			break;
+		
         default:
-            break;
+			break;
     }
 
     if (eventType)
@@ -328,6 +344,25 @@
     }
 
     return 0;
+}
+
+bool wxTaskBarIcon::ShowBalloon(wxString title, wxString message, unsigned int timeout, int icon)
+{
+	if (!IsOk())
+	    return false;
+
+	NotifyIconData notifyData((HWND)m_win->GetHWND());
+    notifyData.uFlags = NIF_INFO;
+
+    wxStrncpy(notifyData.szInfo, message.c_str(), WXSIZEOF(notifyData.szInfo));
+    wxStrncpy(notifyData.szInfoTitle, title.c_str(), WXSIZEOF(notifyData.szInfoTitle));
+    notifyData.dwInfoFlags = icon;
+    notifyData.uTimeout = timeout;
+	
+    if (m_iconAdded)
+	    return Shell_NotifyIcon(NIM_MODIFY, &notifyData);
+    else
+        return false;
 }
 
 #endif // __WIN95__
EVT_TASKBAR_BALLOON_SHOW will be triggered when the ballon is shown (ballons take turns to be shown)
EVT_TASKBAR_BALLOON_HIDE will be triggered when the balloon is deleted by the program. It isnt sent when the user dismisses the balloon
EVT_TASKBAR_BALLOON_CLICK will be triggered when the user clicks on the balloon
Trigunflame
In need of some credit
In need of some credit
Posts: 7
Joined: Thu Feb 16, 2006 8:36 pm

Post by Trigunflame »

Does anyone have a working example of this as a standalone class?
Trigunflame
In need of some credit
In need of some credit
Posts: 7
Joined: Thu Feb 16, 2006 8:36 pm

Post by Trigunflame »

Bump?
User avatar
Ryan Norton
wxWorld Domination!
wxWorld Domination!
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton »

Nice Lowjoel - Kudos!

As for it in a seperate class, well that is a good idea as well...
[Mostly retired moderator, still check in to clean up some stuff]
Trikko
Experienced Solver
Experienced Solver
Posts: 94
Joined: Tue Oct 18, 2005 8:28 pm
Location: Venice, IT
Contact:

Post by Trikko »

Ryan Norton wrote:Nice Lowjoel - Kudos!

As for it in a seperate class, well that is a good idea as well...
Digital Mars compiler has some problem with NOTIFYICONDATA....

Code: Select all

   notifyData.uFlags |= NIF_INFO;
                                ^
src\taskbarIcon.cpp(23) : Error: undefined identifier 'NIF_INFO'
   lstrcpyn(notifyData.szInfo, WXSTRINGCAST message, sizeof(notifyData.szInfo));
                             ^
src\taskbarIcon.cpp(25) : Error: 'szInfo' is not a member of struct '_NOTIFYICONDATAA'
   lstrcpyn(notifyData.szInfoTitle, WXSTRINGCAST title, sizeof(notifyData.szInfoTitle)); 
[...]
Any idea?
Ksmith22
I live to help wx-kind
I live to help wx-kind
Posts: 199
Joined: Mon Nov 21, 2005 4:34 pm

Post by Ksmith22 »

Cool, any chance of seeing a version for normal (non task bar icon) bubble tooltips?
mromanuk
In need of some credit
In need of some credit
Posts: 1
Joined: Mon Apr 10, 2006 5:34 am

steal don't get this

Post by mromanuk »

Hello, this is my first message here, I have been using wxWidgets for around 2 months now( I used it before for a while).

Ok, my problem is with this balloon tooltip and the systray. I have tried this code many times but I can't get it to work... I use to work with Linux (crosscompiling with mingw32 for win32) but now I am using a WinXP with devcpp 4.9.9.2 and wxWidgets 2.6.2, and I have the same problem:

As stated by [email protected] upper in this thread, when I do

notifyData.hWnd = (HWND) m_win->GetHWND();

I get this error:
627 C:\install\developer\wx\winsrc\Accounts.cpp invalid use of undefined type `struct wxTaskBarIconWindow'
23 C:\Dev-Cpp\include\wx\msw\taskbar.h forward declaration of `struct wxTaskBarIconWindow'


I don`t know how to fix this...Ok I hope anybody can help me,
Thanks in advance,
Martin
lowjoel
Part Of The Furniture
Part Of The Furniture
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel »

Hey guys,

sorry, have been VERY busy lately, and I probably wont be on the forum much anymore :(

Oldest to newest:
Trikko: define _WIN32_IE > 0x500 (0x600 is best - though 0x500 is the min)
KSmith: I have a working one at the moment, but I'm nt releasing it (yet). See http://joelsplace.sg/documents/files/pu ... -login.png
mromanuk: please provide some code to show me.

Best regards,
Joel
gbd
In need of some credit
In need of some credit
Posts: 2
Joined: Sun Dec 10, 2006 8:54 am

Post by gbd »

Guys, I've read the posts above and tried to get the ballon tips to work, and I just can't, get things to compile.

I get the following errors:

`sm_taskbarMsg' undeclared (first use this function)
'struct NOTIFYICONDATA' has no member named 'szInfo'

Does, anyone have a working example, I'm using wxDevCpp 6.10

Thanks...
JamesPlock
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Aug 09, 2005 5:55 pm
Location: The Netherlands

Post by JamesPlock »

You are sure that you set the makro definition -D_WIN32_IE=0x0500 when you compile the taskbar.cpp?
lowjoel
Part Of The Furniture
Part Of The Furniture
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel »

Then set _WIN32_IE to be 0x600, meh, the Windows SDK isn't clear sometimes...
gbd
In need of some credit
In need of some credit
Posts: 2
Joined: Sun Dec 10, 2006 8:54 am

Any working examples...?

Post by gbd »

Thanks for the ideas, I've tried both of the above, still no good.

Any change someone could give me a working example, with include statements of the relavent files...?

Thanks in advanced.
Post Reply