API IN VB.NET?

api in vb6.0 ok..
api in vb.net ???

Comments

  • : api in vb6.0 ok..
    : api in vb.net ???
    :
    Even you changed OS, the API is still the same. I went from Windows ME (Moron Edition) to XP Pro. No trouble. Just remember to convert all Integers to Short, and all Long to Integers. Also, a problem I haven't solved yet. The new GDI+ (Maybe XP specific) handles all hDC functions.

    John Emler


  • : : api in vb6.0 ok..
    : : api in vb.net ???
    : :
    : Even you changed OS, the API is still the same. I went from Windows ME (Moron Edition) to XP Pro. No trouble. Just remember to convert all Integers to Short, and all Long to Integers. Also, a problem I haven't solved yet. The new GDI+ (Maybe XP specific) handles all hDC functions.
    :
    : John Emler
    :
    :
    :

    The API support for VB.NET is enhanced. Subclassing is easier because all controls contain a windows procedure that you can override.

    Protected Overrides Sub WndProc( _
    ByRef m As System.Windows.Forms.Message)

    ' Windows API notification messages intercepted here
    End Sub

    Even though many controls, such as the PictureBox lack a device context, you can still use api functions on them. There is a round about way to get a picture boxes device context. Below is a routine that copies an image from one PictureBox to another PictureBox, using the api BitBlt function.

    Private Declare Function BitBlt Lib "gdi32" Alias "BitBlt" ( _
    ByVal hDestDC As Integer, _
    ByVal x As Integer, _
    ByVal y As Integer, _
    ByVal nWidth As Integer, _
    ByVal nHeight As Integer, _
    ByVal hSrcDC As Integer, _
    ByVal xSrc As Integer, _
    ByVal ySrc As Integer, _
    ByVal dwRop As Integer) As Integer

    Private Const SRCCOPY = &HCC0020

    ...

    Sub CopyImage(ByVal src As PictureBox, ByVal des As PictureBox)

    ' Get device context of source and destination picture boxes
    Dim srcHDC As IntPtr = src.CreateGraphics.GetHdc
    Dim desHDC As IntPtr = des.CreateGraphics.GetHdc

    ' Use api function
    BitBlt(desHDC.ToInt32, 0, 0, picSrc.Width, _
    picSrc.Height, srcHDC.ToInt32, 0, 0, SRCCOPY)

    End Sub

    The trick is to call the GetHdc method of a Graphics object, which can easily be returned by the picture boxes CreateGraphics method. The GetHdc object returns a limited version of a pointer (IntPtr), which can be used by VB.NET. To get the actual device context handle, you must call the ToInt32 method of the IntPtr data type. I experimented with this technique and sucessfully copied a jpeg image from one picture box to another. Below is how you basically use the routine

    Private Sub btnCopy_Click( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnCopy.Click

    ' Assuming that picSrc picturebox has a preloaded image
    Call CopyImage(picSrc, picDes)
    End Sub

    Personally most of the api is alleviated by .NET. For instance it is really not necessary to tap into the gdi api considering GDI+ does most of the work by providing the pens, brushes, and image handling. Also, many properties in the Environment object replace the need to tap into the api as well.








Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories