For some reason, I have to manually raise the WM_DRAMITEM when drew a
ListBox, but I got a problem that I couldn't get the correct hdc.
See definition of DRAWITEMSTRUCT. It has a field hDC, the description
is,
HDC hDC;
Handle to a device context; this device context must be used when
performing drawing operations on the control.
I assigned the ListBox control hdc to it, but I got the OutOfMemory
error.
Btw, I sent this msg when I caught WM_WINDOWPOSCHANGING, so I believe
it wouldn't generate the infinite loop.
The thing I didn't understand is which DC I should assign to the msg.
And it looks like there is no way to just get the DC of certain item.
But a WM_DRAWITEM corresponds to an item.
Who can tell me how to do it?
Thx in advance.
Jeff Gaines - 12 Dec 2006 11:52 GMT
On 12/12/2006 in message
>For some reason, I have to manually raise the WM_DRAMITEM when drew a
>ListBox, but I got a problem that I couldn't get the correct hdc.
[quoted text clipped - 16 lines]
>Who can tell me how to do it?
>Thx in advance.
Is this an Owner Draw ListBox?
You can get the HDC:
Graphics gfx = lstBox.CreateGraphics();
IntPtr hdc = gfx.GetHdc();
You *must* dispose the hdc and the Graphics when you have finished:
gfx.ReleaseHdc(hdc);
gfx.Dispose();
If you give us a little more information about what you are drawing, with
the code, there may be a better way of doing it.

Signature
Jeff Gaines
Damerham Hampshire UK