tags:

views:

53

answers:

2

In my application i need to create HBITMAP objects to which I render and from where I copy the result.

I use the function "CreateDIBSection" to create these bitmaps, however this function required a DC (Device Context) as first parameter. Currently I get this by calling GetDC(hWnd) on the main windows handle (hWnd). But I would like to be able to create HBITMAPS without the requirement of having an application window, without some kind of in memory DC, Is this possible?

+1  A: 

CreateCompatibleDC(NULL) will create you a device context that is compatible with the screen - which sounds like it would be ideal in the situation.

Will A
+2  A: 

You can get one with CreateDC for the display:

 HDC hDc = CreateDC(L"DISPLAY", NULL, NULL, NULL);

Cleanup with DeleteDC(). It is only used to initialize the palette for bitmaps with indexed format. NULL might work if you don't use such a format, never tried it.

Then there's GDI+, #include <gdiplus.h> and the Bitmap class...

Hans Passant
Will this break if the user has multiple displays?
Billy ONeal
Could only affect the palette. Haven't seen a video adapter that could run in 8bpp mode for a *long* time. Good riddance.
Hans Passant