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 if (GetAncestor( hwnd
, GA_PARENT
)) return FALSE
; /* refuse to create non-desktop window */
122 sprintfW( buffer
, guid_formatW
, guid
->Data1
, guid
->Data2
, guid
->Data3
,
123 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
124 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7] );
125 atom
= GlobalAddAtomW( buffer
);
126 SetPropW( hwnd
, display_device_guid_propW
, ULongToHandle( atom
) );
133 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
137 /***********************************************************************
138 * PaintDesktop (USER32.@)
141 BOOL WINAPI
PaintDesktop(HDC hdc
)
143 HWND hwnd
= GetDesktopWindow();
145 /* check for an owning thread; otherwise don't paint anything (non-desktop mode) */
146 if (GetWindowThreadProcessId( hwnd
, NULL
))
150 GetClientRect( hwnd
, &rect
);
152 /* Paint desktop pattern (only if wall paper does not cover everything) */
154 if (!hbitmapWallPaper
||
155 (!fTileWallPaper
&& ((bitmapSize
.cx
< rect
.right
) || (bitmapSize
.cy
< rect
.bottom
))))
157 HBRUSH brush
= hbrushPattern
;
158 if (!brush
) brush
= (HBRUSH
)GetClassLongPtrW( hwnd
, GCLP_HBRBACKGROUND
);
159 /* Set colors in case pattern is a monochrome bitmap */
160 SetBkColor( hdc
, RGB(0,0,0) );
161 SetTextColor( hdc
, GetSysColor(COLOR_BACKGROUND
) );
162 FillRect( hdc
, &rect
, brush
);
165 /* Paint wall paper */
167 if (hbitmapWallPaper
)
170 HDC hMemDC
= CreateCompatibleDC( hdc
);
172 SelectObject( hMemDC
, hbitmapWallPaper
);
176 for (y
= 0; y
< rect
.bottom
; y
+= bitmapSize
.cy
)
177 for (x
= 0; x
< rect
.right
; x
+= bitmapSize
.cx
)
178 BitBlt( hdc
, x
, y
, bitmapSize
.cx
, bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
182 x
= (rect
.left
+ rect
.right
- bitmapSize
.cx
) / 2;
183 y
= (rect
.top
+ rect
.bottom
- bitmapSize
.cy
) / 2;
186 BitBlt( hdc
, x
, y
, bitmapSize
.cx
, bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
194 /***********************************************************************
195 * SetDeskWallPaper (USER32.@)
197 * FIXME: is there a unicode version?
199 BOOL WINAPI
SetDeskWallPaper( LPCSTR filename
)
201 return SystemParametersInfoA( SPI_SETDESKWALLPAPER
, MAX_PATH
, (void *)filename
, SPIF_UPDATEINIFILE
);
205 /***********************************************************************
208 BOOL
update_wallpaper( const WCHAR
*wallpaper
, const WCHAR
*pattern
)
212 if (hbrushPattern
) DeleteObject( hbrushPattern
);
214 memset( pat
, 0, sizeof(pat
) );
218 WideCharToMultiByte( CP_ACP
, 0, pattern
, -1, buffer
, sizeof(buffer
), NULL
, NULL
);
219 if (sscanf( buffer
, " %d %d %d %d %d %d %d %d",
220 &pat
[0], &pat
[1], &pat
[2], &pat
[3],
221 &pat
[4], &pat
[5], &pat
[6], &pat
[7] ))
227 for (i
= 0; i
< 8; i
++) ptrn
[i
] = pat
[i
] & 0xffff;
228 hbitmap
= CreateBitmap( 8, 8, 1, 1, ptrn
);
229 hbrushPattern
= CreatePatternBrush( hbitmap
);
230 DeleteObject( hbitmap
);
233 init_wallpaper( wallpaper
);
234 RedrawWindow( GetDesktopWindow(), 0, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_NOCHILDREN
);