2 * Explorer desktop support
4 * Copyright 2006 Alexandre Julliard
5 * Copyright 2013 Hans Leidekker for CodeWeavers
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 St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
33 #include "wine/gdi_driver.h"
34 #include "wine/unicode.h"
35 #include "wine/debug.h"
36 #include "explorer_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(explorer
);
40 #define DESKTOP_CLASS_ATOM ((LPCWSTR)MAKEINTATOM(32769))
41 #define DESKTOP_ALL_ACCESS 0x01ff
43 static HMODULE graphics_driver
;
44 static BOOL using_root
;
53 static WCHAR
*desktop_folder
;
54 static WCHAR
*desktop_folder_public
;
56 static int icon_cx
, icon_cy
, icon_offset_cx
, icon_offset_cy
;
57 static int title_cx
, title_cy
, title_offset_cx
, title_offset_cy
;
58 static int desktop_width
, launcher_size
, launchers_per_row
;
60 static struct launcher
**launchers
;
61 static unsigned int nb_launchers
, nb_allocated
;
63 static RECT
get_icon_rect( unsigned int index
)
66 unsigned int row
= index
/ launchers_per_row
;
67 unsigned int col
= index
% launchers_per_row
;
69 rect
.left
= col
* launcher_size
+ icon_offset_cx
;
70 rect
.right
= rect
.left
+ icon_cx
;
71 rect
.top
= row
* launcher_size
+ icon_offset_cy
;
72 rect
.bottom
= rect
.top
+ icon_cy
;
76 static RECT
get_title_rect( unsigned int index
)
79 unsigned int row
= index
/ launchers_per_row
;
80 unsigned int col
= index
% launchers_per_row
;
82 rect
.left
= col
* launcher_size
+ title_offset_cx
;
83 rect
.right
= rect
.left
+ title_cx
;
84 rect
.top
= row
* launcher_size
+ title_offset_cy
;
85 rect
.bottom
= rect
.top
+ title_cy
;
89 static const struct launcher
*launcher_from_point( int x
, int y
)
92 unsigned int index
= x
/ launcher_size
+ (y
/ launcher_size
) * launchers_per_row
;
94 if (index
>= nb_launchers
) return NULL
;
96 icon
= get_icon_rect( index
);
97 title
= get_title_rect( index
);
98 if ((x
< icon
.left
|| x
> icon
.right
|| y
< icon
.top
|| y
> icon
.bottom
) &&
99 (x
< title
.left
|| x
> title
.right
|| y
< title
.top
|| y
> title
.bottom
)) return NULL
;
100 return launchers
[index
];
103 static void draw_launchers( HDC hdc
, RECT update_rect
)
105 COLORREF color
= SetTextColor( hdc
, RGB(255,255,255) ); /* FIXME: depends on background color */
106 int mode
= SetBkMode( hdc
, TRANSPARENT
);
111 SystemParametersInfoW( SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0 );
112 font
= SelectObject( hdc
, CreateFontIndirectW( &lf
) );
114 for (i
= 0; i
< nb_launchers
; i
++)
116 RECT dummy
, icon
= get_icon_rect( i
), title
= get_title_rect( i
);
118 if (IntersectRect( &dummy
, &icon
, &update_rect
))
119 DrawIconEx( hdc
, icon
.left
, icon
.top
, launchers
[i
]->icon
, icon_cx
, icon_cy
,
120 0, 0, DI_DEFAULTSIZE
|DI_NORMAL
);
122 if (IntersectRect( &dummy
, &title
, &update_rect
))
123 DrawTextW( hdc
, launchers
[i
]->title
, -1, &title
,
124 DT_CENTER
|DT_WORDBREAK
|DT_EDITCONTROL
|DT_END_ELLIPSIS
);
127 SelectObject( hdc
, font
);
128 SetTextColor( hdc
, color
);
129 SetBkMode( hdc
, mode
);
132 static void do_launch( const struct launcher
*launcher
)
134 static const WCHAR openW
[] = {'o','p','e','n',0};
135 ShellExecuteW( NULL
, openW
, launcher
->path
, NULL
, NULL
, 0 );
138 static WCHAR
*append_path( const WCHAR
*path
, const WCHAR
*filename
, int len_filename
)
140 int len_path
= strlenW( path
);
143 if (len_filename
== -1) len_filename
= strlenW( filename
);
144 if (!(ret
= HeapAlloc( GetProcessHeap(), 0, (len_path
+ len_filename
+ 2) * sizeof(WCHAR
) )))
146 memcpy( ret
, path
, len_path
* sizeof(WCHAR
) );
147 ret
[len_path
] = '\\';
148 memcpy( ret
+ len_path
+ 1, filename
, len_filename
* sizeof(WCHAR
) );
149 ret
[len_path
+ 1 + len_filename
] = 0;
153 static IShellLinkW
*load_shelllink( const WCHAR
*path
)
159 hr
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IShellLinkW
,
161 if (FAILED( hr
)) return NULL
;
163 hr
= IShellLinkW_QueryInterface( link
, &IID_IPersistFile
, (void **)&file
);
166 IShellLinkW_Release( link
);
169 hr
= IPersistFile_Load( file
, path
, 0 );
170 IPersistFile_Release( file
);
173 IShellLinkW_Release( link
);
179 static HICON
extract_icon( IShellLinkW
*link
)
181 WCHAR tmp_path
[MAX_PATH
], icon_path
[MAX_PATH
], target_path
[MAX_PATH
];
186 IShellLinkW_GetIconLocation( link
, tmp_path
, MAX_PATH
, &index
);
187 ExpandEnvironmentStringsW( tmp_path
, icon_path
, MAX_PATH
);
189 if (icon_path
[0]) ExtractIconExW( icon_path
, index
, &icon
, NULL
, 1 );
193 IShellLinkW_GetPath( link
, tmp_path
, MAX_PATH
, NULL
, SLGP_RAWPATH
);
194 ExpandEnvironmentStringsW( tmp_path
, target_path
, MAX_PATH
);
195 ExtractIconExW( target_path
, index
, &icon
, NULL
, 1 );
200 static WCHAR
*build_title( const WCHAR
*filename
, int len
)
205 if (len
== -1) len
= strlenW( filename
);
206 for (p
= filename
+ len
- 1; p
>= filename
; p
--)
214 if (!(ret
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) ))) return NULL
;
215 memcpy( ret
, filename
, len
* sizeof(WCHAR
) );
220 static BOOL
add_launcher( const WCHAR
*folder
, const WCHAR
*filename
, int len_filename
)
222 struct launcher
*launcher
;
225 if (nb_launchers
== nb_allocated
)
227 unsigned int count
= nb_allocated
* 2;
228 struct launcher
**tmp
= HeapReAlloc( GetProcessHeap(), 0, launchers
, count
* sizeof(*tmp
) );
229 if (!tmp
) return FALSE
;
231 nb_allocated
= count
;
234 if (!(launcher
= HeapAlloc( GetProcessHeap(), 0, sizeof(*launcher
) ))) return FALSE
;
235 if (!(launcher
->path
= append_path( folder
, filename
, len_filename
))) goto error
;
236 if (!(link
= load_shelllink( launcher
->path
))) goto error
;
238 launcher
->icon
= extract_icon( link
);
239 launcher
->title
= build_title( filename
, len_filename
);
240 IShellLinkW_Release( link
);
241 if (launcher
->icon
&& launcher
->title
)
243 launchers
[nb_launchers
++] = launcher
;
246 HeapFree( GetProcessHeap(), 0, launcher
->title
);
247 DestroyIcon( launcher
->icon
);
250 HeapFree( GetProcessHeap(), 0, launcher
->path
);
251 HeapFree( GetProcessHeap(), 0, launcher
);
255 static void free_launcher( struct launcher
*launcher
)
257 DestroyIcon( launcher
->icon
);
258 HeapFree( GetProcessHeap(), 0, launcher
->path
);
259 HeapFree( GetProcessHeap(), 0, launcher
->title
);
260 HeapFree( GetProcessHeap(), 0, launcher
);
263 static BOOL
remove_launcher( const WCHAR
*folder
, const WCHAR
*filename
, int len_filename
)
269 if (!(path
= append_path( folder
, filename
, len_filename
))) return FALSE
;
270 for (i
= 0; i
< nb_launchers
; i
++)
272 if (!strcmpiW( launchers
[i
]->path
, path
))
274 free_launcher( launchers
[i
] );
276 memmove( &launchers
[i
], &launchers
[i
+ 1], sizeof(launchers
[i
]) * (nb_launchers
- i
) );
281 HeapFree( GetProcessHeap(), 0, path
);
285 static BOOL
get_icon_text_metrics( HWND hwnd
, TEXTMETRICW
*tm
)
293 SystemParametersInfoW( SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0 );
294 hfont
= SelectObject( hdc
, CreateFontIndirectW( &lf
) );
295 ret
= GetTextMetricsW( hdc
, tm
);
296 SelectObject( hdc
, hfont
);
297 ReleaseDC( hwnd
, hdc
);
301 static BOOL
process_changes( const WCHAR
*folder
, char *buf
)
303 FILE_NOTIFY_INFORMATION
*info
= (FILE_NOTIFY_INFORMATION
*)buf
;
308 switch (info
->Action
)
310 case FILE_ACTION_ADDED
:
311 case FILE_ACTION_RENAMED_NEW_NAME
:
312 if (add_launcher( folder
, info
->FileName
, info
->FileNameLength
/ sizeof(WCHAR
) ))
316 case FILE_ACTION_REMOVED
:
317 case FILE_ACTION_RENAMED_OLD_NAME
:
318 if (remove_launcher( folder
, info
->FileName
, info
->FileNameLength
/ sizeof(WCHAR
) ))
323 WARN( "unexpected action %u\n", info
->Action
);
326 if (!info
->NextEntryOffset
) break;
327 info
= (FILE_NOTIFY_INFORMATION
*)((char *)info
+ info
->NextEntryOffset
);
332 static DWORD CALLBACK
watch_desktop_folders( LPVOID param
)
335 HRESULT init
= CoInitialize( NULL
);
336 HANDLE dir0
, dir1
, events
[2];
337 OVERLAPPED ovl0
, ovl1
;
338 char *buf0
= NULL
, *buf1
= NULL
;
339 DWORD count
, size
= 4096, error
= ERROR_OUTOFMEMORY
;
342 dir0
= CreateFileW( desktop_folder
, FILE_LIST_DIRECTORY
|SYNCHRONIZE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
343 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
|FILE_FLAG_OVERLAPPED
, NULL
);
344 if (dir0
== INVALID_HANDLE_VALUE
) return GetLastError();
345 dir1
= CreateFileW( desktop_folder_public
, FILE_LIST_DIRECTORY
|SYNCHRONIZE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
346 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
|FILE_FLAG_OVERLAPPED
, NULL
);
347 if (dir1
== INVALID_HANDLE_VALUE
)
350 return GetLastError();
352 if (!(ovl0
.hEvent
= events
[0] = CreateEventW( NULL
, FALSE
, FALSE
, NULL
))) goto error
;
353 if (!(ovl1
.hEvent
= events
[1] = CreateEventW( NULL
, FALSE
, FALSE
, NULL
))) goto error
;
354 if (!(buf0
= HeapAlloc( GetProcessHeap(), 0, size
))) goto error
;
355 if (!(buf1
= HeapAlloc( GetProcessHeap(), 0, size
))) goto error
;
359 ret
= ReadDirectoryChangesW( dir0
, buf0
, size
, FALSE
, FILE_NOTIFY_CHANGE_FILE_NAME
, NULL
, &ovl0
, NULL
);
362 error
= GetLastError();
365 ret
= ReadDirectoryChangesW( dir1
, buf1
, size
, FALSE
, FILE_NOTIFY_CHANGE_FILE_NAME
, NULL
, &ovl1
, NULL
);
368 error
= GetLastError();
373 switch ((error
= WaitForMultipleObjects( 2, events
, FALSE
, INFINITE
)))
376 if (!GetOverlappedResult( dir0
, &ovl0
, &count
, FALSE
) || !count
) break;
377 if (process_changes( desktop_folder
, buf0
)) redraw
= TRUE
;
380 case WAIT_OBJECT_0
+ 1:
381 if (!GetOverlappedResult( dir1
, &ovl1
, &count
, FALSE
) || !count
) break;
382 if (process_changes( desktop_folder_public
, buf1
)) redraw
= TRUE
;
388 if (redraw
) InvalidateRect( hwnd
, NULL
, TRUE
);
394 CloseHandle( events
[0] );
395 CloseHandle( events
[1] );
396 HeapFree( GetProcessHeap(), 0, buf0
);
397 HeapFree( GetProcessHeap(), 0, buf1
);
398 if (SUCCEEDED( init
)) CoUninitialize();
402 static void add_folder( const WCHAR
*folder
)
404 static const WCHAR lnkW
[] = {'\\','*','.','l','n','k',0};
405 int len
= strlenW( folder
) + strlenW( lnkW
);
406 WIN32_FIND_DATAW data
;
410 if (!(glob
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) ))) return;
411 strcpyW( glob
, folder
);
412 strcatW( glob
, lnkW
);
414 if ((handle
= FindFirstFileW( glob
, &data
)) != INVALID_HANDLE_VALUE
)
416 do { add_launcher( folder
, data
.cFileName
, -1 ); } while (FindNextFileW( handle
, &data
));
419 HeapFree( GetProcessHeap(), 0, glob
);
422 #define BORDER_SIZE 4
423 #define PADDING_SIZE 4
424 #define TITLE_CHARS 14
426 static void initialize_launchers( HWND hwnd
)
432 if (!(get_icon_text_metrics( hwnd
, &tm
))) return;
434 icon_cx
= GetSystemMetrics( SM_CXICON
);
435 icon_cy
= GetSystemMetrics( SM_CYICON
);
436 icon_size
= max( icon_cx
, icon_cy
);
437 title_cy
= tm
.tmHeight
* 2;
438 title_cx
= max( tm
.tmAveCharWidth
* TITLE_CHARS
, icon_size
+ PADDING_SIZE
+ title_cy
);
439 launcher_size
= BORDER_SIZE
+ title_cx
+ BORDER_SIZE
;
440 icon_offset_cx
= (launcher_size
- icon_cx
) / 2;
441 icon_offset_cy
= BORDER_SIZE
+ (icon_size
- icon_cy
) / 2;
442 title_offset_cx
= BORDER_SIZE
;
443 title_offset_cy
= BORDER_SIZE
+ icon_size
+ PADDING_SIZE
;
444 desktop_width
= GetSystemMetrics( SM_CXSCREEN
);
445 launchers_per_row
= desktop_width
/ launcher_size
;
447 hr
= SHGetKnownFolderPath( &FOLDERID_Desktop
, KF_FLAG_CREATE
, NULL
, &desktop_folder
);
450 WINE_ERR("Could not get user desktop folder\n");
453 hr
= SHGetKnownFolderPath( &FOLDERID_PublicDesktop
, KF_FLAG_CREATE
, NULL
, &desktop_folder_public
);
456 WINE_ERR("Could not get public desktop folder\n");
457 CoTaskMemFree( desktop_folder
);
460 if ((launchers
= HeapAlloc( GetProcessHeap(), 0, 2 * sizeof(launchers
[0]) )))
464 init
= CoInitialize( NULL
);
465 add_folder( desktop_folder
);
466 add_folder( desktop_folder_public
);
467 if (SUCCEEDED( init
)) CoUninitialize();
469 CreateThread( NULL
, 0, watch_desktop_folders
, hwnd
, 0, NULL
);
473 /* screen saver handler */
474 static BOOL
start_screensaver( void )
478 const char *argv
[3] = { "xdg-screensaver", "activate", NULL
};
479 int pid
= _spawnvp( _P_DETACH
, argv
[0], argv
);
482 WINE_TRACE( "started process %d\n", pid
);
489 /* window procedure for the desktop window */
490 static LRESULT WINAPI
desktop_wnd_proc( HWND hwnd
, UINT message
, WPARAM wp
, LPARAM lp
)
492 WINE_TRACE( "got msg %04x wp %lx lp %lx\n", message
, wp
, lp
);
503 return start_screensaver();
512 return (LRESULT
)SetCursor( LoadCursorA( 0, (LPSTR
)IDC_ARROW
) );
518 if (!using_root
) PaintDesktop( (HDC
)wp
);
521 case WM_SETTINGCHANGE
:
522 if (wp
== SPI_SETDESKWALLPAPER
)
523 SystemParametersInfoW( SPI_SETDESKWALLPAPER
, 0, NULL
, FALSE
);
526 case WM_LBUTTONDBLCLK
:
528 const struct launcher
*launcher
= launcher_from_point( (short)LOWORD(lp
), (short)HIWORD(lp
) );
529 if (launcher
) do_launch( launcher
);
536 BeginPaint( hwnd
, &ps
);
539 if (ps
.fErase
) PaintDesktop( ps
.hdc
);
540 draw_launchers( ps
.hdc
, ps
.rcPaint
);
542 EndPaint( hwnd
, &ps
);
547 return DefWindowProcW( hwnd
, message
, wp
, lp
);
551 /* create the desktop and the associated driver window, and make it the current desktop */
552 static BOOL
create_desktop( const WCHAR
*name
, unsigned int width
, unsigned int height
)
554 static const WCHAR rootW
[] = {'r','o','o','t',0};
557 BOOL (CDECL
*create_desktop_func
)(unsigned int, unsigned int);
559 desktop
= CreateDesktopW( name
, NULL
, NULL
, 0, DESKTOP_ALL_ACCESS
, NULL
);
562 WINE_ERR( "failed to create desktop %s error %d\n", wine_dbgstr_w(name
), GetLastError() );
565 /* magic: desktop "root" means use the root window */
566 if (graphics_driver
&& strcmpiW( name
, rootW
))
568 create_desktop_func
= (void *)GetProcAddress( graphics_driver
, "wine_create_desktop" );
569 if (create_desktop_func
) ret
= create_desktop_func( width
, height
);
571 SetThreadDesktop( desktop
);
575 /* parse the desktop size specification */
576 static BOOL
parse_size( const WCHAR
*size
, unsigned int *width
, unsigned int *height
)
580 *width
= strtoulW( size
, &end
, 10 );
581 if (end
== size
) return FALSE
;
582 if (*end
!= 'x') return FALSE
;
584 *height
= strtoulW( size
, &end
, 10 );
588 /* retrieve the desktop name to use if not specified on the command line */
589 static const WCHAR
*get_default_desktop_name(void)
591 static const WCHAR desktopW
[] = {'D','e','s','k','t','o','p',0};
592 static const WCHAR defaultW
[] = {'D','e','f','a','u','l','t',0};
593 static const WCHAR explorer_keyW
[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
594 'E','x','p','l','o','r','e','r',0};
595 static WCHAR buffer
[MAX_PATH
];
596 DWORD size
= sizeof(buffer
);
597 HDESK desk
= GetThreadDesktop( GetCurrentThreadId() );
601 if (desk
&& GetUserObjectInformationW( desk
, UOI_NAME
, buffer
, sizeof(buffer
)/sizeof(WCHAR
), NULL
))
603 if (strcmpiW( buffer
, defaultW
)) return buffer
;
606 /* @@ Wine registry key: HKCU\Software\Wine\Explorer */
607 if (!RegOpenKeyW( HKEY_CURRENT_USER
, explorer_keyW
, &hkey
))
609 if (!RegQueryValueExW( hkey
, desktopW
, 0, NULL
, (LPBYTE
)buffer
, &size
)) ret
= buffer
;
615 /* retrieve the default desktop size from the registry */
616 static BOOL
get_default_desktop_size( const WCHAR
*name
, unsigned int *width
, unsigned int *height
)
618 static const WCHAR desktop_keyW
[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
619 'E','x','p','l','o','r','e','r','\\',
620 'D','e','s','k','t','o','p','s',0};
623 DWORD size
= sizeof(buffer
);
629 /* @@ Wine registry key: HKCU\Software\Wine\Explorer\Desktops */
630 if (!RegOpenKeyW( HKEY_CURRENT_USER
, desktop_keyW
, &hkey
))
632 if (!RegQueryValueExW( hkey
, name
, 0, NULL
, (LPBYTE
)buffer
, &size
))
635 if (!parse_size( buffer
, width
, height
)) *width
= *height
= 0;
642 static void initialize_display_settings( HWND desktop
)
644 static const WCHAR display_device_guid_propW
[] = {
645 '_','_','w','i','n','e','_','d','i','s','p','l','a','y','_',
646 'd','e','v','i','c','e','_','g','u','i','d',0 };
653 UuidToStringA( &guid
, &guid_str
);
654 WINE_TRACE( "display guid %s\n", guid_str
);
656 guid_atom
= GlobalAddAtomA( (LPCSTR
)guid_str
);
657 SetPropW( desktop
, display_device_guid_propW
, ULongToHandle(guid_atom
) );
659 RpcStringFreeA( &guid_str
);
661 /* Store current display mode in the registry */
662 if (EnumDisplaySettingsExW( NULL
, ENUM_CURRENT_SETTINGS
, &dmW
, 0 ))
664 WINE_TRACE( "Current display mode %ux%u %u bpp %u Hz\n", dmW
.dmPelsWidth
,
665 dmW
.dmPelsHeight
, dmW
.dmBitsPerPel
, dmW
.dmDisplayFrequency
);
666 ChangeDisplaySettingsExW( NULL
, &dmW
, 0,
667 CDS_GLOBAL
| CDS_NORESET
| CDS_UPDATEREGISTRY
,
672 static void set_desktop_window_title( HWND hwnd
, const WCHAR
*name
)
674 static const WCHAR desktop_nameW
[] = {'W','i','n','e',' ','d','e','s','k','t','o','p',0};
675 static const WCHAR desktop_name_separatorW
[] = {' ', '-', ' ', 0};
676 WCHAR
*window_titleW
= NULL
;
677 int window_title_len
;
681 SetWindowTextW( hwnd
, desktop_nameW
);
685 window_title_len
= strlenW(name
) * sizeof(WCHAR
)
686 + sizeof(desktop_name_separatorW
)
687 + sizeof(desktop_nameW
);
688 window_titleW
= HeapAlloc( GetProcessHeap(), 0, window_title_len
);
691 SetWindowTextW( hwnd
, desktop_nameW
);
695 strcpyW( window_titleW
, name
);
696 strcatW( window_titleW
, desktop_name_separatorW
);
697 strcatW( window_titleW
, desktop_nameW
);
699 SetWindowTextW( hwnd
, window_titleW
);
700 HeapFree( GetProcessHeap(), 0, window_titleW
);
703 /* main desktop management function */
704 void manage_desktop( WCHAR
*arg
)
706 static const WCHAR displayW
[] = {'D','I','S','P','L','A','Y',0};
707 static const WCHAR messageW
[] = {'M','e','s','s','a','g','e',0};
711 unsigned int width
, height
;
712 WCHAR
*cmdline
= NULL
;
714 const WCHAR
*name
= NULL
;
716 /* get the rest of the command line (if any) */
717 while (*p
&& !isspace(*p
)) p
++;
721 while (*p
&& isspace(*p
)) p
++;
725 /* parse the desktop option */
726 /* the option is of the form /desktop=name[,widthxheight] */
727 if (*arg
== '=' || *arg
== ',')
731 if ((p
= strchrW( arg
, ',' ))) *p
++ = 0;
732 if (!p
|| !parse_size( p
, &width
, &height
))
733 get_default_desktop_size( name
, &width
, &height
);
735 else if ((name
= get_default_desktop_name()))
737 if (!get_default_desktop_size( name
, &width
, &height
)) width
= height
= 0;
740 hdc
= CreateDCW( displayW
, NULL
, NULL
, NULL
);
741 graphics_driver
= __wine_get_driver_module( hdc
);
743 if (name
&& width
&& height
) using_root
= !create_desktop( name
, width
, height
);
745 /* create the desktop window */
746 hwnd
= CreateWindowExW( 0, DESKTOP_CLASS_ATOM
, NULL
,
747 WS_POPUP
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
,
748 GetSystemMetrics(SM_XVIRTUALSCREEN
), GetSystemMetrics(SM_YVIRTUALSCREEN
),
749 GetSystemMetrics(SM_CXVIRTUALSCREEN
), GetSystemMetrics(SM_CYVIRTUALSCREEN
),
752 /* create the HWND_MESSAGE parent */
753 msg_hwnd
= CreateWindowExW( 0, messageW
, NULL
, WS_POPUP
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
,
754 0, 0, 100, 100, 0, 0, 0, NULL
);
758 if (hwnd
== GetDesktopWindow())
761 void (WINAPI
*pShellDDEInit
)( BOOL
);
763 SetWindowLongPtrW( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)desktop_wnd_proc
);
764 SendMessageW( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)LoadIconW( 0, MAKEINTRESOURCEW(OIC_WINLOGO
)));
765 if (name
) set_desktop_window_title( hwnd
, name
);
766 ShowWindow( hwnd
, SW_SHOW
);
767 SystemParametersInfoW( SPI_SETDESKWALLPAPER
, 0, NULL
, FALSE
);
769 initialize_display_settings( hwnd
);
771 initialize_systray( graphics_driver
, using_root
);
772 if (!using_root
) initialize_launchers( hwnd
);
774 if ((shell32
= LoadLibraryA( "shell32.dll" )) &&
775 (pShellDDEInit
= (void *)GetProcAddress( shell32
, (LPCSTR
)188)))
777 pShellDDEInit( TRUE
);
782 DestroyWindow( hwnd
); /* someone beat us to it */
786 if (GetAncestor( msg_hwnd
, GA_PARENT
)) DestroyWindow( msg_hwnd
); /* someone beat us to it */
788 /* if we have a command line, execute it */
792 PROCESS_INFORMATION pi
;
794 memset( &si
, 0, sizeof(si
) );
796 WINE_TRACE( "starting %s\n", wine_dbgstr_w(cmdline
) );
797 if (CreateProcessW( NULL
, cmdline
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
799 CloseHandle( pi
.hThread
);
800 CloseHandle( pi
.hProcess
);
804 /* run the desktop message loop */
807 WINE_TRACE( "desktop message loop starting on hwnd %p\n", hwnd
);
808 while (GetMessageW( &msg
, 0, 0, 0 )) DispatchMessageW( &msg
);
809 WINE_TRACE( "desktop message loop exiting for hwnd %p\n", hwnd
);