Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Drawing a Bitmap-Ressource into MainWindow

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

670 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