explorer: Added desktop option.
[wine] / programs / explorer / desktop.c
1 /*
2  * Explorer desktop support
3  *
4  * Copyright 2006 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <windows.h>
22 #include <wine/debug.h>
23 #include "explorer_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(explorer);
26
27 #define DESKTOP_CLASS_ATOM MAKEINTATOMW(32769)
28
29 static LRESULT WINAPI desktop_wnd_proc( HWND hwnd, UINT message, WPARAM wp, LPARAM lp )
30 {
31     WINE_TRACE( "got msg %x wp %x lp %lx\n", message, wp, lp );
32
33     switch(message)
34     {
35     case WM_SYSCOMMAND:
36         if ((wp & 0xfff0) == SC_CLOSE) ExitWindows( 0, 0 );
37         break;
38
39     case WM_SETCURSOR:
40         return (LRESULT)SetCursor( LoadCursorA( 0, (LPSTR)IDC_ARROW ) );
41
42     case WM_NCHITTEST:
43         return HTCLIENT;
44
45     case WM_ERASEBKGND:
46         PaintDesktop( (HDC)wp );
47         return TRUE;
48
49     case WM_PAINT:
50         {
51             PAINTSTRUCT ps;
52             BeginPaint( hwnd, &ps );
53             if (ps.fErase) PaintDesktop( ps.hdc );
54             EndPaint( hwnd, &ps );
55         }
56         return 0;
57     }
58     return 0;
59 }
60
61 void manage_desktop(void)
62 {
63     MSG msg;
64     HWND hwnd = CreateWindowExW( 0, DESKTOP_CLASS_ATOM, NULL,
65                                  WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
66                                  0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
67                                  0, 0, 0, NULL );
68     if (hwnd != GetDesktopWindow()) return;  /* some other process beat us to it */
69     SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)desktop_wnd_proc );
70
71     WINE_TRACE( "explorer starting on hwnd %p\n", hwnd );
72     while (GetMessageW( &msg, 0, 0, 0 )) DispatchMessageW( &msg );
73     WINE_TRACE( "explorer exiting for hwnd %p\n", hwnd );
74 }