readme.wzd

来自「MFC扩展编程实例」· WZD 代码 · 共 68 行

WZD
68
字号
/////////////////////////////////////////////////////////////////////
// Modify any class that can receive a windows message.
/////////////////////////////////////////////////////////////////////


// 1) define a new window message to indicate user has clicked on icon 
//  in system tray
#define WM_SYSTEMTRAY WM_USER+1

// 2) add a message handler for this new message to the message map
// (also define it in this class's include file)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	:	:	:
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_SYSTEMTRAY,OnSystemTray)

// 2) to put an icon in the system tray
    NOTIFYICONDATA nid;
	nid.cbSize = sizeof(NOTIFYICONDATA);
	nid.hWnd = m_hWnd;									 // handle of window that will receive messages from icon
	nid.uID=ID_SYSTEMTRAY; 								 // id for this icon
	nid.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;			 // the next three parameters are valid
	nid.uCallbackMessage=WM_SYSTEMTRAY;					 // message that icon sends when clicked
	nid.hIcon=AfxGetApp()->LoadIcon(IDI_SYSTEMTRAY_ICON);// icon
    strcpy(nid.szTip,"System Tray Tip");				 // bubble help message for icon
	::Shell_NotifyIcon(NIM_ADD,&nid);


// 3) to delete an icon from the system tray
    NOTIFYICONDATA nid;
	nid.cbSize = sizeof(NOTIFYICONDATA);
	nid.hWnd = m_hWnd;
	nid.uID=ID_SYSTEMTRAY; 
	nid.uFlags=0;
	::Shell_NotifyIcon(NIM_DELETE,&nid);


// to handle a system tray icon message
LRESULT CMainFrame::OnSystemTray(WPARAM wParam,LPARAM lParam)
{
	// wParam = the nid.uID defined above (useful if you have more then one icon in tray)
	// lParam = mouse message
	if (wParam==ID_SYSTEMTRAY)
	{
		switch (lParam)
		{
		case WM_LBUTTONDOWN:
			break;

		case WM_RBUTTONDOWN:
			break;

		case WM_LBUTTONDBLCLK:
			break;

		}
	}
	return 1;
}


/////////////////////////////////////////////////////////////////////
// From: Visual C++ MFC Programming by Example by John E. Swanke
// Copyright (C) 1999 jeswanke. All rights reserved.
/////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?