Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / December 2006

Tip: Looking for answers? Try searching our database.

How to get the correct hDC to fill in the DRAWITEMSTRUCT?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dotNeter - 12 Dec 2006 11:16 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.