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
36 static HBRUSH hbrushPattern
;
37 static HBITMAP hbitmapWallPaper
;
38 static SIZE bitmapSize
;
39 static BOOL fTileWallPaper
;
42 /*********************************************************************
43 * desktop class descriptor
45 const struct builtin_class_descr DESKTOP_builtin_class
=
47 (LPCWSTR
)DESKTOP_CLASS_ATOM
, /* name */
48 CS_DBLCLKS
, /* style */
49 WINPROC_DESKTOP
, /* proc */
51 IDC_ARROW
, /* cursor */
52 (HBRUSH
)(COLOR_BACKGROUND
+1) /* brush */
56 /***********************************************************************
59 * Load a bitmap from a file. Used by SetDeskWallPaper().
61 static HBITMAP
DESKTOP_LoadBitmap( HDC hdc
, const char *filename
)
63 BITMAPFILEHEADER
*fileHeader
;
64 BITMAPINFO
*bitmapInfo
;
70 /* Read all the file into memory */
72 if ((file
= _lopen( filename
, OF_READ
)) == HFILE_ERROR
)
74 UINT len
= GetWindowsDirectoryA( NULL
, 0 );
75 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0,
76 len
+ strlen(filename
) + 2 )))
78 GetWindowsDirectoryA( buffer
, len
+ 1 );
79 strcat( buffer
, "\\" );
80 strcat( buffer
, filename
);
81 file
= _lopen( buffer
, OF_READ
);
82 HeapFree( GetProcessHeap(), 0, buffer
);
84 if (file
== HFILE_ERROR
) return 0;
85 size
= _llseek( file
, 0, 2 );
86 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
)))
91 _llseek( file
, 0, 0 );
92 size
= _lread( file
, buffer
, size
);
94 fileHeader
= (BITMAPFILEHEADER
*)buffer
;
95 bitmapInfo
= (BITMAPINFO
*)(buffer
+ sizeof(BITMAPFILEHEADER
));
97 /* Check header content */
98 if ((fileHeader
->bfType
!= 0x4d42) || (size
< fileHeader
->bfSize
))
100 HeapFree( GetProcessHeap(), 0, buffer
);
103 hbitmap
= CreateDIBitmap( hdc
, &bitmapInfo
->bmiHeader
, CBM_INIT
,
104 buffer
+ fileHeader
->bfOffBits
,
105 bitmapInfo
, DIB_RGB_COLORS
);
106 HeapFree( GetProcessHeap(), 0, buffer
);
112 /***********************************************************************
115 LRESULT WINAPI
DesktopWndProc( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
117 if (message
== WM_NCCREATE
) return TRUE
;
118 return 0; /* all other messages are ignored */
121 /***********************************************************************
122 * PaintDesktop (USER32.@)
125 BOOL WINAPI
PaintDesktop(HDC hdc
)
127 HWND hwnd
= GetDesktopWindow();
129 /* check for an owning thread; otherwise don't paint anything (non-desktop mode) */
130 if (GetWindowThreadProcessId( hwnd
, NULL
))
134 GetClientRect( hwnd
, &rect
);
136 /* Paint desktop pattern (only if wall paper does not cover everything) */
138 if (!hbitmapWallPaper
||
139 (!fTileWallPaper
&& ((bitmapSize
.cx
< rect
.right
) || (bitmapSize
.cy
< rect
.bottom
))))
141 HBRUSH brush
= hbrushPattern
;
142 if (!brush
) brush
= (HBRUSH
)GetClassLongPtrW( hwnd
, GCLP_HBRBACKGROUND
);
143 /* Set colors in case pattern is a monochrome bitmap */
144 SetBkColor( hdc
, RGB(0,0,0) );
145 SetTextColor( hdc
, GetSysColor(COLOR_BACKGROUND
) );
146 FillRect( hdc
, &rect
, brush
);
149 /* Paint wall paper */
151 if (hbitmapWallPaper
)
154 HDC hMemDC
= CreateCompatibleDC( hdc
);
156 SelectObject( hMemDC
, hbitmapWallPaper
);
160 for (y
= 0; y
< rect
.bottom
; y
+= bitmapSize
.cy
)
161 for (x
= 0; x
< rect
.right
; x
+= bitmapSize
.cx
)
162 BitBlt( hdc
, x
, y
, bitmapSize
.cx
, bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
166 x
= (rect
.left
+ rect
.right
- bitmapSize
.cx
) / 2;
167 y
= (rect
.top
+ rect
.bottom
- bitmapSize
.cy
) / 2;
170 BitBlt( hdc
, x
, y
, bitmapSize
.cx
, bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
178 /***********************************************************************
179 * SetDeskWallPaper (USER32.@)
181 * FIXME: is there a unicode version?
183 BOOL WINAPI
SetDeskWallPaper( LPCSTR filename
)
189 if (filename
== (LPSTR
)-1)
191 GetProfileStringA( "desktop", "WallPaper", "(None)", buffer
, 256 );
195 hbitmap
= DESKTOP_LoadBitmap( hdc
, filename
);
197 if (hbitmapWallPaper
) DeleteObject( hbitmapWallPaper
);
198 hbitmapWallPaper
= hbitmap
;
199 fTileWallPaper
= GetProfileIntA( "desktop", "TileWallPaper", 0 );
203 GetObjectA( hbitmap
, sizeof(bmp
), &bmp
);
204 bitmapSize
.cx
= (bmp
.bmWidth
!= 0) ? bmp
.bmWidth
: 1;
205 bitmapSize
.cy
= (bmp
.bmHeight
!= 0) ? bmp
.bmHeight
: 1;
211 /***********************************************************************
214 * Set the desktop pattern.
216 BOOL
DESKTOP_SetPattern( LPCWSTR pattern
)
220 if (hbrushPattern
) DeleteObject( hbrushPattern
);
222 memset( pat
, 0, sizeof(pat
) );
226 WideCharToMultiByte( CP_ACP
, 0, pattern
, -1, buffer
, sizeof(buffer
), NULL
, NULL
);
227 if (sscanf( buffer
, " %d %d %d %d %d %d %d %d",
228 &pat
[0], &pat
[1], &pat
[2], &pat
[3],
229 &pat
[4], &pat
[5], &pat
[6], &pat
[7] ))
235 for (i
= 0; i
< 8; i
++) ptrn
[i
] = pat
[i
] & 0xffff;
236 hbitmap
= CreateBitmap( 8, 8, 1, 1, ptrn
);
237 hbrushPattern
= CreatePatternBrush( hbitmap
);
238 DeleteObject( hbitmap
);