Solved

System Tray Icon Hint Message (BCB4.0)

Posted on 2002-05-18
3
586 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 130 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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

696 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