Solved

Drawing a Bitmap-Ressource into MainWindow

Posted on 1998-10-17
3
246 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
iSeries FTP Exit Program 8 114
modThree challenge 4 64
twoTwo  challenge 35 86
Modbus - whats the maximum I can store in one register? 4 75
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now