Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using an image as backgrouond in my apps...

Status
Not open for further replies.

Calder2

Programmer
Jan 10, 2004
6
SE
Hi! I'm wondering how to use an image as a background in my database apps. How do I do that?
What if the image is bigger than the database window (thought I'd use one image for all windows, one size fits all)?

Have been looking at MSDN, but can only find how I use bitmaps for buttons, not background...
 
Hmm... I've only been using Visual C++ for DirectX stuff in games, and as such it's pretty easy using the code we've been given to import a bmp file, or even just bits of a bmp file and use them as individual objects.

I'm not sure how this could be used in a database app, but I don't think resolution matters. If the size of the image is bigger than the area, it'll extend past the area. But if you're making it automatically size the screen at, say, 800x600, and the image you're using is 1024x768, it'll only show the portion of the image it's able to. The rest just won't appear, at least in my experience.

If MSDN says how to use bitmaps as buttons, try adapting it. Create a big button object that can be used as the background, and simply don't apply any button commands to it. Probably the wrong way to do it, but it could work (and I wonder why I get bad grades...)
 
if your app is view based then in the view
void CTest01View::OnDraw(CDC* pDC)
{
CTest01Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

CRect rc;
GetClientRect (rc);

// Get a DC for the bitmap
CDC dcImage;
dcImage.CreateCompatibleDC (pDC);
CBitmap *pOldBitmap = dcImage.SelectObject (&m_bkground);

// Draw the bitmap as the window background
pDC->BitBlt (0, 0, rc.Width(), rc.Height(), &dcImage, 0, 0, SRCCOPY);

// Release
dcImage.SelectObject (pOldBitmap);
dcImage.DeleteDC ();
// TODO: add draw code for native data here
}
where m_bkground is a CBitmap loaded from the resources...
e.g. m_bkground.LoadBitmap(IDB_BITMAP1); do this in the constructor...
if your app is dialog based do this instead...add the function...
BOOL CSkinnedDlg::OnEraseBkgnd (CDC *pDC)
{
CRect rc;
GetClientRect (rc);

// Get a DC for the bitmap
CDC dcImage;
dcImage.CreateCompatibleDC (pDC);
CBitmap *pOldBitmap = dcImage.SelectObject (&m_bkground);

// Draw the bitmap as the window background
pDC->BitBlt (0, 0, rc.Width(), rc.Height(), &dcImage, 0, 0, SRCCOPY);

// Release
dcImage.SelectObject (pOldBitmap);
dcImage.DeleteDC ();

// Return value: Nonzero if it erases the background.
return TRUE;
}
in the *.h file add
afx_msg BOOL OnEraseBkgnd (CDC *pDC);
load your bitmap as before but do it in initinstance.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top