Convert OLE_HANDLE of a Bitmap to HBITMAP-Handle

olli1973 used Ask the Experts™
I´ve been on a long quest for answer til now (posted this question in round about 6 sites like this but got not a single reply!!) - so hopefully someone can help me here!
(And by the way - i don´t belive that my question is that difficult to answer...)

So what is my problem:
If got an ActiveX-Control where i implemented a Picture-Property. The bitmap is stored in a CPictureHolder (m_Picture). I want to create a Pattern-Brush from this to fill the background of the control.
So the problem is how to get a HBITMAP-handle for the CreatePatternBrush-function, because get_Handle returns only an OLE_HANDLE.
I´ve tried it this way:

 // CDrawPicCtrl::OnDraw - Drawing function

 void CDrawPicCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)

  static HBRUSH PatternBrush=NULL;

  if ((PatternBrush==NULL)&(PICTYPE_BITMAP == m_Picture.GetType()))
   HBITMAP hBitmap=NULL;
   m_Picture.m_pPict->get_Handle((OLE_HANDLE FAR *) &hBitmap);

This didn´t work so I also tried it this way:

 PatternBrush=CreatePatternBrush((HBRUSH) hBitmap);

Either way i tried i didnt´t get a valid HBITMAP-handle.

Please help!
I´m really desperate - can´t belive that i can´t make that sh... work!!!

I´m using VC++ 6 and Win98.
If you need more information please ask!

Thanks a lot!

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

try to create memory DC memory Bitmap and render that picture in that DC
I know that this sounds like a big hackaround but if nothing helps :-)


Hi migel!
Thanks for your comment!
But rendering the picture is not the problem.
Of course the problem of filling the background with a pattern of the bitmap could be solved by rendering the bitmap several times in a matrix, but that´s really a hackaround!
I cant´t belive that this is such a big problem!
My first try to solve the problem is an excerp from a VC code sample called "DrawPic" that i downloaded from MSDN.
This of course doesn´t work on my system and i don´t know why.
This is really making me mad - all i want is just getting a damned HBITMAP-handle...

As you see i increased the number of points to 1000 so perhaps this shows how mad i´m getting...

What error messages you get when use DrawPic sample?
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Found answer myself:

m_Picture.m_pPict->get_Handle((OLE_HANDLE FAR *) &hBitmap);
CBitmap * TempBmp = CBitmap::FromHandle(hBitmap);


Thanks migel!


Oh - Sorry - I´ve forgotten to mention that PatternBrush is a CBrush-type. With this type it worked.
Points refunded and moved to PAQ

** Mindphaser - Community Support Moderator **

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial