|
Formlarımıza mozaikler döşeyebiliriz artık bu çok kolay msimg32.dll i kullanarak bunu -
05-13-2008
msimg32.dll için demo
’// Microsoft diyor ki GradientFill Windows 2000 veya Windows 98 altında çalışır ama görülüyorki NT 4.0 ve Windows 95
’// gayet iyi bi şekilde çalışıyor
’// - yeni bir proje oluşturup bi form hazırlayın
’ Form1 in default olarak
’//- BorderStyle = 0 (None) olsun
’// - Timer control ekleyin formunuza ve interval özelliğini 2000 yapın
’ aşağıdaki kodları formunuza ekleyin ve çalıştırın
Option Explicit
Option Base 0
Private Type TRIVERTEX
x As Long
y As Long
RED As Integer
GREEN As Integer
BLUE As Integer
Alpha As Integer
End Type
Private Type GRADIENT_RECT
UpperLeft As Long
LowerRight As Long
End Type
Private Type GRADIENT_TRIANGLE
Vertex1 As Long
Vertex2 As Long
Vertex3 As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GradientFill Lib "msimg32.dll" (ByVal hdc As Long, PVertex As TRIVERTEX, ByVal dwNumVertex As Long, PMesh As Any, ByVal dwNumMesh As Long, ByVal dwMode As Long) As Boolean
Private Const GRADIENT_FILL_RECT_H = &H0
Private Const GRADIENT_FILL_RECT_V = &H1
Private Const GRADIENT_FILL_TRIANGLE = &H2
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Const SWP_WNDFLAGS = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private RR As RECT
Private Const MaxN As Integer = 100
Private Const DefaultN As Integer = 20
Dim CurrentN As Integer
Dim instantN As Integer
Dim ndx As Integer
Dim ndy As Integer
Dim gtri1 As GRADIENT_TRIANGLE, gtri2 As GRADIENT_TRIANGLE
Dim gtri() As GRADIENT_TRIANGLE
Dim vert() As TRIVERTEX
Dim row As Integer, col As Integer
Dim ndx1 As Integer
Dim ndy1 As Integer
Dim ndxrow As Long
Dim ndxrowcol As Long
Dim ndxrow1 As Long
Dim ndxrow1col
Dim rowbyndx As Double
Dim rrrminusrrl1 As Double, rrrminusrrl2 As Double, rrbminusrrt1 As Double, rrbminusrrt2 As Double
Dim res As Long
Private Sub Form_Click()
Unload Me
End
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 27 Then
KeyAscii = 0
Call Form_Click
Exit Sub
ElseIf KeyAscii = Asc("+") Then
’// increase granularity
KeyAscii = 0
If CurrentN < MaxN Then
CurrentN = CurrentN + 10
End If
ElseIf KeyAscii = Asc("-") Then
’// decrease granularity
KeyAscii = 0
If CurrentN > 10 Then
CurrentN = CurrentN - 10
End If
End If
End Sub
Private Sub Form_Load()
If App.PrevInstance Then End
Randomize
CurrentN = DefaultN
instantN = CurrentN
ndx = instantN
ndy = instantN
Me.Move 0, 0, Screen.Width, Screen.Height
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_WNDFLAGS
End Sub
Private Function getrnd() As Long
getrnd = CLng(Val("&H" & Hex$(CInt(Rnd * 255)) & "00"))
End Function
Private Sub Form_Resize()
GetClientRect Me.hwnd, RR
End Sub
Private Sub Timer1_Timer()
test
End Sub
Private Sub test()
instantN = CurrentN
ndx = CInt(Rnd * instantN + 1) ’// minimum 1
ndy = CInt(Rnd * instantN + 1) ’// minimum 1
ndx1 = ndx + 1
ndy1 = ndy + 1
ReDim gtri(0 To 2 * ndx * ndy - 1)
ReDim vert(0 To (ndx + 1) * (ndy + 1) - 1)
For row = 0 To ndy - 1
ndxrow = ndx * row
For col = 0 To ndx - 1
gtri1.Vertex1 = row * ndx1 + col
gtri1.Vertex2 = gtri1.Vertex1 + ndx + 2
gtri1.Vertex3 = gtri1.Vertex2 - 1
gtri2.Vertex1 = gtri1.Vertex1
gtri2.Vertex2 = gtri1.Vertex2
gtri2.Vertex3 = gtri2.Vertex1 + 1
ndxrowcol = (ndxrow + col) * 2
gtri(ndxrowcol).Vertex1 = gtri1.Vertex1
gtri(ndxrowcol).Vertex2 = gtri1.Vertex2
gtri(ndxrowcol).Vertex3 = gtri1.Vertex3
gtri(ndxrowcol + 1).Vertex1 = gtri2.Vertex1
gtri(ndxrowcol + 1).Vertex2 = gtri2.Vertex2
gtri(ndxrowcol + 1).Vertex3 = gtri2.Vertex3
Next
Next
For row = 0 To ndy
ndxrow1 = row * (ndx + 1)
For col = 0 To ndx
ndxrow1col = ndxrow1 + col
vert(ndxrow1col).BLUE = getrnd
vert(ndxrow1col).RED = getrnd
vert(ndxrow1col).GREEN = getrnd
vert(ndxrow1col).Alpha = 0
Next
Next
rrrminusrrl1 = (RR.Right - RR.Left)
rrbminusrrt1 = (RR.Bottom - RR.Top)
rrrminusrrl2 = rrrminusrrl1 / ndx
rrbminusrrt2 = (rrbminusrrt1 / ndy)
For row = 0 To ndy
ndxrow1 = row * ndx1
rowbyndx = rrbminusrrt2 * row
For col = 0 To ndx
ndxrow1col = ndxrow1 + col
vert(ndxrow1col).x = RR.Left + rrrminusrrl2 * col
vert(ndxrow1col).y = RR.Top + rowbyndx
Next
Next
res = GradientFill(Me.hdc, vert(0), (ndx + 1) * (ndy + 1), gtri(0), 2 * ndx * ndy, GRADIENT_FILL_TRIANGLE)
End Sub
|