Click here to Skip to main content
15,894,539 members
Articles / Programming Languages / C++

How to implement mouse hover/leave message on system tray.

Rate me:
Please Sign up or sign in to vote.
3.36/5 (9 votes)
23 Aug 20042 min read 86.5K   1.6K   23  
Ever wanted to get mouse hover/leave message from system tray? Windows shell doesn't support that. This class is a solution that works.
// BmpDlg.cpp : implementation file
//

#include "stdafx.h"
#include "TrayPosDemo.h"
#include "BmpDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CBmpDlg dialog


CBmpDlg::CBmpDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBmpDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBmpDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CBmpDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBmpDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBmpDlg, CDialog)
	//{{AFX_MSG_MAP(CBmpDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBmpDlg message handlers

BOOL CBmpDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CRect	rcWorkArea;
	CRect	rcClient;

	SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWorkArea, FALSE);
	GetClientRect(&rcClient);

	SetWindowPos(&wndTopMost, rcWorkArea.right-rcClient.Width()-5, rcWorkArea.bottom-rcClient.Height()-5, 0, 0, SWP_NOSIZE);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Chief Technology Officer Wellbia.com Co., Ltd.
Korea (Republic of) Korea (Republic of)
YoungJin is a co-founder of Wellbia.com Co., Ltd., a security company in South Korea, and Visual C++ Microsoft Most Valuable Professional. He has developed anti-cheat program called XIGNCODE since 2007. He wrote several PC security programs like PC Firewall, Anti-Spyware, and Keyboard Security Software. He has contributed a number of articles about Windows programming to Microsoftware, the famous programming magazine of South Korea. He also hosts a blog (http://www.jiniya.net) that includes articles about system programming on Windows.

Comments and Discussions