Sign in to follow this  

Minimizing to the system tray (notification area)

This topic is 4668 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
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

This topic is 4668 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this