Commit b2fa004e authored by Alexandre Julliard's avatar Alexandre Julliard

user32: Simplify initialization of the desktop wallpaper.

parent 4d653b77
...@@ -55,59 +55,44 @@ const struct builtin_class_descr DESKTOP_builtin_class = ...@@ -55,59 +55,44 @@ const struct builtin_class_descr DESKTOP_builtin_class =
/*********************************************************************** /***********************************************************************
* DESKTOP_LoadBitmap * DESKTOP_LoadBitmap
*
* Load a bitmap from a file. Used by SetDeskWallPaper().
*/ */
static HBITMAP DESKTOP_LoadBitmap( HDC hdc, const char *filename ) static HBITMAP DESKTOP_LoadBitmap(void)
{ {
BITMAPFILEHEADER *fileHeader;
BITMAPINFO *bitmapInfo;
HBITMAP hbitmap; HBITMAP hbitmap;
HFILE file; WCHAR filename[MAX_PATH];
LPSTR buffer;
LONG size;
/* Read all the file into memory */
if ((file = _lopen( filename, OF_READ )) == HFILE_ERROR) if (!SystemParametersInfoW( SPI_GETDESKWALLPAPER, MAX_PATH, filename, 0 )) return 0;
if (!filename[0]) return 0;
hbitmap = LoadImageW( 0, filename, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
if (!hbitmap)
{ {
UINT len = GetWindowsDirectoryA( NULL, 0 ); WCHAR buffer[MAX_PATH];
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, UINT len = GetWindowsDirectoryW( buffer, MAX_PATH - 2 );
len + strlen(filename) + 2 ))) if (buffer[len - 1] != '\\') buffer[len++] = '\\';
return 0; lstrcpynW( buffer + len, filename, MAX_PATH - len );
GetWindowsDirectoryA( buffer, len + 1 ); hbitmap = LoadImageW( 0, buffer, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
strcat( buffer, "\\" );
strcat( buffer, filename );
file = _lopen( buffer, OF_READ );
HeapFree( GetProcessHeap(), 0, buffer );
} }
if (file == HFILE_ERROR) return 0;
size = _llseek( file, 0, 2 );
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
{
_lclose( file );
return 0;
}
_llseek( file, 0, 0 );
size = _lread( file, buffer, size );
_lclose( file );
fileHeader = (BITMAPFILEHEADER *)buffer;
bitmapInfo = (BITMAPINFO *)(buffer + sizeof(BITMAPFILEHEADER));
/* Check header content */
if ((fileHeader->bfType != 0x4d42) || (size < fileHeader->bfSize))
{
HeapFree( GetProcessHeap(), 0, buffer );
return 0;
}
hbitmap = CreateDIBitmap( hdc, &bitmapInfo->bmiHeader, CBM_INIT,
buffer + fileHeader->bfOffBits,
bitmapInfo, DIB_RGB_COLORS );
HeapFree( GetProcessHeap(), 0, buffer );
return hbitmap; return hbitmap;
} }
/***********************************************************************
* init_wallpaper
*/
static void init_wallpaper(void)
{
HBITMAP hbitmap = DESKTOP_LoadBitmap();
if (hbitmapWallPaper) DeleteObject( hbitmapWallPaper );
hbitmapWallPaper = hbitmap;
if (hbitmap)
{
BITMAP bmp;
GetObjectA( hbitmap, sizeof(bmp), &bmp );
bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
}
}
/*********************************************************************** /***********************************************************************
* DesktopWndProc * DesktopWndProc
...@@ -182,29 +167,7 @@ BOOL WINAPI PaintDesktop(HDC hdc) ...@@ -182,29 +167,7 @@ BOOL WINAPI PaintDesktop(HDC hdc)
*/ */
BOOL WINAPI SetDeskWallPaper( LPCSTR filename ) BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
{ {
HBITMAP hbitmap; return SystemParametersInfoA( SPI_SETDESKWALLPAPER, MAX_PATH, (void *)filename, SPIF_UPDATEINIFILE );
HDC hdc;
char buffer[256];
if (filename == (LPSTR)-1)
{
GetProfileStringA( "desktop", "WallPaper", "(None)", buffer, 256 );
filename = buffer;
}
hdc = GetDC( 0 );
hbitmap = DESKTOP_LoadBitmap( hdc, filename );
ReleaseDC( 0, hdc );
if (hbitmapWallPaper) DeleteObject( hbitmapWallPaper );
hbitmapWallPaper = hbitmap;
fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
if (hbitmap)
{
BITMAP bmp;
GetObjectA( hbitmap, sizeof(bmp), &bmp );
bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
}
return TRUE;
} }
...@@ -238,5 +201,6 @@ BOOL DESKTOP_SetPattern( LPCWSTR pattern ) ...@@ -238,5 +201,6 @@ BOOL DESKTOP_SetPattern( LPCWSTR pattern )
DeleteObject( hbitmap ); DeleteObject( hbitmap );
} }
} }
init_wallpaper();
return TRUE; return TRUE;
} }
...@@ -312,7 +312,6 @@ void manage_desktop( WCHAR *arg ) ...@@ -312,7 +312,6 @@ void manage_desktop( WCHAR *arg )
SendMessageW( hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIconW( 0, MAKEINTRESOURCEW(OIC_WINLOGO))); SendMessageW( hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIconW( 0, MAKEINTRESOURCEW(OIC_WINLOGO)));
if (name) set_desktop_window_title( hwnd, name ); if (name) set_desktop_window_title( hwnd, name );
SystemParametersInfoA( SPI_SETDESKPATTERN, -1, NULL, FALSE ); SystemParametersInfoA( SPI_SETDESKPATTERN, -1, NULL, FALSE );
SetDeskWallPaper( (LPSTR)-1 );
ClipCursor( NULL ); ClipCursor( NULL );
initialize_display_settings( hwnd ); initialize_display_settings( hwnd );
initialize_appbar(); initialize_appbar();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment