Jump to content
  • Advertisement
Sign in to follow this  
CProgrammer

iconed window

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

How does one make applications that only appear as an icon in the bottom right corner. An example being msn messenger. Im also curious as to how msn messenger draws the little pop up windows when someone goes online. Thanks in advance. -CProgrammer

Share this post


Link to post
Share on other sites
Advertisement
The Widnows Form NotifyIcon does this form you, the box you are talking about is a tooltip. Hope that helps.

theTroll

Share this post


Link to post
Share on other sites
What language / OS? Assuming Win32 / C++:
Shell_NotifyIcon. As for the popup windows, I believe they're just top level windows created with CreateWindowEx.

Edit: From some of my code:

#define WM_SHELLNOTIFY WM_USER+1

void CWindow::AddToSystemTray()
{
// Fill in the NOTIFYICONDATA structure //
m_theNotifyData.cbSize = sizeof(m_theNotifyData);
m_theNotifyData.hWnd = m_hWnd;
m_theNotifyData.uID = IDM_POPUP;
m_theNotifyData.hIcon = LoadIcon(m_hInstance,MAKEINTRESOURCE(IDI_MAIN));
m_theNotifyData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
m_theNotifyData.uCallbackMessage = WM_SHELLNOTIFY;
strcpy(m_theNotifyData.szTip,"Druink IM");

// Add to system tray //
Shell_NotifyIcon(NIM_ADD,&m_theNotifyData);
}

void CWindow::RemoveFromSystemTray()
{
Shell_NotifyIcon(NIM_DELETE,&m_theNotifyData);
ZeroMemory(&m_theNotifyData,sizeof(NOTIFYICONDATA));
}

void CWindow::SetSystemTrayTooltip(const string& strTip)
{
strncpy(m_theNotifyData.szTip,strTip.c_str(),64);
Shell_NotifyIcon(NIM_MODIFY,&m_theNotifyData);
}

// In my window proc:
case WM_SHELLNOTIFY:
OnTrayNotify(wParam,lParam);
break;


And then for OnTrayNotify:

void CWindow::OnTrayNotify(WPARAM wParam, LPARAM lParam)
{
// Left mouse activates window //
if(LOWORD(lParam) == WM_LBUTTONDBLCLK)
{
SendMessage(m_hWnd,WM_COMMAND,IDM_SHOWWINDOW,0);
return;
}

// Clicking with right button brings up a context menu //
if(LOWORD(lParam) != WM_RBUTTONUP)
return;

HMENU hMenu = LoadMenu(m_hInstance,MAKEINTRESOURCE(IDM_POPUP));
if(!hMenu)
return;

HMENU hSubMenu = GetSubMenu(hMenu,0);
if(!hSubMenu)
{
DestroyMenu(hMenu);
return;
}

SetMenuDefaultItem(hSubMenu,0,TRUE);

// Display and track the popup menu
POINT pt;
GetCursorPos(&pt);
TrackPopupMenu(hSubMenu,0,pt.x,pt.y,0,m_hWnd,NULL);
PostMessage(m_hWnd,WM_NULL,0,0);

DestroyMenu(hMenu);
DestroyMenu(hSubMenu);
}


You'll also have to hide the main window yourself when you add the tray icon, with ShowWindow(hWnd, SW_HIDE).

Share this post


Link to post
Share on other sites
Hmm, ignore the PostMessage(m_hWnd,WM_NULL,0,0); part - that was from some debug code I think... Let me know if you have any questions about that code, some of it's a bit of a mess [smile]

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!