Author Topic: Device Context Handle  (Read 2575 times)

0 Members and 1 Guest are viewing this topic.

Draftek

  • Guest
Device Context Handle
« on: January 10, 2006, 05:07:29 PM »
I'm writing an activex dll that accepts a drawing file or url and returns a Bitmap handle so I can populate a listview control with various drawing previews of my choice.

The problem is, in order to use the win32 api function: CreateCompatibleBitmap() I need the hDc of some graphics containing object which my dll does not contain.

I see two options since I can't figure out how to push NULL in VB:
1. I create an object in code and create a new hdc like this:
Code: [Select]
Private hDc As Long
Private oPic As Picture
Private Sub Class_Initialize()
    Set oPic = New StdPicture
    hdc = GetDC(oPic.Handle)
End Sub

or change my mind and just make a simple usercontrol that I only want to get the hDc with the hDc built in.

Is there anything wrong with option number 1?

Draftek

  • Guest
Re: Device Context Handle
« Reply #1 on: January 11, 2006, 08:03:31 AM »
*pin drop in the back leaves deafening sound....*

Draftek

  • Guest
Re: Device Context Handle
« Reply #2 on: January 11, 2006, 08:46:04 AM »
okay, one Ramification of option number 1 just occured to me:

If the com class is destroyed before the calling app uses the handle to create the bitmap then I guess that should cause an exception since the pointer is gone.

So, what about forcing the calling app to pass an hDc for use?

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Device Context Handle
« Reply #3 on: January 11, 2006, 08:47:29 AM »
*pin drop in the back leaves deafening sound....*
I'm still on my first cup of coffee, so that pin drop was really loud
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)