-
November 1st, 2020, 07:23 AM
#1
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
-
November 1st, 2020, 10:05 PM
#2
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.
-
November 2nd, 2020, 04:00 PM
#3
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
-
November 3rd, 2020, 02:27 AM
#4
-
November 3rd, 2020, 04:49 PM
#5
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"
-
November 4th, 2020, 02:11 AM
#6
Re: how use UDT(User Defined Types) on a class?
Originally Posted by Cambalinho
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
-
November 4th, 2020, 03:04 PM
#7
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
-
November 4th, 2020, 03:18 PM
#8
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
-
November 4th, 2020, 03:30 PM
#9
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.
-
November 9th, 2020, 12:32 AM
#10
Re: how use UDT(User Defined Types) on a class?
Originally Posted by Cambalinho
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|