|
// TrayPosDemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TrayPosDemo.h"
#include "TrayPosDemoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTrayPosDemoDlg dialog
CTrayPosDemoDlg::CTrayPosDemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTrayPosDemoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTrayPosDemoDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTrayPosDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTrayPosDemoDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTrayPosDemoDlg, CDialog)
//{{AFX_MSG_MAP(CTrayPosDemoDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_TRAYNOTIFY, OnTrayNotify)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTrayPosDemoDlg message handlers
BOOL CTrayPosDemoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
NOTIFYICONDATA nid;
nid.cbSize = sizeof nid;
nid.hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
nid.hWnd = m_hWnd;
nid.uCallbackMessage = WM_TRAYNOTIFY;
nid.uID = 1;
nid.uFlags = NIF_ICON | NIF_MESSAGE;
Shell_NotifyIcon(NIM_ADD, &nid);
m_traypos.SetNotifyIconInfo(m_hWnd, 1, WM_TRAYNOTIFY);
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTrayPosDemoDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTrayPosDemoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
LONG CTrayPosDemoDlg::OnTrayNotify(WPARAM wParam, LPARAM lParam)
{
if(wParam == 1)
{
switch(lParam)
{
case WM_MOUSEMOVE:
m_traypos.OnMouseMove();
break;
case WM_MOUSEHOVER:
m_dlg.Create(CBmpDlg::IDD, this);
m_dlg.ShowWindow(SW_SHOW);
break;
case WM_MOUSELEAVE:
m_dlg.ShowWindow(SW_HIDE);
m_dlg.DestroyWindow();
break;
}
}
return 0;
}
void CTrayPosDemoDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
NOTIFYICONDATA nid;
nid.cbSize = sizeof nid;
nid.hWnd = m_hWnd;
nid.uID = 1;
nid.uFlags = 0;
Shell_NotifyIcon(NIM_DELETE, &nid);
}
|
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.
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.