CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2009
    Posts
    1,355

    how use UDT(User Defined Types) on a class?

    i created a class:
    Code:
    Option Explicit
    
    Private GDIsi As GDIPlusStartupInput, gToken As Long, hGraphics As Long, hBitmap As Long
    
    
    Private Type POINTL
        X As Long
        Y As Long
    End Type
    
    
    Public X As Long
    Public Y As Long
    Public Z As Long
    Public ImageHeight As Long
    Public ImageWidth As Long
    
    
    Private Pi As Double
    
    
    Private Sub Class_Initialize()
        Pi = 4 * Atn(1)
        X = 0
        Y = 0
        Z = 0
        
        GDIsi.GDIPlusVersion = 1&
        GdiplusStartup gToken, GDIsi
        If Err Then
              Err.Clear
              Exit Sub
        ElseIf gToken = 0& Then
             Exit Sub
        End If
        On Error GoTo 0
        Call GdipCreateFromHWND(GetActiveWindow(), hGraphics)
    End Sub
    
    
    Private Sub Class_Terminate()
        If hBitmap Then
            GdipDisposeImage hBitmap
        End If
        GdipDeleteGraphics hGraphics
    End Sub
    
    
    Public Sub FromImageFile(ByVal FileName As String)
        Call GdipGraphicsClear(hGraphics, &HFFFF0000)
        Call GdipLoadImageFromFile(StrPtr(FileName), hBitmap)
    End Sub
    
    
    Friend Sub DrawImage(DestinationHDC As Long, PositionX As Long, PositionY As Long)
        GdipDrawImage hGraphics, hBitmap, PositionX, PositionY
    End Sub
    
    
    'edit:
    Public Sub DrawImageTrapezoid(ByRef Points As POINTL, ByVal DestinationHDC As Long, ByVal TranspColor As Long)
        Dim ScanLines As Long
        Dim FullWidth As Long
        Dim ScanWidth As Single
        Dim ScanLeft As Single
        Dim Delta As Single
        Dim sbmOrig As StretchBltModes
        Dim ScanLine As Long
        Dim ScanZ As Single
        Dim ScanZDec As Single
        
        'Points(0) - UpperLeft
        'Points(1) - UpperRight
        'Points(2) - LowRight
        'Points(3) - LowLeft
        Dim PctTop As Long
        PctTop = Points(2).X - Points(3).X
        
        ScanLines = ImageHeight
        FullWidth = ImageWidth
        
        ScanWidth = ImageWidth * PctTop / 100
        ScanLeft = (ImageWidth - ScanWidth) / 2
        
        Delta = ScanLeft / ScanLines
        
        
        sbmOrig = SetStretchBltMode(DestinationHDC, HALFTONE)
        ScanZ = 1 + (PctTop / 100)
        ScanZDec = ((PctTop / 100)) / ScanLines
        
        For ScanLine = 0 To ScanLines - 1
            StretchBlt DestinationHDC, _
                       ScanLeft + Points(0).X, _
                       ScanLine + Points(0).Y, _
                       ScanWidth, _
                       1, _
                       hGraphics, _
                       0, _
                       ScanLine * ScanZ, _
                       FullWidth, _
                       1
            ScanLeft = ScanLeft - Delta
            ScanWidth = ScanWidth + 2 * Delta
            ScanZ = ScanZ - ScanZDec
        Next
        SetStretchBltMode DestinationHDC, sbmOrig
        
    End Sub
    on method\sub DrawImageTrapezoid() i use a parameter with a UDT: 'POINTL'.
    when i compile it i get an error that i can't use that type... if i do a sub 'friend', i will get a 'byref' error
    Code:
    Dim img As New Image
    Dim s(4) As POINTL
    img.DrawImageTrapezoid s, Me.hdc, -1

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: how use UDT(User Defined Types) on a class?

    What was the actual error message that you received?

    The code you have shown looks like you are trying to pass an array of PointL but the sub is looking for a single PointL. This will not work with or without it being a UDT.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Apr 2009
    Posts
    1,355

    Re: how use UDT(User Defined Types) on a class?

    heres the error message:
    https://imgur.com/a/hOjFifj
    and now the 'array parentheses':
    Code:
    Option Explicit
    
    Private GDIsi As GDIPlusStartupInput, gToken As Long, hGraphics As Long, hBitmap As Long
    
    
    
    
    Private Type POINTL
        X As Long
        Y As Long
    End Type
    
    
    
    
    Public X As Long
    Public Y As Long
    Public Z As Long
    Public ImageHeight As Long
    Public ImageWidth As Long
    
    
    
    
    Private Pi As Double
    
    
    
    
    Private Sub Class_Initialize()
        Pi = 4 * Atn(1)
        X = 0
        Y = 0
        Z = 0
        
        GDIsi.GDIPlusVersion = 1&
        GdiplusStartup gToken, GDIsi
        If Err Then
              Err.Clear
              Exit Sub
        ElseIf gToken = 0& Then
             Exit Sub
        End If
        On Error GoTo 0
        Call GdipCreateFromHWND(GetActiveWindow(), hGraphics)
    End Sub
    
    
    
    
    Private Sub Class_Terminate()
        If hBitmap Then
            GdipDisposeImage hBitmap
        End If
        GdipDeleteGraphics hGraphics
    End Sub
    
    
    
    
    Public Sub FromImageFile(ByVal FileName As String)
        Call GdipGraphicsClear(hGraphics, &HFFFF0000)
        Call GdipLoadImageFromFile(StrPtr(FileName), hBitmap)
    End Sub
    
    
    
    
    Friend Sub DrawImage(DestinationHDC As Long, PositionX As Long, PositionY As Long)
        GdipDrawImage hGraphics, hBitmap, PositionX, PositionY
    End Sub
    
    
    
    
    'edit:
    Public Sub DrawImageTrapezoid(ByRef Points() As POINTL, ByVal DestinationHDC As Long, ByVal TranspColor As Long)
        Dim ScanLines As Long
        Dim FullWidth As Long
        Dim ScanWidth As Single
        Dim ScanLeft As Single
        Dim Delta As Single
        Dim sbmOrig As StretchBltModes
        Dim ScanLine As Long
        Dim ScanZ As Single
        Dim ScanZDec As Single
        
        'Points(0) - UpperLeft
        'Points(1) - UpperRight
        'Points(2) - LowRight
        'Points(3) - LowLeft
        Dim PctTop As Long
        PctTop = Points(2).X - Points(3).X
        
        ScanLines = ImageHeight
        FullWidth = ImageWidth
        
        ScanWidth = ImageWidth * PctTop / 100
        ScanLeft = (ImageWidth - ScanWidth) / 2
        
        Delta = ScanLeft / ScanLines
        
        
        sbmOrig = SetStretchBltMode(DestinationHDC, HALFTONE)
        ScanZ = 1 + (PctTop / 100)
        ScanZDec = ((PctTop / 100)) / ScanLines
        
        For ScanLine = 0 To ScanLines - 1
            StretchBlt DestinationHDC, _
                       ScanLeft + Points(0).X, _
                       ScanLine + Points(0).Y, _
                       ScanWidth, _
                       1, _
                       hGraphics, _
                       0, _
                       ScanLine * ScanZ, _
                       FullWidth, _
                       1
            ScanLeft = ScanLeft - Delta
            ScanWidth = ScanWidth + 2 * Delta
            ScanZ = ScanZ - ScanZDec
        Next
        SetStretchBltMode DestinationHDC, sbmOrig
        
    End Sub

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: how use UDT(User Defined Types) on a class?

    Quote Originally Posted by Cambalinho View Post
    heres the error message:
    https://imgur.com/a/hOjFifj
    Please, attach the error message to your post!
    And the best variant would be to see it as text, not as an image!
    Victor Nijegorodov

  5. #5
    Join Date
    Apr 2009
    Posts
    1,355

    Re: how use UDT(User Defined Types) on a class?

    Code:
    Public Sub DrawImageTrapezoid(ByRef Points() As POINTL, ByVal DestinationHDC As Long, ByVal TranspColor As Long)
    "Compiler error:
    Private enum and user defined types cannot be used as parameters ou return types for public procedures, public data members, or fields of public user defined types"

  6. #6
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: how use UDT(User Defined Types) on a class?

    Quote Originally Posted by Cambalinho View Post
    Code:
    Public Sub DrawImageTrapezoid(ByRef Points() As POINTL, ByVal DestinationHDC As Long, ByVal TranspColor As Long)
    "Compiler error:
    Private enum and user defined types cannot be used as parameters ou return types for public procedures, public data members, or fields of public user defined types"
    And how about the reading the docs?
    https://docs.microsoft.com/en-us/off...r-return-types
    Victor Nijegorodov

  7. #7
    Join Date
    Apr 2009
    Posts
    1,355

    Re: how use UDT(User Defined Types) on a class?

    ok.. the type is public, but i get, now, an error on type:
    Code:
    Public Type POINTL    X As Long
        Y As Long
    End Type
    "compiler error: cannot define a public user-defined type within a private object module"
    i'm much more confused

  8. #8
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: how use UDT(User Defined Types) on a class?

    Perhaps, define the " object module" as public?
    Sorry, i'm not a guru in VB!
    Victor Nijegorodov

  9. #9
    Join Date
    Apr 2009
    Posts
    1,355

    Re: how use UDT(User Defined Types) on a class?

    i can't find that option
    PS: if i use a 'private' on UDT's and the function that have that parameters being 'private', i will not get that error... but the function must be used.. so must be public
    Last edited by Cambalinho; November 4th, 2020 at 03:35 PM.

  10. #10
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: how use UDT(User Defined Types) on a class?

    Quote Originally Posted by Cambalinho View Post
    i can't find that option
    PS: if i use a 'private' on UDT's and the function that have that parameters being 'private', i will not get that error... but the function must be used.. so must be public
    Create a new module and choose public.

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

Featured