4 * Copyright 1999 Kai Morich <kai.morich@bigfoot.de>
5 * Copyright 2004 Mike Hearn, for CodeWeavers
6 * Copyright 2005 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define NONAMELESSUNION
24 #define NONAMELESSSTRUCT
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(systray);
39 static const WCHAR classname[] = /* Shell_TrayWnd */ {'S','h','e','l','l','_','T','r','a','y','W','n','d','\0'};
41 /*************************************************************************
42 * Shell_NotifyIcon [SHELL32.296]
43 * Shell_NotifyIconA [SHELL32.297]
45 BOOL WINAPI Shell_NotifyIconA(DWORD dwMessage, PNOTIFYICONDATAA pnid)
50 /* Validate the cbSize as Windows XP does */
51 if (pnid->cbSize != NOTIFYICONDATAA_V1_SIZE &&
52 pnid->cbSize != NOTIFYICONDATAA_V2_SIZE &&
53 pnid->cbSize != NOTIFYICONDATAA_V3_SIZE &&
54 pnid->cbSize != sizeof(NOTIFYICONDATAA))
56 WARN("Invalid cbSize (%d) - using only Win95 fields (size=%d)\n",
57 pnid->cbSize, NOTIFYICONDATAA_V1_SIZE);
58 cbSize = NOTIFYICONDATAA_V1_SIZE;
61 cbSize = pnid->cbSize;
63 ZeroMemory(&nidW, sizeof(nidW));
64 nidW.cbSize = sizeof(nidW);
65 nidW.hWnd = pnid->hWnd;
67 nidW.uFlags = pnid->uFlags;
68 nidW.uCallbackMessage = pnid->uCallbackMessage;
69 nidW.hIcon = pnid->hIcon;
72 if (pnid->uFlags & NIF_TIP)
73 MultiByteToWideChar(CP_ACP, 0, pnid->szTip, -1, nidW.szTip, sizeof(nidW.szTip)/sizeof(WCHAR));
75 if (cbSize >= NOTIFYICONDATAA_V2_SIZE)
77 nidW.dwState = pnid->dwState;
78 nidW.dwStateMask = pnid->dwStateMask;
80 /* szInfo, szInfoTitle */
81 if (pnid->uFlags & NIF_INFO)
83 MultiByteToWideChar(CP_ACP, 0, pnid->szInfo, -1, nidW.szInfo, sizeof(nidW.szInfo)/sizeof(WCHAR));
84 MultiByteToWideChar(CP_ACP, 0, pnid->szInfoTitle, -1, nidW.szInfoTitle, sizeof(nidW.szInfoTitle)/sizeof(WCHAR));
87 nidW.u.uTimeout = pnid->u.uTimeout;
88 nidW.dwInfoFlags = pnid->dwInfoFlags;
91 if (cbSize >= NOTIFYICONDATAA_V3_SIZE)
92 nidW.guidItem = pnid->guidItem;
94 if (cbSize >= sizeof(NOTIFYICONDATAA))
95 nidW.hBalloonIcon = pnid->hBalloonIcon;
96 return Shell_NotifyIconW(dwMessage, &nidW);
99 /*************************************************************************
100 * Shell_NotifyIconW [SHELL32.298]
102 BOOL WINAPI Shell_NotifyIconW(DWORD dwMessage, PNOTIFYICONDATAW nid)
109 TRACE("dwMessage = %d, nid->cbSize=%d\n", dwMessage, nid->cbSize);
111 /* Validate the cbSize so that WM_COPYDATA doesn't crash the application */
112 if (nid->cbSize != NOTIFYICONDATAW_V1_SIZE &&
113 nid->cbSize != NOTIFYICONDATAW_V2_SIZE &&
114 nid->cbSize != NOTIFYICONDATAW_V3_SIZE &&
115 nid->cbSize != sizeof(NOTIFYICONDATAW))
117 NOTIFYICONDATAW newNid;
119 WARN("Invalid cbSize (%d) - using only Win95 fields (size=%d)\n",
120 nid->cbSize, NOTIFYICONDATAW_V1_SIZE);
121 CopyMemory(&newNid, nid, NOTIFYICONDATAW_V1_SIZE);
122 newNid.cbSize = NOTIFYICONDATAW_V1_SIZE;
123 return Shell_NotifyIconW(dwMessage, &newNid);
126 tray = FindWindowExW(0, NULL, classname, NULL);
127 if (!tray) return FALSE;
129 cds.dwData = dwMessage;
131 /* FIXME: if statement only needed because we don't support interprocess
133 if (nid->uFlags & NIF_ICON)
141 if (!GetIconInfo(nid->hIcon, &iconinfo))
144 if (!GetObjectW(iconinfo.hbmMask, sizeof(bmMask), &bmMask) ||
145 !GetObjectW(iconinfo.hbmColor, sizeof(bmColour), &bmColour))
147 DeleteObject(iconinfo.hbmMask);
148 DeleteObject(iconinfo.hbmColor);
152 cbMaskBits = (bmMask.bmPlanes * bmMask.bmWidth * bmMask.bmHeight * bmMask.bmBitsPixel) / 8;
153 cbColourBits = (bmColour.bmPlanes * bmColour.bmWidth * bmColour.bmHeight * bmColour.bmBitsPixel) / 8;
154 cds.cbData = nid->cbSize + 2*sizeof(BITMAP) + cbMaskBits + cbColourBits;
155 buffer = HeapAlloc(GetProcessHeap(), 0, cds.cbData);
158 DeleteObject(iconinfo.hbmMask);
159 DeleteObject(iconinfo.hbmColor);
164 memcpy(buffer, nid, nid->cbSize);
165 buffer += nid->cbSize;
166 memcpy(buffer, &bmMask, sizeof(bmMask));
167 buffer += sizeof(bmMask);
168 memcpy(buffer, &bmColour, sizeof(bmColour));
169 buffer += sizeof(bmColour);
170 GetBitmapBits(iconinfo.hbmMask, cbMaskBits, buffer);
171 buffer += cbMaskBits;
172 GetBitmapBits(iconinfo.hbmColor, cbColourBits, buffer);
174 /* Reset pointer to allocated block so it can be freed later.
175 * Note that cds.lpData cannot be passed to HeapFree since it
176 * points to nid when no icon info is found. */
179 DeleteObject(iconinfo.hbmMask);
180 DeleteObject(iconinfo.hbmColor);
185 cds.cbData = nid->cbSize;
189 ret = SendMessageW(tray, WM_COPYDATA, (WPARAM)nid->hWnd, (LPARAM)&cds);
191 /* FIXME: if statement only needed because we don't support interprocess
193 HeapFree(GetProcessHeap(), 0, buffer);