Solved

Drawing a Bitmap-Ressource into MainWindow

Posted on 1998-10-17
3
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Three Considerations for Containers

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read our article on Experts Exchange.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

632 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