Archived

This topic is now archived and is closed to further replies.

vbisme

VB device context

Recommended Posts

I''ve been programming C/C++ for awhile but then I''m about to get a job that deals with VB animation and such. I was wondering how do you declare a Device Context in VB? In C/C++ it usually just: hDC mydc; what about Visual Basic?

Share this post


Link to post
Share on other sites
If it is a handle to a device context you are after, then it is just a long. A device context and a handle to a device context are very different though. But I''m pretty sure that what you are looking for is a handle, since I don''t think you can just declare a DC like that.

Share this post


Link to post
Share on other sites
ragonastick- even though your post was correct, t didn''t really help much, did it?

To answer your question, if you want to get a device context, you have to create the device manually by dragging the correct control for it onto your form, then you can se object.hDC. For example Me.hDC, Form1.hDC, PictureBox1.hDC.

On the other hand, if you just want to store a handle to an arbitrary context, then you can declare a long, to hold it. For example, Dim MyDeviceContext as Long; Now you can use MyDeviceContext = FunctionThatReturnsDC().

Share this post


Link to post
Share on other sites
ragonastick- even though your post was correct, t didn''t really help much, did it?

To answer your question, if you want to get a device context, you have to create the device manually by dragging the correct control for it onto your form, then you can se object.hDC. For example Me.hDC, Form1.hDC, PictureBox1.hDC.

On the other hand, if you just want to store a handle to an arbitrary context, then you can declare a long, to hold it. For example, Dim MyDeviceContext as Long; Now you can use MyDeviceContext = FunctionThatReturnsDC().

Share this post


Link to post
Share on other sites
I don''t think you properly understand a device context. A long does not hold a device context, it can hold a handle to it.

quote:
To answer your question, if you want to get a device context, you have to create the device manually by dragging the correct control for it onto your form, then you can se object.hDC. For example Me.hDC, Form1.hDC, PictureBox1.hDC.



Dragging a control onto the form, will create a device context, but it will also have the overhead of the picture box, which is why doing such a thing should not be used. The small h in "hDC" stands for handle, so that property of the control is not actually the DC, but it is the handle to the objects DC.

Seeing as vbisme has a C/C++ background, I''m sure he would be familiar with how to create a DC correctly.

Share this post


Link to post
Share on other sites