当前位置:网站首页>Notifyicondata tray used by BCG
Notifyicondata tray used by BCG
2022-07-23 09:21:00 【51CTO】
(1) The header file
// TryMenuDemoDlg.h : header file
//#pragma once
// CTryMenuDemoDlg dialog
class CTryMenuDemoDlg : public CBCGPDialog
{
// Construction
public:
CTryMenuDemoDlg(CWnd* pParent = NULL); // standard constructor// Dialog Data
enum { IDD = IDD_TRYMENUDEMO_DIALOG }; protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support // Implementation
protected:
HICON m_hIcon; // Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedOk(); void OnTrayContextMenu();
afx_msg LRESULT OnTrayNotify(WPARAM wp, LPARAM lp);
virtual void SetActiveMenu(CBCGPPopupMenu* pMenu);
afx_msg void OnAppExit();
afx_msg void OnAppOpen();
afx_msg void OnClose(); NOTIFYICONDATA m_nid; // struct for Shell_NotifyIcon args
};
The content added is :void OnTrayContextMenu();
afx_msg LRESULT OnTrayNotify(WPARAM wp, LPARAM lp);
virtual void SetActiveMenu(CBCGPPopupMenu* pMenu);
afx_msg void OnAppExit();
afx_msg void OnAppOpen();
afx_msg void OnClose(); NOTIFYICONDATA m_nid; // struct for Shell_NotifyIcon args
(2) In the implementation file
// TryMenuDemoDlg.cpp : implementation file
//#include "stdafx.h"
#include "TryMenuDemo.h"
#include "TryMenuDemoDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#endifCTryMenuDemoDlg::CTryMenuDemoDlg(CWnd* pParent /*=NULL*/)
: CBCGPDialog(CTryMenuDemoDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); //... Need to add Initialize tray
memset(&m_nid, 0, sizeof(m_nid));
m_nid.cbSize = sizeof(m_nid);
m_nid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE; EnableVisualManagerStyle(TRUE, TRUE);
}void CTryMenuDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CBCGPDialog::DoDataExchange(pDX);
}#define UM_TRAYNOTIFY (WM_USER + 1)
BEGIN_MESSAGE_MAP(CTryMenuDemoDlg, CBCGPDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDOK, &CTryMenuDemoDlg::OnBnClickedOk) ON_MESSAGE(UM_TRAYNOTIFY, OnTrayNotify)
ON_COMMAND(ID_APP_EXIT, OnAppExit) // In the tray sign out
ON_COMMAND(ID_APP_OPEN, OnAppOpen)// In the tray open ON_WM_CLOSE() // Click the dialog box to close Button hide
END_MESSAGE_MAP()
// CTryMenuDemoDlg message handlers
void CTryMenuDemoDlg::OnAppExit()
{
CBCGPDialog::OnCancel();
}void CTryMenuDemoDlg::OnAppOpen()
{
ShowWindow(SW_SHOWNORMAL);
}void CTryMenuDemoDlg::OnClose()
{
ShowWindow(SW_HIDE);
}LRESULT CTryMenuDemoDlg::OnTrayNotify(WPARAM /*wp*/, LPARAM lp)
{
UINT uiMsg = (UINT)lp; switch (uiMsg)
{
case WM_RBUTTONUP:
OnTrayContextMenu();
return 1; case WM_LBUTTONDBLCLK:
ShowWindow(SW_SHOWNORMAL);
return 1;
} return 0;
}void CTryMenuDemoDlg::OnTrayContextMenu()
{
CPoint point;
::GetCursorPos(&point); CMenu menu;
menu.LoadMenu(IDR_MENU1); if (menu.GetSafeHmenu() == NULL)
{
return;
} CBCGPPopupMenu::SetForceShadow(TRUE);
HMENU hMenu = menu.GetSubMenu(0)->Detach();
CBCGPPopupMenu* pMenu = GetWorkspace()->GetContextMenuManager()->ShowPopupMenu(
hMenu, point.x, point.y, this, TRUE); pMenu->SetWindowPos(&wndTopMost, -1, -1, -1, -1, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
pMenu->SetForegroundWindow();
}void CTryMenuDemoDlg::SetActiveMenu(CBCGPPopupMenu* pMenu)
{
CBCGPDialog::SetActiveMenu(pMenu); if (pMenu != NULL)
{
pMenu->SetWindowPos(&wndTopMost, -1, -1, -1, -1, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
pMenu->SetForegroundWindow();
}
}BOOL CTryMenuDemoDlg::OnInitDialog()
{
CBCGPDialog::OnInitDialog(); // Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
{
m_nid.hWnd = GetSafeHwnd();
m_nid.uCallbackMessage = UM_TRAYNOTIFY; // Set tray icon and tooltip:
m_nid.hIcon = m_hIcon; CString strToolTip = _T("BCGPTrayDemo");
_tcsncpy(m_nid.szTip, strToolTip, strToolTip.GetLength()); Shell_NotifyIcon(NIM_ADD, &m_nid);
// This sentence can not be , If not , Then there are no pictures in the tray
CBCGPToolBar::AddToolBarForImageCollection(IDR_MENUIMAGES, IDB_MENU_HC);
} return TRUE; // return TRUE unless you set the focus to a control
}void CTryMenuDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
CBCGPDialog::OnSysCommand(nID, lParam);
}// 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 CTryMenuDemoDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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
{
CBCGPDialog::OnPaint();
}
}// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTryMenuDemoDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}void CTryMenuDemoDlg::OnBnClickedOk()
{
// TODO: Add control notification handler code here
}
Resources :
resource.h
#define IDR_MENU1 129
#define ID_APP_OPEN 130#define IDR_MENUIMAGES 131
#define IDB_MENU_HC 132rc file :
/
//
// Toolbar
//IDR_MENUIMAGES TOOLBAR DISCARDABLE 16, 16
BEGIN
BUTTON ID_APP_OPEN
BUTTON ID_APP_EXIT
END/
//
// Bitmap
//
IDR_MENUIMAGES BITMAP DISCARDABLE "res\\menuimag.bmp"/
//
// PNG
//
IDB_MENU_HC PNG DISCARDABLE "res\\menuimag.png" /
//
// Menu
//IDR_MENU1 MENU DISCARDABLE
BEGIN
POPUP "Tray"
BEGIN
MENUITEM "&Open....", ID_APP_OPEN
MENUITEM SEPARATOR
MENUITEM "E&xit", ID_APP_EXIT
END
END
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
- 156.
- 157.
- 158.
- 159.
- 160.
- 161.
- 162.
- 163.
- 164.
- 165.
- 166.
- 167.
- 168.
- 169.
- 170.
- 171.
- 172.
- 173.
- 174.
- 175.
- 176.
- 177.
- 178.
- 179.
- 180.
- 181.
- 182.
- 183.
- 184.
- 185.
- 186.
- 187.
- 188.
- 189.
The above is the code to realize the tray
边栏推荐
- [cann training camp] learning notes - Comparison between diffusion and Gan, dalle2 and Party
- How many points can you get on the latest UnionPay written test for test engineers?
- 关系表达式 大于> 小于< 全等=== Nan isNan() 逻辑运算符 双感叹号!! && || % ++ -- 短路计算 赋值表达式 快捷运算符 顺序 闰年
- Mathematical modeling -- graph and network models and methods (II)
- Anti attack based on conjugate gradient method
- 一文了解微服务低代码实现方式
- php获取证书编号没有serialNumberHex只有serialNumber处理方法
- PyG利用MessagePassing搭建GCN实现节点分类
- RNA 25. SCI文章中只有生信没有实验该怎么办?
- Transformer summary
猜你喜欢

涨薪神器

模板学堂丨JumpServer安全运维审计大屏

C语言实战之猜数游戏

Wallys/DR4019S/IPQ4019/11ABGN/802.11AC/high power

真人踩過的坑,告訴你避免自動化測試常犯的10個錯誤

La fosse Piétinée par l'homme vous dit d'éviter les 10 erreurs courantes dans les tests automatisés

Software testing interview ideas, skills and methods to share, learn is to earn

Solve the greatest common divisor and the least common multiple

RNA 25. SCI文章中只有生信没有实验该怎么办?

SPSS Chi-Square
随机推荐
What is the combined effect of compose and recyclerview?
驱动单片机硬件调试器的一些开源库总结(包含stlink调试器)
涨薪神器
Understand the box model, and the basic methods of box model's frame, internal and external margins, horizontal layout, vertical layout, setting floating, and dealing with height collapse
推荐系统专题 | 推荐系统架构与单域跨域召回模型
The role of include in makefile
软件测试面试思路技巧和方法分享,学到就是赚到
网站建设开始前要考虑的7个问题
[Huawei online battle service] how can new players make up frames when the client quits reconnection or enters the game halfway?
Pytorch visualization
727. 最小窗口子序列 滑动窗口
Stream操作之 先分组再取最大值
Advantages of implementing automatic network performance monitoring
TP5框架 之链接推广项目
真人踩過的坑,告訴你避免自動化測試常犯的10個錯誤
SPSS Chi-Square
【无标题】
程序员不会 jvm?骨灰级工程师:全等着被淘汰吧!这是必会技能!
Is it safe to buy shares and open an account? Will you lose money?
BGP机房的优点