| |

VerySource

 Forgot password?
 Register
Search
Author: wangwei1202

Right-click, occasionally the tray system menu and its own pop-up menu will be displayed at the same time. How to solve

[Copy link]

0

Threads

18

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-7-22 06:30:01
| Show all posts
Can't understand English!
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-25 18:30:01
| Show all posts
Try this code
Before the menu pops up
::SetForegroundWindow(m_nid.hWnd);
After the pop-up menu
::PostMessage(m_nid.hWnd, WM_NULL, 0, 0);
Reply

Use magic Report

2

Threads

15

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-8-6 10:00:01
| Show all posts
No, the problem remains.
I implore the expert to advise...
Reply

Use magic Report

0

Threads

57

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-8-6 19:30:02
| Show all posts
What did you do when responding to the right-click message, look at the code
Reply

Use magic Report

0

Threads

30

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-8-6 20:00:01
| Show all posts
Currently, this is not a system bug
It should be that the user clicked on the wrong location, or your program itself is wrong.
Reply

Use magic Report

2

Threads

15

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-8-6 23:45:01
| Show all posts
Please help me, the following is my tray implementation class:
///////////////////////////////////////////////// /////////////////////////////////////
// preprocessing
#include "TrayIcon.h"
///////////////////////////////////////////////// /////////////////////////////////////



///////////////////////////////////////////////// /////////////////////////////////////
// Initialize
CTrayIcon::CTrayIcon()
{
m_bHealth = TRUE;
}
CTrayIcon::~CTrayIcon()
{
}
///////////////////////////////////////////////// /////////////////////////////////////



///////////////////////////////////////////////// /////////////////////////////////////
// right click menu
VOID CTrayIcon::OnTrayNotify(WPARAM wParam, LPARAM lParam)
{
if(wParam != m_nid.uID)
return;
To
SetForegroundWindow(m_nid.hWnd);
To
switch(LOWORD(lParam))
{
    case WM_RBUTTONUP:{
// Filter system menu
/*
HWND hTray = FindWindow(TEXT("Shell_TrayWnd"), NULL);
hTray = FindWindowEx(hTray, NULL, TEXT("TrayNotifyWnd"), NULL);
DestroyMenu( GetMenu(hTray) );
hTray = NULL;
*/
// Show menu
HMENU hMenuMain = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(m_nid.uID));
if(hMenuMain == NULL)
return;
HMENU hMenuTray = GetSubMenu(hMenuMain, 0);
if(hMenuTray == NULL)
return;
POINT point;
GetCursorPos(&point);
// Whether the health assistant is enabled
UINT Checked = m_bHealth? MF_CHECKED: MF_UNCHECKED;
CheckMenuItem(hMenuTray, IDM_App_Health, MF_BYCOMMAND | Checked);
// Suspend overdue reminders
BOOL bPause = CIniFile::ReadInteger(TEXT("TEMP"), TEXT("PAUSEREMIND"), 0);
Checked = bPause? MF_CHECKED: MF_UNCHECKED;
CheckMenuItem(hMenuTray, IDM_App_PauseRemind, MF_BYCOMMAND | Checked);
// Whether the tray icon is selected
BOOL bIcon = CIniFile::ReadInteger(TEXT("GLOBAL"), TEXT("TrayIcon"), 1);
Checked = bIcon? MF_CHECKED: MF_UNCHECKED;
CheckMenuItem(hMenuTray, IDM_App_TrayIcon, MF_BYCOMMAND | Checked);
// Whether low internet speed shutdown is enabled
BOOL bNetSpeed ​​= CIniFile::ReadInteger(TEXT("SHUTDOWN"), TEXT("NetSpeedShut"), 0);
Checked = bNetSpeed? MF_CHECKED: MF_UNCHECKED;
CheckMenuItem(hMenuTray, IDM_App_NetSpeed, MF_BYCOMMAND | Checked);
// The setting menu is displayed in bold
MENUITEMINFO mmi = {sizeof(MENUITEMINFO)};
mmi.fMask = MIIM_STATE;
mmi.fState = MFS_DEFAULT;
SetMenuItemInfo(hMenuMain, IDM_App_Setting, FALSE,&mmi);
SetMenuItemInfo(hMenuMain, IDM_App_Remind, FALSE,&mmi);
// Show menu
TrackPopupMenu(hMenuTray, 0, point.x, point.y, 0, m_nid.hWnd, NULL);
PostMessage(m_nid.hWnd, WM_NULL, 0, 0);
// destroy
DestroyMenu(hMenuTray);
DestroyMenu(hMenuMain);
break;}

case WM_LBUTTONDBLCLK:
if(m_DbClickMenuItem != 0)
SendMessage(m_nid.hWnd, WM_COMMAND, m_DbClickMenuItem, 0);
break;
To
case WM_LBUTTONUP:
if (m_LeftClickMenuItem != 0)
SendMessage(m_nid.hWnd, WM_COMMAND, m_LeftClickMenuItem, 0);
break;
}
//CSystemTray::OnTrayNotify(wParam, lParam);
}
///////////////////////////////////////////////// /////////////////////////////////////
The following has nothing to do with the tray menu, omitted...
Reply

