?
Solved

System Tray Icon Hint Message (BCB4.0)

Posted on 2002-05-18
3
Medium Priority
?
589 Views
Last Modified: 2012-08-13
I am using Borland C++ Builder 4.0 pro

I have an application that places an icon in the system tray, when the user minimizes the application it goes to the icon, and can be restored by double clicking the icon.  There also is a hint message that is displayed when the mouse is over the icon.

I would like the message to be updated when the user places the mouse over the icon.

At present I can update the hint message when the application starts, and when the user switches to other parts of the application, but NOT when the user actually has the mouse over the icon (just before the hint message is actually displayed.)

Below are the functions that handle the icon, and where I believe I need to make changes (though I am not 100% for sure about this)

void __fastcall TformMain::AddIcon()
{
   NOTIFYICONDATA IconData;
   IconData.cbSize = sizeof(NOTIFYICONDATA);
   IconData.uID = IDC_TRAYICON;
   IconData.hWnd = Handle;
   IconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
   IconData.uCallbackMessage = WM_TRAYNOTIFY;
   HINT_MESSAGE = displayHintMessage();
   lstrcpy(IconData.szTip, HINT_MESSAGE);
   IconData.hIcon = TrayIcon->Handle;

   Shell_NotifyIcon(NIM_ADD, &IconData);
}

void __fastcall TformMain::ModifyIcon()
{
   NOTIFYICONDATA IconData;
   IconData.cbSize = sizeof(NOTIFYICONDATA);
   IconData.uID = IDC_TRAYICON;
   IconData.hWnd = Handle;
   IconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
   IconData.uCallbackMessage = WM_TRAYNOTIFY;
   HINT_MESSAGE = displayHintMessage();  
   lstrcpy(IconData.szTip, HINT_MESSAGE);
   IconData.hIcon = TrayIcon->Handle;

   Shell_NotifyIcon(NIM_MODIFY, &IconData);
}

void __fastcall TformMain::WMTrayNotify(TMessage &Msg)
{
   switch(Msg.LParam)
   {
      case WM_RBUTTONUP:
         POINT WinPoint;
         GetCursorPos(&WinPoint);
         SetForegroundWindow(Handle);
         popupMenu->Popup(WinPoint.x, WinPoint.y);
         PostMessage(Handle, WM_NULL, 0, 0);
         break;
      case WM_LBUTTONDBLCLK:
         Application->Restore();
         break;
   }
}

Thanks in advance. . .
0
Comment
Question by:LordDamein
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 520 total points
ID: 7018423
In your WMTrayNotify handler, you could check for WM_MOUSEMOVE and at that time, call your ModifyIcon fn to update the text.

In my app, I use a different technique:  I have a timer that checks for status changes once every second, and updates the tip text (via my equivalent of your ModifyIcon() fn) if it has changed.

-- Dan
0
 

Author Comment

by:LordDamein
ID: 7018505
Wow.  I have implemented a timer to check for status changes and update the tip text if needed.  That is a great technique.  Thanks! ! !
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7018586
Glad to help.

You can also change the icon image.  For instance it looks pretty snazzy if the the icon gets a red 'x' over it when the program is stopped.  Advanced: If you cycle the icon changes more often, you can even make the thing look animated (though
that is distracting).

Just a side comment... that technique originally got me into trouble becasue I was doing a LoadIcon with each call -- rather than just assigning IconData.hIcon= a_pre_loaded_handle .

LoadIcon can be called repeatedly without problem (the system just returns the handle to the previously-loaded icon), so that was alright.... until I switched to
    LoadImage(...,...,IMAGE_ICON, 16,16,...)
so that I could display a 16x16 icon (it appears less 'blurred' when displayed in the tray).  In that case, each call to LoadImage chewed up a resouce handle (a resource leak!).  I actually shipped some product that way.  After running for a few hours, the entire operating system started croaking... menus broke, fonts failed, it was embarassing.

-- Dan
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question