BitBlt in MFC - can someone assist please? 
Author Message
 BitBlt in MFC - can someone assist please?

Folks,
I have got the BitBlt to work in a non-MFC prog using HDCs but can't get an
MFC version to work.
I think it's the SelectObject that is thr problem. Coded as below I get an
Access violation and when I code it as
    CBitmap* pOldBitmap = srcDC.SelectObject((CBitmap *)&pBitmap);
/* this works */
      it "works" but I get 0 in pOldBitmap. Obviously there is an
incompatibility with the   way I'm using
LoadImage???

 CBitmap  * pBitmap;
 CBitmap  cBitmap;
 BITMAP  bm;
 int   ret;
 bool  bret;
LPCTSTR lpszImg = "D:\\Chip16.bmp";
pBitmap = (CBitmap *)LoadImage (0, lpszImg, IMAGE_BITMAP, 0, 0,
LR_CREATEDIBSECTION | LR_LOADFROMFILE | LR_DEFAULTSIZE );

// create an in-memory DC
 CDC srcDC;
       int inta = srcDC.CreateCompatibleDC(pDC);
// select bitmap into in-memory DC
    CBitmap* pOldBitmap = srcDC.SelectObject((CBitmap *)pBitmap);
/* this fails */
      int intb = GetObject(pBitmap,  sizeof(BITMAP), &bm );
//      CBitmap* pOldBitmap = dc.SelectObject((CBitmap* )&pBitmap);

  ret = pDC->BitBlt( 50, 30, bm.bmWidth, bm.bmHeight,
             &srcDC, 0, 0, BLACKNESS );
//  bret = dc.BitBlt( 10, 50, bm.bmWidth, bm.bmHeight,
//   &srcDC, 0, 0, SRCCOPY );

//       (CBitmap *)srcDC.SelectObject(pOldBitmap);

TIA
--

Ian Turnbull
0961 931941

Web  : www.turnbui.freeserve.co.uk



Fri, 26 Sep 2003 01:10:25 GMT  
 BitBlt in MFC - can someone assist please?
LoadImage() does not return a CBitmap type object. Take a look at
CBitmap::FromHandle();



Quote:
> Folks,
> I have got the BitBlt to work in a non-MFC prog using HDCs but can't get
an
> MFC version to work.
> I think it's the SelectObject that is thr problem. Coded as below I get an
> Access violation and when I code it as
>     CBitmap* pOldBitmap = srcDC.SelectObject((CBitmap *)&pBitmap);
> /* this works */
>       it "works" but I get 0 in pOldBitmap. Obviously there is an
> incompatibility with the   way I'm using
> LoadImage???

>  CBitmap  * pBitmap;
>  CBitmap  cBitmap;
>  BITMAP  bm;
>  int   ret;
>  bool  bret;
> LPCTSTR lpszImg = "D:\\Chip16.bmp";
> pBitmap = (CBitmap *)LoadImage (0, lpszImg, IMAGE_BITMAP, 0, 0,
> LR_CREATEDIBSECTION | LR_LOADFROMFILE | LR_DEFAULTSIZE );

> // create an in-memory DC
>  CDC srcDC;
>        int inta = srcDC.CreateCompatibleDC(pDC);
> // select bitmap into in-memory DC
>     CBitmap* pOldBitmap = srcDC.SelectObject((CBitmap *)pBitmap);
> /* this fails */
>       int intb = GetObject(pBitmap,  sizeof(BITMAP), &bm );
> //      CBitmap* pOldBitmap = dc.SelectObject((CBitmap* )&pBitmap);

>   ret = pDC->BitBlt( 50, 30, bm.bmWidth, bm.bmHeight,
>              &srcDC, 0, 0, BLACKNESS );
> //  bret = dc.BitBlt( 10, 50, bm.bmWidth, bm.bmHeight,
> //   &srcDC, 0, 0, SRCCOPY );

> //       (CBitmap *)srcDC.SelectObject(pOldBitmap);

> TIA
> --

> Ian Turnbull
> 0961 931941

> Web  : www.turnbui.freeserve.co.uk



Fri, 26 Sep 2003 04:17:14 GMT  
 BitBlt in MFC - can someone assist please?
Graphics is not my specialty and the one CodeGuru article I have is the
result of my learning. It might be enough to help you here though. See:

http://www.codeguru.com/bitmap/SimpleBMPViewer.shtml



Quote:
> Folks,
> I have got the BitBlt to work in a non-MFC prog using HDCs but can't get
an
> MFC version to work.
> I think it's the SelectObject that is thr problem. Coded as below I get an
> Access violation and when I code it as
>     CBitmap* pOldBitmap = srcDC.SelectObject((CBitmap *)&pBitmap);
> /* this works */
>       it "works" but I get 0 in pOldBitmap. Obviously there is an
> incompatibility with the   way I'm using
> LoadImage???

>  CBitmap  * pBitmap;
>  CBitmap  cBitmap;
>  BITMAP  bm;
>  int   ret;
>  bool  bret;
> LPCTSTR lpszImg = "D:\\Chip16.bmp";
> pBitmap = (CBitmap *)LoadImage (0, lpszImg, IMAGE_BITMAP, 0, 0,
> LR_CREATEDIBSECTION | LR_LOADFROMFILE | LR_DEFAULTSIZE );

> // create an in-memory DC
>  CDC srcDC;
>        int inta = srcDC.CreateCompatibleDC(pDC);
> // select bitmap into in-memory DC
>     CBitmap* pOldBitmap = srcDC.SelectObject((CBitmap *)pBitmap);
> /* this fails */
>       int intb = GetObject(pBitmap,  sizeof(BITMAP), &bm );
> //      CBitmap* pOldBitmap = dc.SelectObject((CBitmap* )&pBitmap);

>   ret = pDC->BitBlt( 50, 30, bm.bmWidth, bm.bmHeight,
>              &srcDC, 0, 0, BLACKNESS );
> //  bret = dc.BitBlt( 10, 50, bm.bmWidth, bm.bmHeight,
> //   &srcDC, 0, 0, SRCCOPY );

> //       (CBitmap *)srcDC.SelectObject(pOldBitmap);

> TIA
> --

> Ian Turnbull
> 0961 931941

> Web  : www.turnbui.freeserve.co.uk



Fri, 26 Sep 2003 01:40:58 GMT  
 BitBlt in MFC - can someone assist please?
Ian,

LoadImage returns a handle to a system resource - not a pointer to a bitmap.
You can get a pointer to a temporary CBitMap object given a handle to a
system gdi bitmap using the static FromHandle method of CBitMap, and passing
the system gdi bitmap handle to the CBitMap method.  See the MSDN help on
this method -- the CBitMap pointer is a temp pointer, and is valid only
until the next time the trash is taken out.  You are however, guaranteed
that it will be valid for the duration of the current/any single windows
message - the WM_PAINT for instance.

I have carved and sanitized a snip from one of our programs that uses the
LoadImage method to get to a CBitMap reference that is then passed to the
CDC::SelectObject method...

best regards
roy fine

//
//
// --------------------------------------------------------------
void CSplashWnd::OnPaint(){
CPaintDC dc(this);

CDC dcImage;
if (!dcImage.CreateCompatibleDC(&dc)) return;
HBITMAP  hndImage =
(HBITMAP)::LoadImage(NULL,strIPath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);

m_bitmap = CBitmap::FromHandle( hndImage);
BITMAP bm;
m_bitmap->GetBitmap(&bm);

 // Paint the image.
CBitmap* pOldBitmap = dcImage.SelectObject(m_bitmap);
dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
dcImage.SelectObject(pOldBitmap);

Quote:
}



Quote:
> Folks,
> I have got the BitBlt to work in a non-MFC prog using HDCs but can't get
an
> MFC version to work.
> I think it's the SelectObject that is thr problem. Coded as below I get an
> Access violation and when I code it as
>     CBitmap* pOldBitmap = srcDC.SelectObject((CBitmap *)&pBitmap);
> /* this works */
>       it "works" but I get 0 in pOldBitmap. Obviously there is an
> incompatibility with the   way I'm using
> LoadImage???

>  CBitmap  * pBitmap;
>  CBitmap  cBitmap;
>  BITMAP  bm;
>  int   ret;
>  bool  bret;
> LPCTSTR lpszImg = "D:\\Chip16.bmp";
> pBitmap = (CBitmap *)LoadImage (0, lpszImg, IMAGE_BITMAP, 0, 0,
> LR_CREATEDIBSECTION | LR_LOADFROMFILE | LR_DEFAULTSIZE );

> // create an in-memory DC
>  CDC srcDC;
>        int inta = srcDC.CreateCompatibleDC(pDC);
> // select bitmap into in-memory DC
>     CBitmap* pOldBitmap = srcDC.SelectObject((CBitmap *)pBitmap);
> /* this fails */
>       int intb = GetObject(pBitmap,  sizeof(BITMAP), &bm );
> //      CBitmap* pOldBitmap = dc.SelectObject((CBitmap* )&pBitmap);

>   ret = pDC->BitBlt( 50, 30, bm.bmWidth, bm.bmHeight,
>              &srcDC, 0, 0, BLACKNESS );
> //  bret = dc.BitBlt( 10, 50, bm.bmWidth, bm.bmHeight,
> //   &srcDC, 0, 0, SRCCOPY );

> //       (CBitmap *)srcDC.SelectObject(pOldBitmap);

> TIA
> --

> Ian Turnbull
> 0961 931941

> Web  : www.turnbui.freeserve.co.uk



Fri, 26 Sep 2003 02:11:26 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. MFC Beginner Question: CDC::BitBlt vs. Win32 BitBlt

2. Please Assist Student programming C

3. Function Pointer Problem--Please Assist

4. Experienced VC++ programmers, please assist VB guy lookin to learn C++

5. Experienced VC++ programmers, please assist VB guy lookin to learn C++

6. Starting a dialog minimized: please assist.

7. Could you help me please?(bitblt)

8. BitBlt on a printer DC, Please Help.

9. BitBlt problem w/Win98 and MFC?

10. BitBlt and MFC

11. Could someone build me this sample, please?

12. Can someone look at this code?please.

 

 
Powered by phpBB® Forum Software