Option Explicit Private m_Deformation As IDeformation2 Private Function SlightlyComplicatedCalculation(ByVal Param1 As Long, ByVal Param2 As Single) As Double
Return (Param1+(Param2/3.141-(Param1/6 + (2*param1+fn(x, (x+1)))) + 42)) + 11
End Function Private Property Get QueryString() As String
' Visual Basic does not support inline comments. Dim sql As String Dim SomeCondition As String SomeCondition = "FirstName='Smith'" sql = "SELECT SomeField FROM SomeTable WHERE " & SomeCondition QueryString = sql
End Property Public Function MakeUpSomeJs As String
Dim js As String js = "var r = function() { var x = DoSomeJQueryStuff(); return x+1 }" Return js
End Function Public Function MakeUpSomeJsThatWritesSql As String
Dim js As String js = "var r = function() { return 'SELECT * FROM ' + name_of_table + ' WHERE ' + condition }"; Return js;
End Function Private Sub Form_Activate()
Static AlreadyActivated As Boolean If AlreadyActivated Then
Exit Sub ' Ensure that the rest of this routine is only executed when the form is first activated.
End If AlreadyActivated = True Dim OriginalPicture As IPicture Dim OriginalFilename As String Dim OriginalDimensions As Rect OriginalFilename = "OriginalImage.bmp" Set OriginalPicture = LoadPicture(OriginalFilename) OriginalDimensions = GetPictureDimensions(OriginalPicture) Dim hdcOffscreen As Long Dim hTemp As Long hdcOffscreen = CreateCompatibleDC(Me.hdc) hTemp = SelectObject(hdcOffscreen, OriginalPicture.Handle) ' SelectObject returns a handle ot the previously selected object. InitializeDeformation OriginalDimensions PaintOriginalImage hdcOffscreen, OriginalDimensions PaintModifiedImage hdcOffscreen, OriginalDimensions SelectObject hdcOffscreen, hTemp ' Always select the original object (returned by the first call to SelectObject). DeleteDC hdcOffscreen ' Always DeleteDC when finished with a hdc created by CreateCompatibleDC.
End Sub Private Sub InitializeDeformation(ByRef OriginalDimensions As Rect)
' Set up the transformation. Dim t As Transform2 Set t = New Transform2 t.Rotate Pi / 4 Set m_Deformation = t ' The Transform2 class implements IDeformation2, making this assignment valid. ' Calculate the dimensions of the modified image. Dim NewDimensions As Rect NewDimensions = OriginalDimensions m_Deformation.ApplyToDimensions NewDimensions ' A simple rotation will move the boundaries of the picture so that it overlaps the x or y axis. ' To keep the whole picture on the form, with the top left corner of the image on the top left corner ' of the form, we must move the image. t.Translate -NewDimensions.Left, -NewDimensions.Top ' The dimensions of the modified image will need to be recalculated in PaintModifiedImage, ' because we have changed t.
End Sub Private Sub PaintOriginalImage(ByVal hdcOffscreen As Long, ByRef OriginalDimensions As Rect)
' Paint the original image, one pixel at a time. Dim x As Long Dim y As Long For y = 0 To OriginalDimensions.Bottom - 1
For x = 0 To OriginalDimensions.Right - 1
SetPixel hdc, x, y, GetPixel(hdcOffscreen, x, y)
Next x
Next y
End Sub Private Sub PaintModifiedImage(ByVal hdcOffscreen As Long, ByRef OriginalDimensions As Rect)
' Calculate the dimensions of the resulting image. Dim NewDimensions As Rect Dim OriginalCoordinates As Coordinates2 Dim DummyColor As RgbQuad NewDimensions = OriginalDimensions m_Deformation.ApplyToDimensions NewDimensions ' Paint the modified image, one pixel at a time. ' Now that we know the dimensions of the modified image, we can process each pixel in the modified image. ' For each pixel, we call m_Deformation.UnApply to determine the coordinates of the pixel in the original image ' which corresponds to the current pixel in the new image. Dim x As Long Dim y As Long For y = 0 To NewDimensions.Bottom + 1
For x = 0 To NewDimensions.Right + 1
OriginalCoordinates = MakeCoordinates2(x, y) If m_Deformation.UnApply(OriginalCoordinates, DummyColor, OriginalDimensions) Then
If RectBoundsPoint(OriginalCoordinates, OriginalDimensions) Then
SetPixel hdc, OriginalDimensions.Right + x, y, GetPixel(hdcOffscreen, OriginalCoordinates.x, OriginalCoordinates.y)
End If
End If
Next x
Next y
End Sub