Results 1 to 1 of 1

Thread: Something's wrong with GDI API in VB6

  1. #1
    Hyperactive Member
    Join Date
    Oct 08
    Posts
    272

    Something's wrong with GDI API in VB6

    Ok so I made a class (.cls file) for handling graphics. Here's the declarations in my class.

    Code:
    Private Declare Function GetDIBits Lib "GDI32.dll" ( _
        ByVal hDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, _
        ByVal nNumScans As Long, ByRef lpBits As Any, _
        ByRef lpBI As BitmapInfo, ByVal wUsage As Long) As Long
    Private Declare Function SetDIBits Lib "GDI32.dll" ( _
        ByVal hDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, _
        ByVal nNumScans As Long, ByRef lpBits As Any, _
        ByRef lpBI As BitmapInfo, ByVal wUsage As Long) As Long
     
    Private Type BitmapInfoHeader
        biSize As Long
        biWidth As Long
        biHeight As Long
        biPlanes As Integer
        biBitCount As Integer
        biCompression As Long
        biSizeImage As Long
        biXPelsPerMeter As Long
        biYPelsPerMeter As Long
        biClrUsed As Long
        biClrImportant As Long
    End Type
    
    Private Type BitmapInfo
        bmiHeader As BitmapInfoHeader
        bmiColors(255) As Long
    End Type
    
    Dim DIBinfo As BitmapInfo
    
    Dim MyPic As PictureBox


    Here's the functions in the class that are having a problem

    Code:
    Public Property Set PictBox(ByRef PicBox As PictureBox)
    Set MyPic = PicBox
    End Property
    
    
    Public Sub GetPixels()
    DIBinfo.bmiHeader.biSize = Len(DIBinfo.bmiHeader)
    GetDIBits MyPic.hDC, MyPic.Image, 0, 0, ByVal 0&, DIBinfo, 0
    MsgBox Dibinfo.bmiHeader.biWidth
    MsgBox Dibinfo.bmiHeader.biHeight
    End Sub

    Now the initial size of my Picture1 picture box is 256x224.
    Now the code I'm using in my form in the command button's "click" event, to test my API functions is

    Code:
    Dim BM As New Bitmap 'Bitmap is the name of my class
    
    Set BM.PictBox = Picture1
    BM.GetPixels
     'The first MsgBox shows "256" and the second one shows "224"
    
    Picture1.Height=80
    Set BM.PictBox = Picture1
    BM.GetPixels
     'As expected, the GDI API correctly reads the new smaller size of Picture1 and the first MsgBox shows "256" and the second one shows "80"
    
    
    Picture1.Height=224
    Set BM.PictBox = Picture1
    BM.GetPixels
     'Now the unexpected happens.
     'The GDI API INCORRECTLY reads the new larger size of Picture1 and as a result it "thinks" that the height hasn't changed,
     'so while the first MsgBox shows "256", second one INCORRECTLY still shows "80"
    What is going on? Please help. Am I just overlooking something very obvious and easy to correct here?
    Last edited by Ben321; Jul 31st, 2012 at 12:10 AM.

Posting Permissions

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