2 * Desktop window class.
4 * Copyright 1994 Alexandre Julliard
15 /***********************************************************************
18 * Load a bitmap from a file. Used by SetDeskWallPaper().
20 static HBITMAP32
DESKTOP_LoadBitmap( HDC32 hdc
, const char *filename
)
22 BITMAPFILEHEADER
*fileHeader
;
23 BITMAPINFO
*bitmapInfo
;
29 /* Read all the file into memory */
31 if ((file
= _lopen32( filename
, OF_READ
)) == HFILE_ERROR32
)
33 UINT32 len
= GetWindowsDirectory32A( NULL
, 0 );
34 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0,
35 len
+ strlen(filename
) + 2 )))
37 GetWindowsDirectory32A( buffer
, len
+ 1 );
38 strcat( buffer
, "\\" );
39 strcat( buffer
, filename
);
40 file
= _lopen32( buffer
, OF_READ
);
41 HeapFree( GetProcessHeap(), 0, buffer
);
43 if (file
== HFILE_ERROR32
) return 0;
44 size
= _llseek32( file
, 0, 2 );
45 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
)))
50 _llseek32( file
, 0, 0 );
51 size
= _lread32( file
, buffer
, size
);
53 fileHeader
= (BITMAPFILEHEADER
*)buffer
;
54 bitmapInfo
= (BITMAPINFO
*)(buffer
+ sizeof(BITMAPFILEHEADER
));
56 /* Check header content */
57 if ((fileHeader
->bfType
!= 0x4d42) || (size
< fileHeader
->bfSize
))
59 HeapFree( GetProcessHeap(), 0, buffer
);
62 hbitmap
= CreateDIBitmap32( hdc
, &bitmapInfo
->bmiHeader
, CBM_INIT
,
63 buffer
+ fileHeader
->bfOffBits
,
64 bitmapInfo
, DIB_RGB_COLORS
);
65 HeapFree( GetProcessHeap(), 0, buffer
);
70 /***********************************************************************
71 * DESKTOP_DoEraseBkgnd
73 * Handle the WM_ERASEBKGND message.
75 static LRESULT
DESKTOP_DoEraseBkgnd( HWND32 hwnd
, HDC32 hdc
,
76 DESKTOPINFO
*infoPtr
)
79 WND
* Wnd
= WIN_FindWndPtr( hwnd
);
81 if (Wnd
->hrgnUpdate
> 1) DeleteObject32( Wnd
->hrgnUpdate
);
84 GetClientRect32( hwnd
, &rect
);
86 /* Paint desktop pattern (only if wall paper does not cover everything) */
88 if (!infoPtr
->hbitmapWallPaper
||
89 (!infoPtr
->fTileWallPaper
&& ((infoPtr
->bitmapSize
.cx
< rect
.right
) ||
90 (infoPtr
->bitmapSize
.cy
< rect
.bottom
))))
92 /* Set colors in case pattern is a monochrome bitmap */
93 SetBkColor32( hdc
, RGB(0,0,0) );
94 SetTextColor32( hdc
, GetSysColor32(COLOR_BACKGROUND
) );
95 FillRect32( hdc
, &rect
, infoPtr
->hbrushPattern
);
98 /* Paint wall paper */
100 if (infoPtr
->hbitmapWallPaper
)
103 HDC32 hMemDC
= CreateCompatibleDC32( hdc
);
105 SelectObject32( hMemDC
, infoPtr
->hbitmapWallPaper
);
107 if (infoPtr
->fTileWallPaper
)
109 for (y
= 0; y
< rect
.bottom
; y
+= infoPtr
->bitmapSize
.cy
)
110 for (x
= 0; x
< rect
.right
; x
+= infoPtr
->bitmapSize
.cx
)
111 BitBlt32( hdc
, x
, y
, infoPtr
->bitmapSize
.cx
,
112 infoPtr
->bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
116 x
= (rect
.left
+ rect
.right
- infoPtr
->bitmapSize
.cx
) / 2;
117 y
= (rect
.top
+ rect
.bottom
- infoPtr
->bitmapSize
.cy
) / 2;
120 BitBlt32( hdc
, x
, y
, infoPtr
->bitmapSize
.cx
,
121 infoPtr
->bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
123 DeleteDC32( hMemDC
);
130 /***********************************************************************
133 * Window procedure for the desktop window.
135 LRESULT WINAPI
DesktopWndProc( HWND32 hwnd
, UINT32 message
,
136 WPARAM32 wParam
, LPARAM lParam
)
138 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
139 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
141 /* Most messages are ignored (we DON'T call DefWindowProc) */
145 /* Warning: this message is sent directly by */
146 /* WIN_CreateDesktopWindow() and does not contain a valid lParam */
148 infoPtr
->hbrushPattern
= 0;
149 infoPtr
->hbitmapWallPaper
= 0;
151 SetDeskWallPaper32( (LPSTR
)-1 );
155 if (rootWindow
== DefaultRootWindow(display
)) return 1;
156 return DESKTOP_DoEraseBkgnd( hwnd
, (HDC32
)wParam
, infoPtr
);
159 if ((wParam
& 0xfff0) != SC_CLOSE
) return 0;
160 ExitWindows16( 0, 0 );
163 return (LRESULT
)SetCursor16( LoadCursor16( 0, IDC_ARROW16
) );
169 /***********************************************************************
170 * PaintDesktop (USER32.415)
173 BOOL32 WINAPI
PaintDesktop(HDC32 hdc
)
175 HWND32 hwnd
= GetDesktopWindow32();
176 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
177 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
179 return DESKTOP_DoEraseBkgnd( hwnd
, hdc
, infoPtr
);
182 /***********************************************************************
183 * SetDeskPattern (USER.279)
185 BOOL16 WINAPI
SetDeskPattern(void)
188 GetProfileString32A( "desktop", "Pattern", "(None)", buffer
, 100 );
189 return DESKTOP_SetPattern( buffer
);
193 /***********************************************************************
194 * SetDeskWallPaper16 (USER.285)
196 BOOL16 WINAPI
SetDeskWallPaper16( LPCSTR filename
)
198 return SetDeskWallPaper32( filename
);
202 /***********************************************************************
203 * SetDeskWallPaper32 (USER32.475)
205 * FIXME: is there a unicode version?
207 BOOL32 WINAPI
SetDeskWallPaper32( LPCSTR filename
)
212 WND
*wndPtr
= WIN_GetDesktop();
213 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
215 if (filename
== (LPSTR
)-1)
217 GetProfileString32A( "desktop", "WallPaper", "(None)", buffer
, 256 );
221 hbitmap
= DESKTOP_LoadBitmap( hdc
, filename
);
222 ReleaseDC32( 0, hdc
);
223 if (infoPtr
->hbitmapWallPaper
) DeleteObject32( infoPtr
->hbitmapWallPaper
);
224 infoPtr
->hbitmapWallPaper
= hbitmap
;
225 infoPtr
->fTileWallPaper
= GetProfileInt32A( "desktop", "TileWallPaper", 0 );
229 GetObject32A( hbitmap
, sizeof(bmp
), &bmp
);
230 infoPtr
->bitmapSize
.cx
= (bmp
.bmWidth
!= 0) ? bmp
.bmWidth
: 1;
231 infoPtr
->bitmapSize
.cy
= (bmp
.bmHeight
!= 0) ? bmp
.bmHeight
: 1;
237 /***********************************************************************
240 * Set the desktop pattern.
242 BOOL32
DESKTOP_SetPattern( LPCSTR pattern
)
244 WND
*wndPtr
= WIN_GetDesktop();
245 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
248 if (infoPtr
->hbrushPattern
) DeleteObject32( infoPtr
->hbrushPattern
);
249 memset( pat
, 0, sizeof(pat
) );
250 if (pattern
&& sscanf( pattern
, " %d %d %d %d %d %d %d %d",
251 &pat
[0], &pat
[1], &pat
[2], &pat
[3],
252 &pat
[4], &pat
[5], &pat
[6], &pat
[7] ))
258 for (i
= 0; i
< 8; i
++) pattern
[i
] = pat
[i
] & 0xffff;
259 hbitmap
= CreateBitmap32( 8, 8, 1, 1, (LPSTR
)pattern
);
260 infoPtr
->hbrushPattern
= CreatePatternBrush32( hbitmap
);
261 DeleteObject32( hbitmap
);
263 else infoPtr
->hbrushPattern
= CreateSolidBrush32( GetSysColor32(COLOR_BACKGROUND
) );