1

The problem I face is the fact that it is not possible to draw to one hdc from multiple threads simultaneously. I have found out that it is possible to create a bitmap, lock it for the write access and get the pointer to the bitmap data in memory. This thread is about this topic, however I struggle with implementing all this.

My first question is: if I want to get this pointer to the data, does it matter how the bitmap was created (CreateCimpatibleDC() or CreateDIBitmap())?

The second question is: how to get that pointer? In this thread it is received from the CreateDIBSection() function.

Could anyone provide me with the tiny example how to access the data using the pointer please? Thanks in advance.

Community
  • 1
  • 1
pro100tom
  • 165
  • 1
  • 10
  • [this](http://stackoverflow.com/questions/21937095/creating-a-hbitmap-from-an-existing-buffer/21941601#21941601) might help you – γηράσκω δ' αεί πολλά διδασκόμε Dec 12 '14 at 03:09
  • Thank you for the link. However I struggle with the "data" variable. Which type should it be so that I could draw a pixel on the bitmap? Another question: if I "talk" directly with memory, I probably don't need to run BeginPaint and EndPaint, right? – pro100tom Dec 12 '14 at 22:42
  • You create an *hBitmap* in memory but your drawings involve *dc's*. It is the way GDI works. You can't draw an *hBitmap*, only *dc's*. This *hdc* is what you *bitblt()* into the *hdc* you get from *BeginPaint*. So you need it. You can't get a pointer from the control *hdc* unfortunatelly. – γηράσκω δ' αεί πολλά διδασκόμε Dec 13 '14 at 14:56
  • *...I struggle with the "data" variable*. If the *hBitmap* is 24bit, to set a pixel color eg the first one(blue): `data[0] = 255; data[1] = 0; data[2] = 0'. The colors are BGR BGR ... I am not sure however if the first pixel in *data* array is the *top-left* or *bottom-right* of the bitmap. You need to experiment a little. – γηράσκω δ' αεί πολλά διδασκόμε Dec 13 '14 at 15:01

0 Answers0