Use magic Report

2

Threads

15

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-8-7 00:30:01
| Show all posts
///////////////////////////////////////////////// /////////////////////////////////////
// preprocessing
#include "SysTray.h"
///////////////////////////////////////////////// /////////////////////////////////////



///////////////////////////////////////////////// /////////////////////////////////////
// Initialize
CSystemTray::CSystemTray()
{
m_DbClickMenuItem = 0;
m_LeftClickMenuItem = 0;
m_IconCount = 0;
m_TimerId = 0;
m_pIconList = NULL;
}

CSystemTray::~CSystemTray()
{
if(m_pIconList != NULL)
delete m_pIconList;
}
///////////////////////////////////////////////// /////////////////////////////////////



///////////////////////////////////////////////// /////////////////////////////////////
// Create tray icon
BOOL CSystemTray::Create(HWND hWndParent, UINT CallbackMessage, const TCHAR *pToolTip,
HICON hIcon, UINT MenuID)
{
assert(CallbackMessage >= WM_USER);
assert(lstrlen(pToolTip) <128);
m_nid.cbSize = sizeof(m_nid);
m_nid.uCallbackMessage = CallbackMessage;
m_nid.uFlags = NIF_ICON | NIF_TIP;
m_nid.hIcon = hIcon;
m_nid.hWnd = hWndParent;
m_nid.uID = MenuID;
lstrcpyn(m_nid.szTip, pToolTip, 128);
return Shell_NotifyIcon(NIM_ADD,&m_nid)? true: false;
}
///////////////////////////////////////////////// /////////////////////////////////////



///////////////////////////////////////////////// /////////////////////////////////////
// Add tray message response
BOOL CSystemTray::EnableTrayMessage()
{
m_nid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
return Shell_NotifyIcon(NIM_MODIFY,&m_nid)? true: false;
}
///////////////////////////////////////////////// /////////////////////////////////////



///////////////////////////////////////////////// /////////////////////////////////////
// Set the right-click menu
BOOL CSystemTray::SetMenu(UINT MenuID)
{
m_nid.uID = MenuID;
To
return Shell_NotifyIcon(NIM_MODIFY,&m_nid)? true: false;
}
///////////////////////////////////////////////// /////////////////////////////////////



///////////////////////////////////////////////// /////////////////////////////////////
// Right-click menu message response
VOID CSystemTray::OnTrayNotify(WPARAM wParam, LPARAM lParam)
{
if(wParam != m_nid.uID)
return;
To
SetForegroundWindow(m_nid.hWnd);
To
switch(LOWORD(lParam))
{
    case WM_RBUTTONUP:{
HMENU hMenuMain = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(m_nid.uID));
if(hMenuMain == NULL)
return;
HMENU hMenuTray = GetSubMenu(hMenuMain, 0);
if(hMenuTray == NULL)
return;
POINT MousePos;
GetCursorPos(&MousePos);
// show
TrackPopupMenu(hMenuTray, 0, //TPM_CENTERALIGN | TPM_RIGHTBUTTON,
MousePos.x, MousePos.y, 0, m_nid.hWnd, NULL);
// destroy
DestroyMenu(hMenuTray);
DestroyMenu(hMenuMain);
break;}
To
    case WM_LBUTTONDBLCLK:
if(m_DbClickMenuItem != 0)
SendMessage(m_nid.hWnd, WM_COMMAND, m_DbClickMenuItem, 0);
break;
To
    case WM_LBUTTONUP:
if(m_LeftClickMenuItem != 0)
SendMessage(m_nid.hWnd, WM_COMMAND, m_LeftClickMenuItem, 0);
break;
}
}
///////////////////////////////////////////////// /////////////////////////////////////



///////////////////////////////////////////////// /////////////////////////////////////
// delete tray icon
VOID CSystemTray::RemoveIcon()
{
Shell_NotifyIcon(NIM_DELETE,&m_nid);
}
///////////////////////////////////////////////// /////////////////////////////////////



///////////////////////////////////////////////// /////////////////////////////////////
// Set tray prompt information
BOOL CSystemTray::SetTooltipText(const TCHAR *pToolTips)
{
m_nid.uFlags = NIF_TIP;
lstrcpyn(m_nid.szTip, pToolTips, 128);
To
return Shell_NotifyIcon(NIM_MODIFY,&m_nid)? true: false;
}
///////////////////////////////////////////////// /////////////////////////////////////



///////////////////////////////////////////////// /////////////////////////////////////
// Tray balloon prompt
BOOL CSystemTray::ShowBalloonTip(LPCTSTR lpszTitle, LPCTSTR lpszMsg, DWORD dwInfoFlags, UINT nTimeout/*=3000*/)
{
if(!(m_nid.uFlags&NIF_INFO))
m_nid.uFlags |= NIF_INFO;
m_nid.uTimeout = nTimeout;
m_nid.dwInfoFlags = dwInfoFlags;
lstrcpy(m_nid.szInfoTitle, lpszTitle);
lstrcpy(m_nid.szInfo, lpszMsg);
To
return Shell_NotifyIcon(NIM_MODIFY,&m_nid)? true: false;
}
///////////////////////////////////////////////// /////////////////////////////////////



///////////////////////////////////////////////// /////////////////////////////////////
// Set tray icon
BOOL CSystemTray::SetIcon(HICON hIcon)
{
m_nid.uFlags = NIF_ICON;
m_nid.hIcon = hIcon;
To
return Shell_NotifyIcon(NIM_MODIFY,&m_nid)? true: false;
}
BOOL CSystemTray::SetIcon(UINT IconID)
{
HICON hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IconID));
assert(hIcon != NULL);
To
return SetIcon(hIcon);
}
///////////////////////////////////////////////// /////////////////////////////////////



///////////////////////////////////////////////// /////////////////////////////////////
// Create a list of tray dynamic icons
BOOL CSystemTray::CreateIconList(UINT FirstIconID, UINT LastIconID)
{
m_IconCount = LastIconID-FirstIconID + 1;
assert(m_IconCount> 1&&m_IconCount <= 20);
To
if(m_pIconList != NULL)
delete m_pIconList;
To
m_pIconList = new HICON[m_IconCount];
assert(m_pIconList != NULL);
To
HINSTANCE hInstance = GetModuleHandle(NULL);
for(UINT CurIconID = FirstIconID; CurIconID <= LastIconID; CurIconID++)
{
HICON hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(CurIconID));
assert(hIcon != NULL);
To
m_pIconList[CurIconID-FirstIconID] = hIcon;
}
To
return true;
}
///////////////////////////////////////////////// /////////////////////////////////////



///////////////////////////////////////////////// /////////////////////////////////////
// Tray dynamic icon
static CSystemTray *pThis = NULL;
static VOID CALLBACK AnimateTimerProc(HWND hWnd, UINT Msg, UINT_PTR IdEvent, DWORD Time)
{
if(pThis == NULL)
return;
To
static INT Steps = 0;
pThis->SetIcon(pThis->m_pIconList[Steps]);
To
Steps++;
if(Steps >= pThis->m_IconCount)
Steps = 0;
}
BOOL CSystemTray::BeginAnimate(UINT DelayMilliSeconds)
{
assert(m_pIconList != NULL);
if(m_pIconList == NULL)
return false;
To
pThis = this;
To
m_TimerId = (UINT)SetTimer(NULL, 0, DelayMilliSeconds, (TIMERPROC)AnimateTimerProc);
return m_TimerId != 0;
}
VOID CSystemTray::StopAnimate()
{
assert(m_TimerId != 0);
if(m_TimerId == 0)
return;
To
KillTimer(NULL, m_TimerId);
m_TimerId = 0;
}
///////////////////////////////////////////////// /////////////////////////////////////
Reply

Use magic Report

0

Threads

57

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-8-7 02:00:01
| Show all posts
SetForegroundWindow(hDlg);
with
PostMessage(hDlg, WM_NULL, 0, 0);

Still not added
Reply

Use magic Report

2

Threads

15

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-8-7 10:15:02
| Show all posts
No, I inherited from CSysTray class to CTrayIcon.

Respond to the right-click menu in CTrayIcon.
Reply

Use magic Report

2

Threads

15

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-8-7 10:30:01
| Show all posts
SetForegroundWindow(hDlg);
with
PostMessage(hDlg, WM_NULL, 0, 0);

Added to CTrayIcon.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list