Solved

Drawing a Bitmap-Ressource into MainWindow

Posted on 1998-10-17
3
269 Views
Last Modified: 2013-11-20
I have a Bitmap ressource... and I'm looking for a way to use it as the background for the main window, which should be scaled to the bitmap's size...

Most likely a silly question, but I'm working on the Mac primarily which has quite different ways to do suh stuff.
0
Comment
Question by:busse
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 60 total points
ID: 1323484
Add bitmap to Visual C as a resource.  It will be called something like IDB_BITMAP1 in the resource tab in Dev Studio

Override the OnDraw function, and add code inside:


// prepare to draw
HBITMAP hBitmap = ::LoadBitmap( AfxGetInstanceHandle(), IDB_BITMAP1 ) ;
HDC hDC = ::CreateCompatibleDC( pDC->m_hDC ) ;
::SelectObject( hDC, hBitmap ) ;

// get bitmap size
GetObject( hBitmap, sizeof bm, &bm ) ;

// get screen size
CRect rect ;
GetClientRect( &rect ) ;

// draw bitmap with scaling
StretchBlt( pdc->m_hDC, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, hDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY ) ;

// clean up
DeleteDC( hDC ) ;
DeleteObject( hBitmap ) ;
0
 

Author Comment

by:busse
ID: 1323485
This solves my problem for the moment... the only remaining thing  I would like to know is how to adapt the Window to the Bitmap size instead of the other way 'raound?

BTW: I'm not working with Visual Studio, but with CodeWarrior
;-)
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1323486
Something like this:

// get bitmap size
BITMAP bm ;
HBITMAP hBitmap = ::LoadBitmap( AfxGetInstanceHandle(), IDB_BITMAP1 ) ;
GetObject( hBitmap, sizeof bm, &bm ) ;
DeleteObject( hBitmap ) ;
// Calculate required size
CRect rect ;
rect.left = 0 ;
rect.top = 0 ;
rect.right = bm.bmWidth ;
rect.bottom = bm.bmHeight ;
AdjustWindowRect( &rect, style, bMenu ) ;

set style to the window style of the required window to size.  if an SDI app you can use
DWORD style = (DWORD)::GetWindowLong( AfxGetMainWnd()->m_hWnd, GWL_STYLE ) ;

set bMenu to TRUE or FALSE depending on if the window has a menu or not

Then size the window, e.g. for SDI app

AfxGetMainWnd()->MoveWindow( &rect ) ;

For an MDI app - you need to size the view (class deriving from CView) instead of the frame.  Replace references to AfxGetMainWnd() with a pointer to the view, or remove if doing it inside the view class.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
java ^ examples 8 69
Window placement 17 85
Annoying "thing" blocks my view 4 113
unix example issues 18 98
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question