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)
49 ZeroMemory(&nidW, sizeof(nidW));
50 nidW.cbSize = sizeof(nidW);
51 nidW.hWnd = pnid->hWnd;
53 nidW.uFlags = pnid->uFlags;
54 nidW.uCallbackMessage = pnid->uCallbackMessage;
55 nidW.hIcon = pnid->hIcon;
58 if (pnid->uFlags & NIF_TIP)
59 MultiByteToWideChar(CP_ACP, 0, pnid->szTip, -1, nidW.szTip, sizeof(nidW.szTip)/sizeof(WCHAR));
61 if (pnid->cbSize >= NOTIFYICONDATAA_V2_SIZE)
63 nidW.dwState = pnid->dwState;
64 nidW.dwStateMask = pnid->dwStateMask;
66 /* szInfo, szInfoTitle */
67 if (pnid->uFlags & NIF_INFO)
69 MultiByteToWideChar(CP_ACP, 0, pnid->szInfo, -1, nidW.szInfo, sizeof(nidW.szInfo)/sizeof(WCHAR));
70 MultiByteToWideChar(CP_ACP, 0, pnid->szInfoTitle, -1, nidW.szInfoTitle, sizeof(nidW.szInfoTitle)/sizeof(WCHAR));
73 nidW.u.uTimeout = pnid->u.uTimeout;
74 nidW.dwInfoFlags = pnid->dwInfoFlags;
77 if (pnid->cbSize >= NOTIFYICONDATAA_V3_SIZE)
78 nidW.guidItem = pnid->guidItem;
80 if (pnid->cbSize >= sizeof(NOTIFYICONDATAA))
81 nidW.hBalloonIcon = pnid->hBalloonIcon;
82 return Shell_NotifyIconW(dwMessage, &nidW);
85 /*************************************************************************
86 * Shell_NotifyIconW [SHELL32.298]
88 BOOL WINAPI Shell_NotifyIconW(DWORD dwMessage, PNOTIFYICONDATAW nid)
94 TRACE("dwMessage = %d, nid->cbSize=%d\n", dwMessage, nid->cbSize);
96 tray = FindWindowExW(0, NULL, classname, NULL);
97 if (!tray) return FALSE;
99 cds.dwData = dwMessage;
101 /* FIXME: if statement only needed because we don't support interprocess
103 if (nid->uFlags & NIF_ICON)
111 if (!GetIconInfo(nid->hIcon, &iconinfo))
114 if (!GetObjectW(iconinfo.hbmMask, sizeof(bmMask), &bmMask) ||
115 !GetObjectW(iconinfo.hbmColor, sizeof(bmColour), &bmColour))
117 DeleteObject(iconinfo.hbmMask);
118 DeleteObject(iconinfo.hbmColor);
122 cbMaskBits = (bmMask.bmPlanes * bmMask.bmWidth * bmMask.bmHeight * bmMask.bmBitsPixel) / 8;
123 cbColourBits = (bmColour.bmPlanes * bmColour.bmWidth * bmColour.bmHeight * bmColour.bmBitsPixel) / 8;
124 cds.cbData = nid->cbSize + 2*sizeof(BITMAP) + cbMaskBits + cbColourBits;
125 buffer = HeapAlloc(GetProcessHeap(), 0, cds.cbData);
128 DeleteObject(iconinfo.hbmMask);
129 DeleteObject(iconinfo.hbmColor);
134 memcpy(buffer, nid, sizeof(*nid));
135 buffer += nid->cbSize;
136 memcpy(buffer, &bmMask, sizeof(bmMask));
137 buffer += sizeof(bmMask);
138 memcpy(buffer, &bmColour, sizeof(bmColour));
139 buffer += sizeof(bmColour);
140 GetBitmapBits(iconinfo.hbmMask, cbMaskBits, buffer);
141 buffer += cbMaskBits;
142 GetBitmapBits(iconinfo.hbmColor, cbColourBits, buffer);
143 buffer += cbColourBits;
145 DeleteObject(iconinfo.hbmMask);
146 DeleteObject(iconinfo.hbmColor);
151 cds.cbData = nid->cbSize;
155 SendMessageW(tray, WM_COPYDATA, (WPARAM)nid->hWnd, (LPARAM)&cds);
157 /* FIXME: if statement only needed because we don't support interprocess
159 HeapFree(GetProcessHeap(), 0, buffer);