2 * Desktop window class.
4 * Copyright 1994 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
35 #include "wine/unicode.h"
37 static HBRUSH hbrushPattern
;
38 static HBITMAP hbitmapWallPaper
;
39 static SIZE bitmapSize
;
40 static BOOL fTileWallPaper
;
43 /*********************************************************************
44 * desktop class descriptor
46 const struct builtin_class_descr DESKTOP_builtin_class
=
48 (LPCWSTR
)DESKTOP_CLASS_ATOM
, /* name */
49 CS_DBLCLKS
, /* style */
50 WINPROC_DESKTOP
, /* proc */
53 (HBRUSH
)(COLOR_BACKGROUND
+1) /* brush */
57 /***********************************************************************
60 static HBITMAP
DESKTOP_LoadBitmap( const WCHAR
*filename
)
64 if (!filename
[0]) return 0;
65 hbitmap
= LoadImageW( 0, filename
, IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
| LR_LOADFROMFILE
);
68 WCHAR buffer
[MAX_PATH
];
69 UINT len
= GetWindowsDirectoryW( buffer
, MAX_PATH
- 2 );
70 if (buffer
[len
- 1] != '\\') buffer
[len
++] = '\\';
71 lstrcpynW( buffer
+ len
, filename
, MAX_PATH
- len
);
72 hbitmap
= LoadImageW( 0, buffer
, IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
| LR_LOADFROMFILE
);
77 /***********************************************************************
80 static void init_wallpaper( const WCHAR
*wallpaper
)
82 HBITMAP hbitmap
= DESKTOP_LoadBitmap( wallpaper
);
84 if (hbitmapWallPaper
) DeleteObject( hbitmapWallPaper
);
85 hbitmapWallPaper
= hbitmap
;
89 GetObjectA( hbitmap
, sizeof(bmp
), &bmp
);
90 bitmapSize
.cx
= (bmp
.bmWidth
!= 0) ? bmp
.bmWidth
: 1;
91 bitmapSize
.cy
= (bmp
.bmHeight
!= 0) ? bmp
.bmHeight
: 1;
92 fTileWallPaper
= GetProfileIntA( "desktop", "TileWallPaper", 0 );
96 /***********************************************************************
99 LRESULT WINAPI
DesktopWndProc( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
101 static const WCHAR display_device_guid_propW
[] = {
102 '_','_','w','i','n','e','_','d','i','s','p','l','a','y','_',
103 'd','e','v','i','c','e','_','g','u','i','d',0 };
104 static const WCHAR guid_formatW
[] = {
105 '%','0','8','x','-','%','0','4','x','-','%','0','4','x','-','%','0','2','x','%','0','2','x','-',
106 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x',0};
112 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lParam
;
113 const GUID
*guid
= cs
->lpCreateParams
;
120 sprintfW( buffer
, guid_formatW
, guid
->Data1
, guid
->Data2
, guid
->Data3
,
121 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
122 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7] );
123 atom
= GlobalAddAtomW( buffer
);
124 SetPropW( hwnd
, display_device_guid_propW
, ULongToHandle( atom
) );
129 return 0; /* all other messages are ignored */
133 /***********************************************************************
134 * PaintDesktop (USER32.@)
137 BOOL WINAPI
PaintDesktop(HDC hdc
)
139 HWND hwnd
= GetDesktopWindow();
141 /* check for an owning thread; otherwise don't paint anything (non-desktop mode) */
142 if (GetWindowThreadProcessId( hwnd
, NULL
))
146 GetClientRect( hwnd
, &rect
);
148 /* Paint desktop pattern (only if wall paper does not cover everything) */
150 if (!hbitmapWallPaper
||
151 (!fTileWallPaper
&& ((bitmapSize
.cx
< rect
.right
) || (bitmapSize
.cy
< rect
.bottom
))))
153 HBRUSH brush
= hbrushPattern
;
154 if (!brush
) brush
= (HBRUSH
)GetClassLongPtrW( hwnd
, GCLP_HBRBACKGROUND
);
155 /* Set colors in case pattern is a monochrome bitmap */
156 SetBkColor( hdc
, RGB(0,0,0) );
157 SetTextColor( hdc
, GetSysColor(COLOR_BACKGROUND
) );
158 FillRect( hdc
, &rect
, brush
);
161 /* Paint wall paper */
163 if (hbitmapWallPaper
)
166 HDC hMemDC
= CreateCompatibleDC( hdc
);
168 SelectObject( hMemDC
, hbitmapWallPaper
);
172 for (y
= 0; y
< rect
.bottom
; y
+= bitmapSize
.cy
)
173 for (x
= 0; x
< rect
.right
; x
+= bitmapSize
.cx
)
174 BitBlt( hdc
, x
, y
, bitmapSize
.cx
, bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
178 x
= (rect
.left
+ rect
.right
- bitmapSize
.cx
) / 2;
179 y
= (rect
.top
+ rect
.bottom
- bitmapSize
.cy
) / 2;
182 BitBlt( hdc
, x
, y
, bitmapSize
.cx
, bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
190 /***********************************************************************
191 * SetDeskWallPaper (USER32.@)
193 * FIXME: is there a unicode version?
195 BOOL WINAPI
SetDeskWallPaper( LPCSTR filename
)
197 return SystemParametersInfoA( SPI_SETDESKWALLPAPER
, MAX_PATH
, (void *)filename
, SPIF_UPDATEINIFILE
);
201 /***********************************************************************
204 BOOL
update_wallpaper( const WCHAR
*wallpaper
, const WCHAR
*pattern
)
208 if (hbrushPattern
) DeleteObject( hbrushPattern
);
210 memset( pat
, 0, sizeof(pat
) );
214 WideCharToMultiByte( CP_ACP
, 0, pattern
, -1, buffer
, sizeof(buffer
), NULL
, NULL
);
215 if (sscanf( buffer
, " %d %d %d %d %d %d %d %d",
216 &pat
[0], &pat
[1], &pat
[2], &pat
[3],
217 &pat
[4], &pat
[5], &pat
[6], &pat
[7] ))
223 for (i
= 0; i
< 8; i
++) ptrn
[i
] = pat
[i
] & 0xffff;
224 hbitmap
= CreateBitmap( 8, 8, 1, 1, ptrn
);
225 hbrushPattern
= CreatePatternBrush( hbitmap
);
226 DeleteObject( hbitmap
);
229 init_wallpaper( wallpaper
);
230 RedrawWindow( GetDesktopWindow(), 0, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_NOCHILDREN
);