ntdll: Print process id in the relay log if requested.
[wine.git] / programs / explorer / systray.c
blobbeb0a88b49fd8e2b93418f38c1e72e9f3304cf75
1 /*
2 * Copyright (C) 2004 Mike Hearn, for CodeWeavers
3 * Copyright (C) 2005 Robert Shearman
4 * Copyright (C) 2008 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <assert.h>
23 #define NONAMELESSUNION
24 #define _WIN32_IE 0x500
25 #include <windows.h>
26 #include <commctrl.h>
27 #include <shellapi.h>
29 #include <wine/debug.h>
30 #include <wine/list.h>
32 #include "explorer_private.h"
33 #include "resource.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(systray);
37 struct notify_data /* platform-independent format for NOTIFYICONDATA */
39 LONG hWnd;
40 UINT uID;
41 UINT uFlags;
42 UINT uCallbackMessage;
43 WCHAR szTip[128];
44 DWORD dwState;
45 DWORD dwStateMask;
46 WCHAR szInfo[256];
47 union {
48 UINT uTimeout;
49 UINT uVersion;
50 } u;
51 WCHAR szInfoTitle[64];
52 DWORD dwInfoFlags;
53 GUID guidItem;
54 /* data for the icon bitmap */
55 UINT width;
56 UINT height;
57 UINT planes;
58 UINT bpp;
61 static int (CDECL *wine_notify_icon)(DWORD,NOTIFYICONDATAW *);
63 /* an individual systray icon, unpacked from the NOTIFYICONDATA and always in unicode */
64 struct icon
66 struct list entry;
67 HICON image; /* the image to render */
68 HWND owner; /* the HWND passed in to the Shell_NotifyIcon call */
69 HWND tooltip; /* Icon tooltip */
70 UINT state; /* state flags */
71 UINT id; /* the unique id given by the app */
72 UINT callback_message;
73 int display; /* index in display list, or -1 if hidden */
74 WCHAR tiptext[128]; /* Tooltip text. If empty => tooltip disabled */
75 WCHAR info_text[256]; /* info balloon text */
76 WCHAR info_title[64]; /* info balloon title */
77 UINT info_flags; /* flags for info balloon */
78 UINT info_timeout; /* timeout for info balloon */
79 HICON info_icon; /* info balloon icon */
82 static struct list icon_list = LIST_INIT( icon_list );
83 static HWND tray_window;
85 static unsigned int alloc_displayed;
86 static unsigned int nb_displayed;
87 static struct icon **displayed; /* array of currently displayed icons */
89 static BOOL hide_systray, enable_shell;
90 static int icon_cx, icon_cy, tray_width;
92 static struct icon *balloon_icon;
93 static HWND balloon_window;
95 static HWND start_button;
97 #define MIN_DISPLAYED 8
98 #define ICON_BORDER 2
100 #define BALLOON_CREATE_TIMER 1
101 #define BALLOON_SHOW_TIMER 2
103 #define BALLOON_CREATE_TIMEOUT 2000
104 #define BALLOON_SHOW_MIN_TIMEOUT 10000
105 #define BALLOON_SHOW_MAX_TIMEOUT 30000
107 /* Retrieves icon record by owner window and ID */
108 static struct icon *get_icon(HWND owner, UINT id)
110 struct icon *this;
112 /* search for the icon */
113 LIST_FOR_EACH_ENTRY( this, &icon_list, struct icon, entry )
114 if ((this->id == id) && (this->owner == owner)) return this;
116 return NULL;
119 static RECT get_icon_rect( struct icon *icon )
121 RECT rect;
123 rect.right = tray_width - icon_cx * icon->display;
124 rect.left = rect.right - icon_cx;
125 rect.top = 0;
126 rect.bottom = icon_cy;
127 return rect;
130 static void init_common_controls(void)
132 static BOOL initialized = FALSE;
134 if (!initialized)
136 INITCOMMONCONTROLSEX init_tooltip;
138 init_tooltip.dwSize = sizeof(INITCOMMONCONTROLSEX);
139 init_tooltip.dwICC = ICC_TAB_CLASSES|ICC_STANDARD_CLASSES;
141 InitCommonControlsEx(&init_tooltip);
142 initialized = TRUE;
146 /* Creates tooltip window for icon. */
147 static void create_tooltip(struct icon *icon)
149 TTTOOLINFOW ti;
151 init_common_controls();
152 icon->tooltip = CreateWindowExW(WS_EX_TOPMOST, TOOLTIPS_CLASSW, NULL,
153 WS_POPUP | TTS_ALWAYSTIP,
154 CW_USEDEFAULT, CW_USEDEFAULT,
155 CW_USEDEFAULT, CW_USEDEFAULT,
156 tray_window, NULL, NULL, NULL);
158 ZeroMemory(&ti, sizeof(ti));
159 ti.cbSize = sizeof(TTTOOLINFOW);
160 ti.hwnd = tray_window;
161 ti.lpszText = icon->tiptext;
162 if (icon->display != -1) ti.rect = get_icon_rect( icon );
163 SendMessageW(icon->tooltip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
166 static void set_balloon_position( struct icon *icon )
168 RECT rect = get_icon_rect( icon );
169 POINT pos;
171 MapWindowPoints( tray_window, 0, (POINT *)&rect, 2 );
172 pos.x = (rect.left + rect.right) / 2;
173 pos.y = (rect.top + rect.bottom) / 2;
174 SendMessageW( balloon_window, TTM_TRACKPOSITION, 0, MAKELONG( pos.x, pos.y ));
177 static void balloon_create_timer(void)
179 TTTOOLINFOW ti;
181 init_common_controls();
182 balloon_window = CreateWindowExW( WS_EX_TOPMOST, TOOLTIPS_CLASSW, NULL,
183 WS_POPUP | TTS_ALWAYSTIP | TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE,
184 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
185 tray_window, NULL, NULL, NULL);
187 memset( &ti, 0, sizeof(ti) );
188 ti.cbSize = sizeof(TTTOOLINFOW);
189 ti.hwnd = tray_window;
190 ti.uFlags = TTF_TRACK;
191 ti.lpszText = balloon_icon->info_text;
192 SendMessageW( balloon_window, TTM_ADDTOOLW, 0, (LPARAM)&ti );
193 if ((balloon_icon->info_flags & NIIF_ICONMASK) == NIIF_USER)
194 SendMessageW( balloon_window, TTM_SETTITLEW, (WPARAM)balloon_icon->info_icon,
195 (LPARAM)balloon_icon->info_title );
196 else
197 SendMessageW( balloon_window, TTM_SETTITLEW, balloon_icon->info_flags,
198 (LPARAM)balloon_icon->info_title );
199 set_balloon_position( balloon_icon );
200 SendMessageW( balloon_window, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti );
201 KillTimer( tray_window, BALLOON_CREATE_TIMER );
202 SetTimer( tray_window, BALLOON_SHOW_TIMER, balloon_icon->info_timeout, NULL );
205 static BOOL show_balloon( struct icon *icon )
207 if (icon->display == -1) return FALSE; /* not displayed */
208 if (!icon->info_text[0]) return FALSE; /* no balloon */
209 balloon_icon = icon;
210 SetTimer( tray_window, BALLOON_CREATE_TIMER, BALLOON_CREATE_TIMEOUT, NULL );
211 return TRUE;
214 static void hide_balloon(void)
216 if (!balloon_icon) return;
217 if (balloon_window)
219 KillTimer( tray_window, BALLOON_SHOW_TIMER );
220 DestroyWindow( balloon_window );
221 balloon_window = 0;
223 else KillTimer( tray_window, BALLOON_CREATE_TIMER );
224 balloon_icon = NULL;
227 static void show_next_balloon(void)
229 struct icon *icon;
231 LIST_FOR_EACH_ENTRY( icon, &icon_list, struct icon, entry )
232 if (show_balloon( icon )) break;
235 static void update_balloon( struct icon *icon )
237 if (balloon_icon == icon)
239 hide_balloon();
240 show_balloon( icon );
242 else if (!balloon_icon)
244 if (!show_balloon( icon )) return;
246 if (!balloon_icon) show_next_balloon();
249 static void balloon_timer(void)
251 if (balloon_icon) balloon_icon->info_text[0] = 0; /* clear text now that balloon has been shown */
252 hide_balloon();
253 show_next_balloon();
256 /* Synchronize tooltip text with tooltip window */
257 static void update_tooltip_text(struct icon *icon)
259 TTTOOLINFOW ti;
261 ZeroMemory(&ti, sizeof(ti));
262 ti.cbSize = sizeof(TTTOOLINFOW);
263 ti.hwnd = tray_window;
264 ti.lpszText = icon->tiptext;
266 SendMessageW(icon->tooltip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
269 /* synchronize tooltip position with tooltip window */
270 static void update_tooltip_position( struct icon *icon )
272 TTTOOLINFOW ti;
274 ZeroMemory(&ti, sizeof(ti));
275 ti.cbSize = sizeof(TTTOOLINFOW);
276 ti.hwnd = tray_window;
277 if (icon->display != -1) ti.rect = get_icon_rect( icon );
278 SendMessageW( icon->tooltip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti );
279 if (balloon_icon == icon) set_balloon_position( icon );
282 /* find the icon located at a certain point in the tray window */
283 static struct icon *icon_from_point( int x, int y )
285 if (y < 0 || y >= icon_cy) return NULL;
286 x = tray_width - x;
287 if (x < 0 || x >= icon_cx * nb_displayed) return NULL;
288 return displayed[x / icon_cx];
291 /* invalidate the portion of the tray window that contains the specified icons */
292 static void invalidate_icons( unsigned int start, unsigned int end )
294 RECT rect;
296 rect.left = tray_width - (end + 1) * icon_cx;
297 rect.top = 0;
298 rect.right = tray_width - start * icon_cx;
299 rect.bottom = icon_cy;
300 InvalidateRect( tray_window, &rect, TRUE );
303 /* make an icon visible */
304 static BOOL show_icon(struct icon *icon)
306 WINE_TRACE("id=0x%x, hwnd=%p\n", icon->id, icon->owner);
308 if (icon->display != -1) return TRUE; /* already displayed */
310 if (nb_displayed >= alloc_displayed)
312 unsigned int new_count = max( alloc_displayed * 2, 32 );
313 struct icon **ptr;
314 if (displayed) ptr = HeapReAlloc( GetProcessHeap(), 0, displayed, new_count * sizeof(*ptr) );
315 else ptr = HeapAlloc( GetProcessHeap(), 0, new_count * sizeof(*ptr) );
316 if (!ptr) return FALSE;
317 displayed = ptr;
318 alloc_displayed = new_count;
321 icon->display = nb_displayed;
322 displayed[nb_displayed++] = icon;
323 update_tooltip_position( icon );
324 invalidate_icons( nb_displayed-1, nb_displayed-1 );
326 if (nb_displayed == 1 && !hide_systray) ShowWindow( tray_window, SW_SHOWNA );
328 create_tooltip(icon);
329 update_balloon( icon );
330 return TRUE;
333 /* make an icon invisible */
334 static BOOL hide_icon(struct icon *icon)
336 unsigned int i;
338 WINE_TRACE("id=0x%x, hwnd=%p\n", icon->id, icon->owner);
340 if (icon->display == -1) return TRUE; /* already hidden */
342 assert( nb_displayed );
343 for (i = icon->display; i < nb_displayed - 1; i++)
345 displayed[i] = displayed[i + 1];
346 displayed[i]->display = i;
347 update_tooltip_position( displayed[i] );
349 nb_displayed--;
350 invalidate_icons( icon->display, nb_displayed );
351 icon->display = -1;
353 if (!nb_displayed && !enable_shell) ShowWindow( tray_window, SW_HIDE );
355 update_balloon( icon );
356 update_tooltip_position( icon );
357 return TRUE;
360 /* Modifies an existing icon record */
361 static BOOL modify_icon( struct icon *icon, NOTIFYICONDATAW *nid )
363 WINE_TRACE("id=0x%x, hwnd=%p\n", nid->uID, nid->hWnd);
365 /* demarshal the request from the NID */
366 if (!icon)
368 WINE_WARN("Invalid icon ID (0x%x) for HWND %p\n", nid->uID, nid->hWnd);
369 return FALSE;
372 if (nid->uFlags & NIF_STATE)
374 icon->state = (icon->state & ~nid->dwStateMask) | (nid->dwState & nid->dwStateMask);
377 if (nid->uFlags & NIF_ICON)
379 if (icon->image) DestroyIcon(icon->image);
380 icon->image = CopyIcon(nid->hIcon);
381 if (icon->display != -1) invalidate_icons( icon->display, icon->display );
384 if (nid->uFlags & NIF_MESSAGE)
386 icon->callback_message = nid->uCallbackMessage;
388 if (nid->uFlags & NIF_TIP)
390 lstrcpynW(icon->tiptext, nid->szTip, sizeof(icon->tiptext)/sizeof(WCHAR));
391 if (icon->display != -1) update_tooltip_text(icon);
393 if (nid->uFlags & NIF_INFO && nid->cbSize >= NOTIFYICONDATAA_V2_SIZE)
395 lstrcpynW( icon->info_text, nid->szInfo, sizeof(icon->info_text)/sizeof(WCHAR) );
396 lstrcpynW( icon->info_title, nid->szInfoTitle, sizeof(icon->info_title)/sizeof(WCHAR) );
397 icon->info_flags = nid->dwInfoFlags;
398 icon->info_timeout = max(min(nid->u.uTimeout, BALLOON_SHOW_MAX_TIMEOUT), BALLOON_SHOW_MIN_TIMEOUT);
399 icon->info_icon = nid->hBalloonIcon;
400 update_balloon( icon );
402 if (icon->state & NIS_HIDDEN) hide_icon( icon );
403 else show_icon( icon );
404 return TRUE;
407 /* Adds a new icon record to the list */
408 static BOOL add_icon(NOTIFYICONDATAW *nid)
410 struct icon *icon;
412 WINE_TRACE("id=0x%x, hwnd=%p\n", nid->uID, nid->hWnd);
414 if ((icon = get_icon(nid->hWnd, nid->uID)))
416 WINE_WARN("duplicate tray icon add, buggy app?\n");
417 return FALSE;
420 if (!(icon = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*icon))))
422 WINE_ERR("out of memory\n");
423 return FALSE;
426 ZeroMemory(icon, sizeof(struct icon));
427 icon->id = nid->uID;
428 icon->owner = nid->hWnd;
429 icon->display = -1;
431 list_add_tail(&icon_list, &icon->entry);
433 return modify_icon( icon, nid );
436 /* Deletes tray icon window and icon record */
437 static BOOL delete_icon(struct icon *icon)
439 hide_icon(icon);
440 list_remove(&icon->entry);
441 DestroyIcon(icon->image);
442 HeapFree(GetProcessHeap(), 0, icon);
443 return TRUE;
446 /* cleanup icons belonging to a window that has been destroyed */
447 void cleanup_systray_window( HWND hwnd )
449 struct icon *icon, *next;
451 LIST_FOR_EACH_ENTRY_SAFE( icon, next, &icon_list, struct icon, entry )
452 if (icon->owner == hwnd) delete_icon( icon );
454 if (wine_notify_icon)
456 NOTIFYICONDATAW nid = { sizeof(nid), hwnd };
457 wine_notify_icon( 0xdead, &nid );
461 static BOOL handle_incoming(HWND hwndSource, COPYDATASTRUCT *cds)
463 struct icon *icon = NULL;
464 const struct notify_data *data;
465 NOTIFYICONDATAW nid;
466 int ret = FALSE;
468 if (cds->cbData < sizeof(*data)) return FALSE;
469 data = cds->lpData;
471 nid.cbSize = sizeof(nid);
472 nid.hWnd = LongToHandle( data->hWnd );
473 nid.uID = data->uID;
474 nid.uFlags = data->uFlags;
475 nid.uCallbackMessage = data->uCallbackMessage;
476 nid.hIcon = 0;
477 nid.dwState = data->dwState;
478 nid.dwStateMask = data->dwStateMask;
479 nid.u.uTimeout = data->u.uTimeout;
480 nid.dwInfoFlags = data->dwInfoFlags;
481 nid.guidItem = data->guidItem;
482 lstrcpyW( nid.szTip, data->szTip );
483 lstrcpyW( nid.szInfo, data->szInfo );
484 lstrcpyW( nid.szInfoTitle, data->szInfoTitle );
485 nid.hBalloonIcon = 0;
487 /* FIXME: if statement only needed because we don't support interprocess
488 * icon handles */
489 if ((nid.uFlags & NIF_ICON) && cds->cbData > sizeof(*data))
491 LONG cbMaskBits;
492 LONG cbColourBits;
493 const char *buffer = (const char *)(data + 1);
495 cbMaskBits = (data->width * data->height + 15) / 16 * 2;
496 cbColourBits = (data->planes * data->width * data->height * data->bpp + 15) / 16 * 2;
498 if (cds->cbData < sizeof(*data) + cbMaskBits + cbColourBits)
500 WINE_ERR("buffer underflow\n");
501 return FALSE;
503 nid.hIcon = CreateIcon(NULL, data->width, data->height, data->planes, data->bpp,
504 buffer, buffer + cbMaskBits);
507 /* try forward to x11drv first */
508 if (cds->dwData == NIM_ADD || !(icon = get_icon( nid.hWnd, nid.uID )))
510 if (wine_notify_icon && ((ret = wine_notify_icon( cds->dwData, &nid )) != -1))
512 if (nid.hIcon) DestroyIcon( nid.hIcon );
513 return ret;
515 ret = FALSE;
518 switch (cds->dwData)
520 case NIM_ADD:
521 ret = add_icon(&nid);
522 break;
523 case NIM_DELETE:
524 if (icon) ret = delete_icon( icon );
525 break;
526 case NIM_MODIFY:
527 if (icon) ret = modify_icon( icon, &nid );
528 break;
529 default:
530 WINE_FIXME("unhandled tray message: %ld\n", cds->dwData);
531 break;
534 if (nid.hIcon) DestroyIcon( nid.hIcon );
535 return ret;
538 static void do_hide_systray(void)
540 SetWindowPos( tray_window, 0,
541 GetSystemMetrics(SM_XVIRTUALSCREEN) + GetSystemMetrics(SM_CXVIRTUALSCREEN),
542 GetSystemMetrics(SM_YVIRTUALSCREEN) + GetSystemMetrics(SM_CYVIRTUALSCREEN),
543 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
546 static LRESULT WINAPI tray_wndproc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
548 switch (msg)
550 case WM_COPYDATA:
551 return handle_incoming((HWND)wparam, (COPYDATASTRUCT *)lparam);
553 case WM_DISPLAYCHANGE:
554 if (hide_systray) do_hide_systray();
555 else
557 tray_width = GetSystemMetrics( SM_CXSCREEN );
558 SetWindowPos( tray_window, 0, 0, GetSystemMetrics( SM_CYSCREEN ) - icon_cy,
559 tray_width, icon_cy, SWP_NOZORDER | SWP_NOACTIVATE );
561 break;
563 case WM_TIMER:
564 switch (wparam)
566 case BALLOON_CREATE_TIMER: balloon_create_timer(); break;
567 case BALLOON_SHOW_TIMER: balloon_timer(); break;
569 break;
571 case WM_PAINT:
573 unsigned int i;
574 PAINTSTRUCT ps;
575 HDC hdc;
577 hdc = BeginPaint( hwnd, &ps );
578 for (i = 0; i < nb_displayed; i++)
580 RECT dummy, rect = get_icon_rect( displayed[i] );
581 if (IntersectRect( &dummy, &rect, &ps.rcPaint ))
582 DrawIconEx( hdc, rect.left + ICON_BORDER, rect.top + ICON_BORDER, displayed[i]->image,
583 icon_cx - 2*ICON_BORDER, icon_cy - 2*ICON_BORDER,
584 0, 0, DI_DEFAULTSIZE|DI_NORMAL);
586 EndPaint( hwnd, &ps );
587 break;
590 case WM_MOUSEMOVE:
591 case WM_LBUTTONDOWN:
592 case WM_LBUTTONUP:
593 case WM_RBUTTONDOWN:
594 case WM_RBUTTONUP:
595 case WM_MBUTTONDOWN:
596 case WM_MBUTTONUP:
597 case WM_LBUTTONDBLCLK:
598 case WM_RBUTTONDBLCLK:
599 case WM_MBUTTONDBLCLK:
601 MSG message;
602 struct icon *icon = icon_from_point( (short)LOWORD(lparam), (short)HIWORD(lparam) );
603 if (!icon) break;
605 /* notify the owner hwnd of the message */
606 WINE_TRACE("relaying 0x%x\n", msg);
608 message.hwnd = hwnd;
609 message.message = msg;
610 message.wParam = wparam;
611 message.lParam = lparam;
612 SendMessageW( icon->tooltip, TTM_RELAYEVENT, 0, (LPARAM)&message );
614 if (!PostMessageW( icon->owner, icon->callback_message, (WPARAM) icon->id, (LPARAM) msg ) &&
615 GetLastError() == ERROR_INVALID_WINDOW_HANDLE)
617 WINE_WARN("application window was destroyed without removing "
618 "notification icon, removing automatically\n");
619 delete_icon( icon );
621 break;
624 case WM_CLOSE:
625 /* don't destroy the tray window, just hide it */
626 ShowWindow( hwnd, SW_HIDE );
627 return 0;
629 case WM_COMMAND:
630 if ((HWND)lparam == start_button && HIWORD(wparam) == BN_CLICKED)
631 do_startmenu(hwnd);
632 break;
634 case WM_INITMENUPOPUP:
635 case WM_MENUCOMMAND:
636 return menu_wndproc(hwnd, msg, wparam, lparam);
638 default:
639 return DefWindowProcW( hwnd, msg, wparam, lparam );
641 return 0;
644 static void get_system_text_size( const WCHAR *text, SIZE *size )
646 /* FIXME: Implement BCM_GETIDEALSIZE and use that instead. */
647 HDC hdc = GetDC( 0 );
649 GetTextExtentPointW(hdc, text, lstrlenW(text), size);
651 ReleaseDC( 0, hdc );
654 /* this function creates the listener window */
655 void initialize_systray( HMODULE graphics_driver, BOOL using_root, BOOL arg_enable_shell )
657 WNDCLASSEXW class;
658 static const WCHAR classname[] = {'S','h','e','l','l','_','T','r','a','y','W','n','d',0};
659 static const WCHAR button_class[] = {'B','u','t','t','o','n',0};
660 WCHAR start_label[50];
661 SIZE start_text_size;
663 wine_notify_icon = (void *)GetProcAddress( graphics_driver, "wine_notify_icon" );
665 icon_cx = GetSystemMetrics( SM_CXSMICON ) + 2*ICON_BORDER;
666 icon_cy = GetSystemMetrics( SM_CYSMICON ) + 2*ICON_BORDER;
667 hide_systray = using_root;
668 enable_shell = arg_enable_shell;
670 /* register the systray listener window class */
671 ZeroMemory(&class, sizeof(class));
672 class.cbSize = sizeof(class);
673 class.style = CS_DBLCLKS | CS_HREDRAW;
674 class.lpfnWndProc = tray_wndproc;
675 class.hInstance = NULL;
676 class.hIcon = LoadIconW(0, (LPCWSTR)IDI_WINLOGO);
677 class.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
678 class.hbrBackground = (HBRUSH) COLOR_WINDOW;
679 class.lpszClassName = classname;
681 if (!RegisterClassExW(&class))
683 WINE_ERR("Could not register SysTray window class\n");
684 return;
687 tray_width = GetSystemMetrics( SM_CXSCREEN );
688 tray_window = CreateWindowExW( WS_EX_NOACTIVATE, classname, NULL, WS_POPUP,
689 0, GetSystemMetrics( SM_CYSCREEN ) - icon_cy,
690 tray_width, icon_cy, 0, 0, 0, 0 );
691 if (!tray_window)
693 WINE_ERR("Could not create tray window\n");
694 return;
697 LoadStringW( NULL, IDS_START_LABEL, start_label, sizeof(start_label)/sizeof(WCHAR) );
699 get_system_text_size( start_label, &start_text_size );
701 start_button = CreateWindowW( button_class, start_label, WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
702 0, 0, start_text_size.cx + 8, icon_cy, tray_window, 0, 0, 0 );
704 if (enable_shell && !hide_systray) ShowWindow( tray_window, SW_SHOWNA );
706 if (hide_systray) do_hide_systray();