- #1
TenNen
- 97
- 0
how i can use a bitmap as background image ?
Thanks
Thanks
faust9,faust9 said:In what? Are you using Gnome? Are you using KDE? Are you using the WinAPI? Are you using Mac OS X? Are you using another windowing environment? Are you trying to set the background for a particular piece of software (AIM for example)?
If you're trying to do this in a piece of software of your own design which platform are you running? Are you using an IDE if so which?
Most IDE's have the ability to select a background bmp and generate the appropriate code for you. I know KDevelope does, Glade(2) Does, Mac Interface Builder does, and I'm almost (+) VC++ does.
[edit]The Qt interface builder does, not KDevelope. Qt interface builder can be invoke from KDevelope though before any KDE users correct me.
Anteros said:What are you trying to set the background of? I am racking my brain trying to think of something in which the background is a number but can't. Start over from the beginning and tell us exactly what you are trying to set the background of, on what platform, in what programming language and then hopfully we will be able to help.
I think I got that this was windows. Is this a GUI application? Console?
Is this C++/MFC, .NET, web programming, or something totally different?
LRESULT CALLBACK WndProc (HWND hWnd,
UINT ui<essage,
WPARAM wParam,
LPARAM lParam)
{
static BITMAPFILEHEADER *pbmfh;
static BITMAPINFO *pbmi;
static BYTE *pBits;
static int cxDib, cyDib;
DWORD dwFileSize, dwHighSize, dwBytesRead;
HANDLE hFile;
hFile = CreateFile ("C:\\!place file path here, lose the ! keep the quotes",
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_FLAG_SEQUENTIAL_SCAN,
NULL);
dwFileSize = GetFileSize(hFile, &bdHighSize);
pbmfh = (BITMAPHEADER) * malloc (dxFileSize);
ReadFile (hFile,
pbmfh,
dwFileSize,
&dwBytesRead,
NULL);
pbmi= (BITMAPINFO) * (pbmfh+1);
pBits = (BYTE) * pbmfh + pbmfh->bfOffBits;
cxDib = pbmi->bmiHeader.biWidth;
cyDib = abs(pbmi->bmiHeader.biHeight);
HDC hdc;
hdc = GetDC(hWnd);
SetDIBitsToDevice (hdc,
0,
0,
cxDib,
cyDib,
0,
0,
0,
cyDib,
pBits,
pbmi,
DIB_RGB_COLOR);
ReleaseDC (hWind, hdc);
free (pbmfh);
return 0;
}
/************************************
REVISION LOG ENTRY
Revision By: Mihai Filimon
Revised on 11/24/99 9:45:45 AM
Comments: PictureWindow.h: interface for the CPictureWindow class.
************************************/
#if !defined(AFX_PICTUREWINDOW_H__44323373_9E89_11D3_A393_00C0DFC59237__INCLUDED_)
#define AFX_PICTUREWINDOW_H__44323373_9E89_11D3_A393_00C0DFC59237__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <atlbase.h>
#include <atlwin.h>
class CPictureWindow : public CWindowImpl<CPictureWindow>
{
public:
typedef enum HandlerTypeEnum
{
ClientPaint = WM_PAINT,
BackGroundPaint = WM_ERASEBKGND
} HandlerTypeEnum;
CPictureWindow()
{
m_nMessageHandler = ClientPaint;
};
virtual ~CPictureWindow()
{
};
BEGIN_MSG_MAP(CPictureWindow)
MESSAGE_HANDLER(WM_PAINT, OnPaint)
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkGnd)
END_MSG_MAP()
// Function name : Load
// Description : Loads the picture into memory, and then display it!
// Return type : virtual BOOL
// Argument : LPCTSTR szFileName
virtual BOOL Load( LPCTSTR szFileName )
{
BOOL bResult = FALSE;
Close();
if ( szFileName )
{
OFSTRUCT of;
HANDLE hFile = NULL;;
if ( (hFile = (HANDLE)OpenFile( szFileName, &of, OF_READ | OF_SHARE_COMPAT)) != (HANDLE)HFILE_ERROR )
{
DWORD dwHighWord = NULL, dwSizeLow = GetFileSize( hFile, &dwHighWord );
DWORD dwFileSize = dwSizeLow;
HRESULT hResult = NULL;
if ( HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize) )
if ( void* pvData = GlobalLock( hGlobal ) )
{
DWORD dwReadBytes = NULL;
BOOL bRead = ReadFile( hFile, pvData, dwFileSize, &dwReadBytes, NULL );
GlobalUnlock( hGlobal );
if ( bRead )
{
CComPtr<IStream> spStream;
_ASSERTE( dwFileSize == dwReadBytes );
if ( SUCCEEDED( CreateStreamOnHGlobal( hGlobal, TRUE, &spStream) ) )
if ( SUCCEEDED( hResult = OleLoadPicture( spStream, 0, FALSE, IID_IPicture, (void**)&m_spPicture ) ) )
bResult = TRUE;
}
}
CloseHandle( hFile );
}
}
Invalidate();
return bResult;
}
HandlerTypeEnum m_nMessageHandler;
protected:
inline virtual BOOL IsHandlerMessage( UINT uMsg )
{
return m_nMessageHandler == (HandlerTypeEnum)uMsg ;
}
void PutPicture( IPicture* pPicture, HDC hDC, RECT rPicture )
{
OLE_XSIZE_HIMETRIC nWidth = NULL; OLE_YSIZE_HIMETRIC nHeight = NULL;
pPicture->get_Width( &nWidth ); pPicture->get_Height( &nHeight );
pPicture->Render( hDC, rPicture.left ,rPicture.top, rPicture.right - rPicture.left, rPicture.bottom - rPicture.top, 0, nHeight, nWidth, -nHeight, NULL );
};
LRESULT OnEraseBkGnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if ( IsHandlerMessage( uMsg ) )
{
if ( m_spPicture )
{
BeginPaint( NULL );
RECT r ; GetClientRect( &r );
HDC hDC = GetDC();
HWND hWndChild = GetWindow( GW_CHILD );
while ( ::IsWindow( hWndChild ) )
{
if ( ::IsWindowVisible( hWndChild ) )
{
RECT rChild; ::GetWindowRect( hWndChild, &rChild );
ScreenToClient( &rChild );
ExcludeClipRect( hDC, rChild.left, rChild.top, rChild.right, rChild.bottom );
}
hWndChild = ::GetWindow( hWndChild, GW_HWNDNEXT );
}
PutPicture( m_spPicture, hDC, r );
ReleaseDC( hDC );
EndPaint( NULL );
return TRUE;
}
}
bHandled = FALSE;
return FALSE;
};
LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if ( IsHandlerMessage( uMsg ) )
{
if ( m_spPicture )
{
BeginPaint( NULL );
RECT r ; GetClientRect( &r );
HDC hDC = GetDC();
PutPicture( m_spPicture, hDC, r );
ReleaseDC( hDC );
EndPaint( NULL );
}
}
bHandled = FALSE;
return NULL;
};
void Close()
{
m_spPicture = NULL;
}
//Attributes
CComPtr<IPicture> m_spPicture;
};
#endif // !defined(AFX_PICTUREWINDOW_H__44323373_9E89_11D3_A393_00C0DFC59237__INCLUDED_)
TenNen said:Anteros, I am coding to make a Win32 application from scratch, I amnot using MFC... I am still new to API, I have known about it for long but never tried to learn it,
I am actually trying to draw a clock, I think if I can use something as a background image, my application would look better, but I am stuck at it...
To insert a bitmap as a background image on a webpage, you can use the CSS background-image property. Here's an example of the code:
body { background-image: url("image.jpg");}
Yes, you can use any type of bitmap as a background image as long as it is supported by web browsers. Some common bitmap formats include JPEG, PNG, and GIF.
To make the background image cover the entire webpage, you can use the CSS background-size property. Set the value to "cover" and it will automatically resize the image to cover the entire webpage.
Yes, you can use multiple bitmaps as background images by using the CSS multiple background image syntax. Here's an example:
body { background-image: url("image1.jpg"), url("image2.jpg");}
You can use the CSS background-position property to position the background image on a specific part of the webpage. You can specify the position using keywords (e.g. top, bottom, left, right) or using pixel values.