Link to home
Start Free TrialLog in
Avatar of olli1973
olli1973

asked on

Convert OLE_HANDLE of a Bitmap to HBITMAP-Handle

Hi!
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);
   PatternBrush=CreatePatternBrush(hBitmap);
  }
     
  FillRect((HDC)pdc,rcBounds,PatternBrush);
 }


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

 OLE_HANDLE hBitmap=NULL;
 m_Picture.m_pPict->get_Handle(&hBitmap);
 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!
Olli.

Avatar of migel
migel

Hi!
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 :-)
Avatar of olli1973

ASKER

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...
Hi!
What error messages you get when use DrawPic sample?
ASKER CERTIFIED SOLUTION
Avatar of olli1973
olli1973

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 **