43 #ifndef QT_NO_SYSTEMTRAYICON 46 #define _WIN32_WINNT 0x0600 50 #define _WIN32_IE 0x600 57 #include <private/qsystemlibrary_p.h> 58 #include <QApplication> 66 #define MYWM_NOTIFYICON (WM_APP+101) 75 #ifndef NOTIFYICON_VERSION_4 76 #define NOTIFYICON_VERSION_4 4 80 #define NIN_SELECT (WM_USER + 0) 84 #define NIN_KEYSELECT (WM_USER + 1) 87 #ifndef NIN_BALLOONTIMEOUT 88 #define NIN_BALLOONTIMEOUT (WM_USER + 4) 91 #ifndef NIN_BALLOONUSERCLICK 92 #define NIN_BALLOONUSERCLICK (WM_USER + 5) 96 #define NIF_SHOWTIP 0x00000080 99 #define Q_MSGFLT_ALLOW 1 110 bool winEvent(
MSG *m,
long *result );
111 bool trayMessage(DWORD msg);
112 void setIconContents(NOTIFYICONDATA &
data);
114 QRect findIconGeometry(
const int a_iButtonID);
128 #ifndef QT_NO_SETTINGS 138 : hIcon(0), q(object), ignoreNextMouseRelease(false)
160 if (pChangeWindowMessageFilterEx) {
167 if (pChangeWindowMessageFilter) {
182 tnd.uFlags |= NIF_MESSAGE | NIF_ICON | NIF_TIP;
205 Q_ASSERT_X(
false,
"QSystemTrayIconSys::showMessage",
"Invalid QSystemTrayIcon::MessageIcon value");
215 memcpy(tnd.szInfo, message.
utf16(),
qMin(message.
length() + 1, 256) *
sizeof(
wchar_t));
216 memcpy(tnd.szInfoTitle, title.
utf16(),
qMin(title.
length() + 1, 64) *
sizeof(
wchar_t));
222 tnd.uTimeout = uSecs;
227 return Shell_NotifyIcon(NIM_MODIFY, &tnd);
243 if (msg == NIM_ADD || msg == NIM_MODIFY) {
247 bool success = Shell_NotifyIcon(msg, &tnd);
250 return success && Shell_NotifyIcon(NIM_SETVERSION, &tnd);
262 const int iconSizeX = GetSystemMetrics(SM_CXSMICON);
263 const int iconSizeY = GetSystemMetrics(SM_CYSMICON);
282 message = LOWORD(m->lParam);
299 case WM_LBUTTONDBLCLK:
342 sys->trayMessage(NIM_ADD);
356 if (Shell_NotifyIconGetRect) {
358 memset(&nid, 0,
sizeof(nid));
364 HRESULT hr = Shell_NotifyIconGetRect(&nid, &rect);
366 return QRect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
374 HWND trayHandle = FindWindow(L
"Shell_TrayWnd", NULL);
378 trayHandle = FindWindowEx(trayHandle, NULL, L
"TrayNotifyWnd", NULL);
380 HWND hwnd = FindWindowEx(trayHandle, NULL, L
"SysPager", NULL);
382 hwnd = FindWindowEx(hwnd, NULL, L
"ToolbarWindow32", NULL);
392 GetWindowThreadProcessId(trayHandle, &processID);
396 HANDLE trayProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ, 0, processID);
400 int buttonCount = SendMessage(trayHandle, TB_BUTTONCOUNT, 0, 0);
401 LPVOID
data = VirtualAllocEx(trayProcess, NULL,
sizeof(TBBUTTON), MEM_COMMIT, PAGE_READWRITE);
403 if ( buttonCount < 1 || !data ) {
404 CloseHandle(trayProcess);
409 for (
int toolbarButton = 0; toolbarButton < buttonCount; ++toolbarButton ) {
411 DWORD appData[2] = { 0, 0 };
412 SendMessage(trayHandle, TB_GETBUTTON, toolbarButton , (LPARAM)data);
414 if (!ReadProcessMemory(trayProcess, data, &buttonData,
sizeof(TBBUTTON), &numBytes))
417 if (!ReadProcessMemory(trayProcess, (LPVOID) buttonData.dwData, appData,
sizeof(appData), &numBytes))
420 int currentIconId = appData[1];
421 HWND currentIconHandle = (HWND) appData[0];
422 bool isHidden = buttonData.fsState & TBSTATE_HIDDEN;
424 if (currentIconHandle ==
winId() &&
425 currentIconId == iconId && !
isHidden) {
426 SendMessage(trayHandle, TB_GETITEMRECT, toolbarButton , (LPARAM)data);
427 RECT iconRect = {0, 0, 0, 0};
428 if(ReadProcessMemory(trayProcess, data, &iconRect,
sizeof(RECT), &numBytes)) {
429 MapWindowPoints(trayHandle, NULL, (LPPOINT)&iconRect, 2);
431 iconRect.right - iconRect.left - 2,
432 iconRect.bottom - iconRect.top - 2);
439 VirtualFreeEx(trayProcess, data, 0, MEM_RELEASE);
440 CloseHandle(trayProcess);
452 else uSecs = (int)timeOut;
459 messageString = message.
left(255) +
QChar();
464 sys->showMessage(titleString, messageString,
type, uSecs);
480 sys->trayMessage(NIM_DELETE);
490 HICON hIconToDestroy = sys->hIcon;
493 sys->trayMessage(NIM_MODIFY);
496 DestroyIcon(hIconToDestroy);
509 sys->trayMessage(NIM_MODIFY);
void showMessage_sys(const QString &msg, const QString &title, QSystemTrayIcon::MessageIcon icon, int secs)
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for setting key.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
BOOL(WINAPI * PtrChangeWindowMessageFilter)(UINT message, DWORD dwFlag)
The QSettings class provides persistent platform-independent application settings.
int length() const
Returns the number of characters in this string.
#define NIN_BALLOONUSERCLICK
static WinVersion windowsVersion()
Returns the version of the Windows operating system on which the application is run (Windows only)...
QRect geometry_sys() const
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
static bool allowsMessages()
bool winEvent(MSG *m, long *result)
This special event handler can be reimplemented in a subclass to receive native Windows events which ...
The QString class provides a Unicode character string.
static bool supportsMessages_sys()
The QChar class provides a 16-bit Unicode character.
void activated(QSystemTrayIcon::ActivationReason reason)
This signal is emitted when the user activates the system tray icon.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QString toolTip
the tooltip for the system tray entry
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
static bool isSystemTrayAvailable_sys()
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
QRect findIconGeometry(const int a_iButtonID)
void setIconContents(NOTIFYICONDATA &data)
static const char * data(const QByteArray &arr)
QMenu * contextMenu() const
Returns the current context menu for the system tray entry.
static uint MYWM_TASKBARCREATED
QIcon icon
the system tray icon
bool ignoreNextMouseRelease
bool showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs)
bool isNull() const
Returns true if this string is null; otherwise returns false.
#define Q_ASSERT_X(cond, where, what)
void * resolve(const char *symbol)
HICON toWinHICON() const
Returns the HICON handle.
QSize actualSize(const QSize &size, Mode mode=Normal, State state=Off) const
Returns the actual size of the icon for the requested size, mode, and state.
The QPoint class defines a point in the plane using integer precision.
static const UINT q_uNOTIFYICONID
The QRect class defines a rectangle in the plane using integer precision.
static int iconFlag(QSystemTrayIcon::MessageIcon icon)
The QPixmap class is an off-screen image representation that can be used as a paint device...
bool trayMessage(DWORD msg)
QPixmap pixmap(const QSize &size, Mode mode=Normal, State state=Off) const
Returns a pixmap with the requested size, mode, and state, generating one if necessary.
The QSize class defines the size of a two-dimensional object using integer point precision.
#define NOTIFYICON_VERSION_4
HRESULT(WINAPI * PtrShell_NotifyIconGetRect)(const Q_NOTIFYICONIDENTIFIER *identifier, RECT *iconLocation)
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
MessageIcon
This enum describes the icon that is shown when a balloon message is displayed.
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
QSystemTrayIconSys(QSystemTrayIcon *icon, QSystemTrayIconPrivate *d)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
BOOL(WINAPI * PtrChangeWindowMessageFilterEx)(HWND hWnd, UINT message, DWORD action, void *pChangeFilterStruct)
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
The QSystemTrayIcon class provides an icon for an application in the system tray. ...
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.
void messageClicked()
This signal is emitted when the message displayed using showMessage() was clicked by the user...
The QIcon class provides scalable icons in different modes and states.