Results 1 to 8 of 8

Thread: BitBlt: Problem converting vb6 to vb.net

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Posts
    170

    BitBlt: Problem converting vb6 to vb.net

    this is the API call:
    Code:
    Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As IntPtr, _
     ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, _
     ByVal nHeight As Long, ByVal hSrcDC As IntPtr, ByVal xSrc As Long, _
     ByVal ySrc As Long, ByVal dwRop As Long) As Long
    
     Public Const SRCCOPY = &HCC0020
     Public Const SRCPAINT = &HEE0086
     Public Const SRCAND = &H8800C6
    which i need to find an equivelent for vb.net.

    Code:
    RetVal = BitBlt(Form1.Picture1.hDC, XVal_To, YVal_To, Width, Height, Form1.Picture1.hDC, XVal_From, YVal_From, SRCAND)
    as you may have guessed, the is Form1 , with Picture1 as a picture box in it.
    the property "hDC" in picture1.hDC is removed !!!!!!!!!!
    what can i do ???!
    well, i tried to use:

    Code:
    Dim HDC1 as IntPtr
    HDC1=Form1.DefInstance.Picture1.CreatGraphics.GethDC
    'bla bla bla
    is that way right ??
    if it is, y it is not working ???

    as i have noticed (although not sure of how accurate this notice is)
    the thing draw for a second and is erased immediates (probably after re-painting)
    well, that doesnot happen in vb6 !!!!!

    anyone can help ????
    Last edited by ZaidGS; Aug 20th, 2003 at 07:01 PM.

  2. #2
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536
    You might try converting all the Longs in Declare Function BitBlt to Integers and declare dwRop as System.Int32. I belive that .NET integers are the same as VB6 Longs. I'm guessing that maybe Longs are also different between .NET and 6.

    If that doesn't help, go out and buy ".NET Graphics and Printing" by Peter G. Aitken from Optimax, ISBN 1-931097-04-6. It's got a whole chapter on BitBlt.
    www.optimaxpublishinggroup.com
    This world is not my home. I'm just passing through.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Posts
    170
    thanks for considering....

    ok, i hav changed the api call to:
    Code:
        Private Declare Function BitBlt Lib "gdi32.dll" Alias "BitBlt" (ByVal _
           hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As _
           Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal _
           hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, _
           ByVal dwRop As System.Int32) As Long
    as it is found in one of the examples in msdn.

    still, did not work out :S

    would i be rude if i asked to provide for a link to a free tutorial
    site, if u would consider suggesting such a thing ??

    here is the example i found, if that would help at all:
    http://msdn.microsoft.com/library/en...iewingForm.asp
    Last edited by ZaidGS; Aug 20th, 2003 at 07:21 PM.

  4. #4
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Sorry, can't help any more

    I think I've told you everything I know on the subject.

    Maybe someone else can pick up from here?
    This world is not my home. I'm just passing through.

  5. #5
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    I don't know why you need to use BitBlt , perhaps, you aren't aware of .Net's graphics abilities.

    Open a new windows application, slap on a PictureBox And a button, open the code window, replace it with this code below...

    REPLACE the bolded lines with two images files you want to switch between...

    VB Code:
    1. Public Class Form1
    2.     Inherits System.Windows.Forms.Form
    3.     Private flip As Boolean = False
    4.     Private g As Graphics
    5.     Private c As New ImageList()
    6. +[Windows Form Designer generated code]
    7.  
    8.    
    9. ''replace the New sub in the windows form generated code with this one
    10.     Private Sub New()
    11.         MyBase.new()
    12.         InitializeComponent()
    13.         c.ImageSize = New Size(PictureBox1.Width, PictureBox1.Height)
    14.         c.Images.Add(Image.FromFile("[b]C:\documents and settings\Karl\Desktop\owned.bmp[/b]"))
    15.         c.Images.Add(Image.FromFile("[b]C:\documents and settings\Karl\Desktop\et.bmp[/b]"))
    16.         g = Graphics.FromHwnd(hwnd:=PictureBox1.Handle)
    17.     End Sub
    18. '''''''
    19.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    20.         If flip Then
    21.             g.DrawImage(c.Images(0), 0, 0)
    22.             flip = False
    23.         Else
    24.             g.DrawImage(c.Images(1), 0, 0)
    25.             flip = True
    26.         End If
    27.     End Sub
    28.  
    29.     Protected Overrides Sub Finalize()
    30.         g.Dispose()
    31.         MyBase.Finalize()
    32.     End Sub
    33. End Class
    Last edited by nemaroller; Aug 21st, 2003 at 07:33 PM.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Posts
    170

    things are starting to become clearer

    thanks nemaroller, your code helped me a lot.

    although it was not what i exactly wanted, but it
    helped me for a start

    what i did is similar to:
    translating:
    Code:
    RetVal = BitBlt(PictureBox1.hDC, XVal_To, YVal_To, Width, Height, PictureBox2.hDC, XVal_From, YVal_From, SRCCOPY)
    into:
    Code:
    Dim g as Graphics = PictureBox1.CreateGraphics
    Dim srcRect = New Rectangle(XVal_From, YVal_From, Width, Height)
    g.DrawImage(PictureBox2.Image, XVal_To, YVal_To, srcRect, GraphicsUnit.Pixel)
    i used the overloaded DrawImage so, that it suits the function of BitBlt, as it copies a portion of an image using its orignial size.
    (the code you made resizes the whole picture to fit into place)

    well, "copies".

    BitBlt has three flags, i have solved the first flag "SRCCOPY"

    im left helpless translating the flags "SRCAND" , "SRCPAINT"

    PLZZZZZZ, help
    at least a hint to the function i should use for these two flags.

    PS: i have this visual studio .net only two weeks ago, and im having bad time concerning new features

  7. #7
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    I guess it would be helpful if you could say what these operations are for? (Program purpose)

    BitBlit may not be supported in future Windows OS's since its an unmanaged resource, but then again, its seem to be so prevalent in programs, I couldn't possibly see Microsoft causing major incompatibilities by not including the gdi.dll somewhere. Staying with DrawImage will ensure your program runs on future OS's... windows or others.

    Anyway, I will investigate, but I'm not promising anything, I already have two other projects to work on...

    You might want to look at the CompositingMode setting of the graphics objects, includes two settings, SourceOVer , SourceCopy
    http://msdn.microsoft.com/library/de...cliptopic5.asp

    In the meantime, perhaps you can just stick with BlitBit...

    take a look here.. http://www.vbdotnetheaven.com/Code/Jul2003/2128.asp

    and here... http://www.vb-helper.com/howto_net_g...dow_image.html
    Last edited by nemaroller; Aug 22nd, 2003 at 09:53 AM.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Posts
    170
    well, i'd rather stick to VB.NET graphics stuff, not bitblt,
    because bitblt is not working with me at all !!!
    although it did in vb6, which is a strange problem.

    but, as i said bitblt has three flags:
    (1)SRCCOPY: which copies an exact portion from one place to another.
    (2)SRCPAINT: which paints OVER current image, which means that
    painting red over yellow gives orange, painting black over anything gives black
    and painting white over anything dont make any change.
    (3)SRCAND: which makes AND operation on the color, ie.
    orange && red = red , because orange and red has red in common
    (orange is (red OR yellow) )
    and produces no difference for black, and paints white when one
    of the two colors is white !!

    i need these functions for drawing a chess board:
    u kno, using a black mask, and paint the piece over
    the mask.
    so i need to use the three flags.
    Last edited by ZaidGS; Aug 22nd, 2003 at 01:54 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width