2 * Copyright 2004 Martin Fuchs
4 * Pass on icon notification messages to the systray implementation
5 * in the currently running shell.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
26 /* copy data structure for tray notifications */
27 typedef struct TrayNotifyCDS_Dummy
{
30 DWORD nicon_data
[1]; // placeholder for NOTIFYICONDATA structure
31 } TrayNotifyCDS_Dummy
;
33 /* The only difference between Shell_NotifyIconA and Shell_NotifyIconW is the call to SendMessageA/W. */
34 static BOOL
SHELL_NotifyIcon(DWORD dwMessage
, void* pnid
, HWND nid_hwnd
, DWORD nid_size
, BOOL unicode
)
40 int len
= FIELD_OFFSET(TrayNotifyCDS_Dummy
, nicon_data
) + nid_size
;
42 TrayNotifyCDS_Dummy
* pnotify_data
= (TrayNotifyCDS_Dummy
*) alloca(len
);
44 pnotify_data
->cookie
= 1;
45 pnotify_data
->notify_code
= dwMessage
;
46 memcpy(&pnotify_data
->nicon_data
, pnid
, nid_size
);
50 data
.lpData
= pnotify_data
;
52 for(hwnd
= 0; (hwnd
= FindWindowExW(0, hwnd
, L
"Shell_TrayWnd", NULL
)); )
53 if ((unicode
? SendMessageW
: SendMessageA
)(hwnd
, WM_COPYDATA
, (WPARAM
)nid_hwnd
, (LPARAM
)&data
))
60 /*************************************************************************
61 * Shell_NotifyIcon [SHELL32.296]
62 * Shell_NotifyIconA [SHELL32.297]
64 BOOL WINAPI
Shell_NotifyIconA(DWORD dwMessage
, PNOTIFYICONDATAA pnid
)
68 /* Validate the cbSize as Windows XP does */
69 if (pnid
->cbSize
!= NOTIFYICONDATAA_V1_SIZE
&&
70 pnid
->cbSize
!= NOTIFYICONDATAA_V2_SIZE
&&
71 pnid
->cbSize
!= sizeof(NOTIFYICONDATAA
))
73 WARN("Invalid cbSize (%d) - using only Win95 fields (size=%d)\n",
74 pnid
->cbSize
, NOTIFYICONDATAA_V1_SIZE
);
75 cbSize
= NOTIFYICONDATAA_V1_SIZE
;
78 cbSize
= pnid
->cbSize
;
80 return SHELL_NotifyIcon(dwMessage
, pnid
, pnid
->hWnd
, cbSize
, FALSE
);
83 /*************************************************************************
84 * Shell_NotifyIconW [SHELL32.298]
86 BOOL WINAPI
Shell_NotifyIconW(DWORD dwMessage
, PNOTIFYICONDATAW pnid
)
90 /* Validate the cbSize so that WM_COPYDATA doesn't crash the application */
91 if (pnid
->cbSize
!= NOTIFYICONDATAW_V1_SIZE
&&
92 pnid
->cbSize
!= NOTIFYICONDATAW_V2_SIZE
&&
93 pnid
->cbSize
!= sizeof(NOTIFYICONDATAW
))
95 WARN("Invalid cbSize (%d) - using only Win95 fields (size=%d)\n",
96 pnid
->cbSize
, NOTIFYICONDATAW_V1_SIZE
);
97 cbSize
= NOTIFYICONDATAA_V1_SIZE
;
100 cbSize
= pnid
->cbSize
;
102 return SHELL_NotifyIcon(dwMessage
, pnid
, pnid
->hWnd
, cbSize
, TRUE
);