Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Drawing a Bitmap-Ressource into MainWindow

Posted on 1998-10-17
3
Medium Priority
?
288 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 240 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
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.
Suggested Courses

916 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