Jump to content
  • Advertisement
Sign in to follow this  
eq

Minimizing to the system tray (notification area)

This topic is 4883 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Say I've got an application up and running with a single window. Now, when minimizing my window I'd like it to go into the system tray instead of the task bar. How do I do that? I'm using vanilla Win32 C programming, no MFC etc. Please advice!

Share this post


Link to post
Share on other sites
Advertisement
you have to use the shell functions.
there is sample source on MSDN, look up
Intermediate Shell Techniques under the Visual C++ filter
and there is a section called The Taskbar. You will find
sample source there.

Share this post


Link to post
Share on other sites
Shell_NotifyIcon() is pretty much everything you need. You'll have to trap the message for minimization and override the standard handler.

I believe there's an easy function for doing the "animate window header bar minimizing" thing but I couldn't think of it off the top of my head.


[edit] Here we go, shamelessly stolen from a project here at work:

void CSystemTray::MinimiseToTray(CWnd* pWnd)
{
#ifndef _WIN32_WCE
if (GetDoWndAnimation())
{
CRect rectFrom, rectTo;

pWnd->GetWindowRect(rectFrom);
GetTrayWndRect(rectTo);

::DrawAnimatedRects(pWnd->m_hWnd, IDANI_CAPTION, rectFrom, rectTo);
}

// RemoveTaskbarIcon(pWnd);
pWnd->ShowWindow(SW_HIDE);
#endif
}

void CSystemTray::MaximiseFromTray(CWnd* pWnd)
{
#ifndef _WIN32_WCE
if (GetDoWndAnimation())
{
CRect rectTo;
pWnd->GetWindowRect(rectTo);

CRect rectFrom;
GetTrayWndRect(rectFrom);

pWnd->SetParent(NULL);
::DrawAnimatedRects(pWnd->m_hWnd, IDANI_CAPTION, rectFrom, rectTo);
}
else
pWnd->SetParent(NULL);

pWnd->ShowWindow(SW_SHOW);
pWnd->CenterWindow();
pWnd->RedrawWindow(NULL, NULL, RDW_UPDATENOW | RDW_ALLCHILDREN | RDW_FRAME |
RDW_INVALIDATE | RDW_ERASE);

// Move focus away and back again to ensure taskbar icon is recreated
if (::IsWindow(m_wndInvisible.m_hWnd))
m_wndInvisible.SetActiveWindow();
pWnd->SetActiveWindow();
pWnd->SetForegroundWindow();
#endif
}



It works off of MFC but it should be very easy to clean out that code and adapt it to straight Win32. The code is from a class by Chris Maunder - a google for CSystemTray should turn up the full source for it. There's also some nice functions for doing the popup balloons in Win2k and XP as well as other general management stuff. I don't like the code itself (it's very messy and some of the more advanced features are buggy) but it's a good place to learn how it all works in practice.

Share this post


Link to post
Share on other sites
Thanks all, doesn't seem to be that hard, have some things to do before actually implementing it (just wanted to get an idea on how much work was involved).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!