GetDC from Bitmap via API (for double buffered controls under CF)

B

Benjamin Lukner

Hi!

When using the Full Framework, it's quite easy to get the handle of a
bitmap object:

Private _bmp As System.Drawing.Bitmap
Private _graphics As System.Drawing.Graphics

_bmp = New System.Drawing.Bitmap(100, 100)
_graphics = Graphics.FromImage(_bmp)

Dim hDC As IntPtr

hDC = _graphics.GetHdc
'[...]
_graphics.ReleaseHdc(hDC)


But in Compact Framework GetHdc and ReleaseHdc aren't implemented.
I can use the following code to get the handle of a control:


Me.Capture = True
hWnd = GetCapture
Me.Capture = False

hDC = GetDC(hWnd)
'[...]
ReleaseDC(hWnd, hDC)


But my custom control is double buffered. So I have to get the device
context of my bitmap, not from the control it's painted on.
Does anyone know how to do it?


Kind regards,

Benjamin Lukner
 
A

Alex Yakhnin

As Peter's already suggested to you earlier, take a look at the GraphicsEx
lib in the SDF.
 
B

Benjamin Lukner

Alex Yakhnin said:
As Peter's already suggested to you earlier, take a look at the GraphicsEx
lib in the SDF.

I already had a closer look ;-)

But I've only found code for getting access to a control, not to a bitmap.
Could you give me another hint?


Kind regards,

Benjamin Lukner
 
A

Alex Yakhnin

Benjamin,

You will not be able to get access to the offscreen native graphics handles.
The only way to do any double buffering with the native drawing is to do
everything by yourself, i.e.
get HDC, create compatible DC/ BITMAP, SelectObject etc...
 
Top