Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overlaying an image on a bitmap in a dialog

Status
Not open for further replies.

richsb

Technical User
Aug 2, 2001
34
NO
Hi,

Would appreciate guidance on the following.

I have a dialog onto which I have a picture control with a bitmap loaded into it that will display an image of a portion of the earth - ie a map in other words.

I would like to be able to display a smaller image over that map to represent yourself, and have that move around over the said map.

What will be the best method of approaching this.

Many thanks.


So much to do, so much to learn !
 
why don't you just draw the bitmaps to the dialog's HDC in the OnPaint() function instead of making the first bitmap an actual control?
If you need to handle clicks or something in the first bitmap, you can still do it by overriding the OnLButtonDown() etc. and examining if PtInRect() and so on.


 
Hi Buzznik,

I have used the bitmap control for the base image as I wish to update the control with different bitmaps via dll's, so this is a method that I know and am comfortable with. Would this still be able to happen with the method that you have suggested?

Cheers
richsb

So much to do, so much to learn !
 
yes, drawing a bitmap image direct to the device context is really easy - here's a function that you can use:

Code:
void DrawBitmap(HDC pDC,int x,int y,HBITMAP bmpBG)
{
    auto HBITMAP  oldBmp=(HBITMAP)::GetCurrentObject(pDC,OBJ_BITMAP);
    auto BITMAP    bm;  ::GetObject(bmpBG,sizeof(BITMAP),&bm);
    auto HDC        dcMem=::CreateCompatibleDC(pDC);

    ::SelectObject(dcMem,bmpBG);
    ::BitBlt(pDC,x,y,bm.bmWidth,bm.bmHeight,dcMem,0,0,SRCCOPY);
    ::SelectObject(dcMem,oldBmp);
    ::DeleteObject(dcMem);
}


If using MFC, use class wizard to add a handler in your dialog class for WM_PAINT messages - that will create a member function OnPaint() for you. Then, in the OnPaint() function, add the necessary code to draw your bitmap:

Code:
void MyDialog::OnPaint()
{
    CPaintDC       dc(this);

    auto HDC      pDC=::GetDC(m_hWnd);

    // load the bitmap from resource file...
    auto HBITMAP myBmp=(HBITMAP)::LoadBitmap(::AfxGetResourceHandle(),
              MAKEINTRESOURCE(IDB_MYBITMAPRESOURCEID));

    // draw the bitmap image 20 pixels in and 40 pixels down
    DrawBitmap(pDC,20,40,myBmp);

   // now delete the bitmap object to avoid memory leaks
   ::DeleteObject(myBmp);

   // don't forget to release the DC when done with it!!!!!
   ::ReleaseDC(m_hWnd,pDC);
}

To use bitmaps from DLLs (i'm assuming resources), simply pass the relevant module handle to the LoadBitmap() function as necessary.
 
That works fine, thanks.

Now, I take it, to overlay that base image with another to indicate my position all I need to do is call another function with a similar style and use the OnPaint function again ?

So much to do, so much to learn !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top