BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Tahoma"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
TabCaption(0) = "&Canvas"
TabPicture(0) = "frmPNGmenu.frx":0000
Tab(0).ControlEnabled= 0 'False
Tab(0).Control(0)= "txtAlphaBlend"
Tab(0).Control(1)= "chkAutoErase"
Tab(0).Control(2)= "chkAlphaBlend"
Tab(0).Control(3)= "Label2"
Tab(0).Control(4)= "lblBkg(3)"
Tab(0).Control(5)= "lblBkg(2)"
Tab(0).Control(6)= "lblBkg(1)"
Tab(0).Control(7)= "lblBkg(0)"
Tab(0).ControlCount= 8
TabCaption(1) = "&Size && Pos"
TabPicture(1) = "frmPNGmenu.frx":001C
Tab(1).ControlEnabled= 0 'False
Tab(1).Control(0)= "Label1(0)"
Tab(1).Control(1)= "Label1(1)"
Tab(1).Control(2)= "Label3(3)"
Tab(1).Control(3)= "txtImgXY(1)"
Tab(1).Control(4)= "txtImgXY(0)"
Tab(1).Control(5)= "txtScale(1)"
Tab(1).Control(6)= "txtScale(0)"
Tab(1).Control(7)= "chkScale"
Tab(1).Control(8)= "chkRatio"
Tab(1).Control(9)= "cmdApply"
Tab(1).ControlCount= 10
TabCaption(2) = "Prg &Display"
TabPicture(2) = "frmPNGmenu.frx":0038
Tab(2).ControlEnabled= 0 'False
Tab(2).Control(0)= "Frame1(1)"
Tab(2).Control(1)= "Frame1(0)"
Tab(2).Control(2)= "Label3(2)"
Tab(2).Control(3)= "Label3(1)"
Tab(2).ControlCount= 4
TabCaption(3) = "PNG &Info"
TabPicture(3) = "frmPNGmenu.frx":0054
Tab(3).ControlEnabled= -1 'True
Tab(3).Control(0)= "lblInfo(0)"
Tab(3).Control(0).Enabled= 0 'False
Tab(3).Control(1)= "lblInfo(1)"
Tab(3).Control(1).Enabled= 0 'False
Tab(3).Control(2)= "lblInfo(2)"
Tab(3).Control(2).Enabled= 0 'False
Tab(3).Control(3)= "lblInfo(3)"
Tab(3).Control(3).Enabled= 0 'False
Tab(3).Control(4)= "Label3(0)"
Tab(3).Control(4).Enabled= 0 'False
Tab(3).Control(5)= "lblInfo(4)"
Tab(3).Control(5).Enabled= 0 'False
Tab(3).Control(6)= "Text1"
Tab(3).Control(6).Enabled= 0 'False
Tab(3).Control(7)= "chkShowInfo"
Tab(3).Control(7).Enabled= 0 'False
Tab(3).ControlCount= 8
Begin VB.TextBox txtAlphaBlend
Alignment = 2 'Center
Height = 285
Left = -72885
MaxLength = 3
TabIndex = 4
Text = "255"
Top = 4140
Width = 840
End
Begin VB.CheckBox chkShowInfo
Caption = "Show this tab after PNG shown"
Height = 240
Left = 405
TabIndex = 45
Top = 4380
Value = 1 'Checked
Width = 2625
End
Begin VB.Frame Frame1
Height = 1680
Index = 1
Left = -74520
TabIndex = 31
Top = 2970
Width = 2400
Begin VB.CheckBox chkIL
Caption = "Non-Interlaced PNGs Only Always use scanner effect"
Height = 420
Left = 75
TabIndex = 35
ToolTipText = "Automode will apply effect if image is > 1/3 screen size"
Top = 1155
Width = 2235
End
Begin VB.OptionButton optIL
Caption = "Fade-In (non Alpha Only)"
Height = 210
Index = 2
Left = 75
TabIndex = 33
ToolTipText = "Note: If Alpha, then Fade In is also the Default"
Top = 525
Width = 2175
End
Begin VB.OptionButton optIL
Caption = "Don't Progressive Display"
Height = 210
Index = 1
Left = 75
TabIndex = 34
Top = 855
Width = 2175
End
Begin VB.OptionButton optIL
Caption = "Auto Mode"
Height = 210
Index = 0
Left = 75
TabIndex = 32
ToolTipText = "Alpha=FadeIn,Non-Alpha=Pixelated,Non-Interlaced=Scanner if >1/3 screen size"
Top = 210
Value = -1 'True
Width = 2175
End
End
Begin VB.Frame Frame1
Height = 1980
Index = 0
Left = -74550
TabIndex = 25
Top = 540
Width = 2520
Begin VB.OptionButton optTrans
Caption = "Use the Transparent Color"
Height = 210
Index = 4
Left = 45
TabIndex = 28
Top = 1095
Width = 2400
End
Begin VB.OptionButton optTrans
Caption = "Don't allow any transparency"
Height = 210
Index = 3
Left = 45
TabIndex = 30
Top = 1710
Width = 2400
End
Begin VB.OptionButton optTrans
Caption = "Use another Color"
Height = 210
Index = 2
Left = 45
TabIndex = 29
ToolTipText = "Click ellipse to select a color"
Top = 1395
Width = 1635
End
Begin VB.OptionButton optTrans
Caption = "Use Suggested Window Bkg"
Height = 210
Index = 1
Left = 45
TabIndex = 27
ToolTipText = "If no BKG color provided, white will be default"
Top = 810
Width = 2400
End
Begin VB.OptionButton optTrans
Caption = "Always transparent"
Height = 210
Index = 0
Left = 45
TabIndex = 26
Top = 210
Value = -1 'True
Width = 2235
End
Begin VB.Label Label1
Caption = "Following destroys Alpha info..."
ForeColor = &H000000C0&
Height = 225
Index = 2
Left = 90
TabIndex = 46
Top = 525
Width = 2325
End
Begin VB.Label lblShowColorDlg
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H00808080&
Caption = "..."
ForeColor = &H80000008&
Height = 195
Left = 1725
TabIndex = 36
ToolTipText = "Click to select a color"
Top = 1410
Width = 420
End
Begin VB.Label lblBkgColor
Appearance = 0 'Flat
BorderStyle = 1 'Fixed Single
ForeColor = &H80000008&
Height = 225
Left = 1710
TabIndex = 41
ToolTipText = "Click to select a color"
Top = 1395
Width = 690
End
End
Begin VB.TextBox Text1
Height = 2460
Left = 450
Locked = -1 'True
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 23
Top = 1890
Width = 2535
End
Begin VB.CommandButton cmdApply
Caption = "Apply Above Settings"
Height = 420
Left = -74310
TabIndex = 11
ToolTipText = "Select PNG File"
Top = 3375
Width = 2070
End
Begin VB.CheckBox chkRatio
Caption = "Lock Ratio"
Height = 345
Left = -74025
TabIndex = 10
Top = 2745
Value = 1 'Checked
Width = 1350
End
Begin VB.CheckBox chkScale
Caption = "Reset to 0,0 coordinates && 100% scale for each newly loaded PNG"
Height = 810
Left = -74070
TabIndex = 7
Top = 1140
Value = 1 'Checked
Width = 1740
End
Begin VB.TextBox txtScale
Alignment = 2 'Center
Height = 285
Index = 0
Left = -74025
TabIndex = 8
Text = "100"
Top = 2385
Width = 645
End
Begin VB.TextBox txtScale
Alignment = 2 'Center
Height = 285
Index = 1
Left = -73290
TabIndex = 9
Text = "100"
Top = 2385
Width = 645
End
Begin VB.TextBox txtImgXY
Alignment = 2 'Center
Height = 285
Index = 0
Left = -73965
MaxLength = 4
TabIndex = 5
Text = "0"
Top = 675
Width = 645
End
Begin VB.TextBox txtImgXY
Alignment = 2 'Center
Height = 285
Index = 1
Left = -73230
MaxLength = 4
TabIndex = 6
Text = "0"
Top = 660
Width = 645
End
Begin VB.CheckBox chkAutoErase
Caption = "Always Erase Canvas before Loading new PNG File"
Height = 495
Left = -74490
TabIndex = 2
Top = 810
Value = 1 'Checked
Width = 2535
End
Begin VB.CheckBox chkAlphaBlend
Caption = "Alpha blend PNG over canvas using opacity of"
Height = 495
Left = -74490
TabIndex = 3
Top = 3885
Width = 2475
End
Begin VB.Label Label3
Caption = "Tip: Double click settings to reset to defaults"
Height = 420
Index = 3
Left = -74325
TabIndex = 40
Top = 4170
Width = 2115
End
Begin VB.Label lblInfo
Caption = "Type: "
Height = 240
Index = 4
Left = 555
TabIndex = 39
Tag = "Type: "
Top = 1320
Width = 2295
End
Begin VB.Label Label3
Caption = "How is Interlacing handled. Progressive display will be"
Height = 435
Index = 2
Left = -74490
TabIndex = 38
Top = 2565
Width = 2160
End
Begin VB.Label Label3
Caption = "How are background colors applied for images with transparencies"
Height = 465
Index = 1
Left = -74565
TabIndex = 37
Top = 120
Width = 2580
End
Begin VB.Label Label3
Caption = "Other Information within PNG"
Height = 195
Index = 0
Left = 495
TabIndex = 24
Top = 1665
Width = 2460
End
Begin VB.Label lblInfo
Caption = "Interlaced: "
Height = 240
Index = 3
Left = 555
TabIndex = 22
Tag = "Interlaced: "
Top = 1035
Width = 2295
End
Begin VB.Label lblInfo
Caption = "Bit Depth:"
Height = 240
Index = 2
Left = 555
TabIndex = 21
Tag = "Bit Depth: "
Top = 750
Width = 2295
End
Begin VB.Label lblInfo
Caption = "Last Modified: "
Height = 240
Index = 1
Left = 555
TabIndex = 20
Tag = "Last Modified: "
Top = 465
Width = 2295
End
Begin VB.Label lblInfo
Caption = "Size: "
Height = 240
Index = 0
Left = 555
TabIndex = 19
Tag = "Size: "
Top = 195
Width = 2295
End
Begin VB.Label Label2
Alignment = 2 'Center
Caption = "CANVAS CLEARING ACTIONS"
BeginProperty Font
Name = "Tahoma"
Size = 8.25
Charset = 0
Weight = 400
Underline = -1 'True
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H8000000D&
Height = 255
Left = -74520
TabIndex = 18
Top = 405
Width = 2475
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "Scale W / H %"
Height = 195
Index = 1
Left = -73890
TabIndex = 17
Top = 2055
Width = 1065
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "Image Left / Top"
Height = 195
Index = 0
Left = -73935
TabIndex = 16
Top = 330
Width = 1200
End
Begin VB.Label lblBkg
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000018&
BorderStyle = 1 'Fixed Single
Caption = "Click to Clear the Canvas"
ForeColor = &H000000C0&
Height = 300
Index = 3
Left = -74565
TabIndex = 15
Top = 3285
Width = 2565
End
Begin VB.Label lblBkg
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000018&
BorderStyle = 1 'Fixed Single
Caption = "Click to Remove Bkg Image"
ForeColor = &H000000C0&
Height = 300
Index = 2
Left = -74565
TabIndex = 14
Top = 2655
Width = 2565
End
Begin VB.Label lblBkg
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000018&
BorderStyle = 1 'Fixed Single
Caption = "Click to Change Bkg Image"
ForeColor = &H00C00000&
Height = 300
Index = 1
Left = -74565
TabIndex = 13
Top = 2055
Width = 2565
End
Begin VB.Label lblBkg
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000018&
BorderStyle = 1 'Fixed Single
Caption = "Click to Change Background Color"
ForeColor = &H00C00000&
Height = 300
Index = 0
Left = -74565
TabIndex = 12
Top = 1500
Width = 2565
End
End
Begin VB.CommandButton cmdOpen
Caption = "Load PNG Image"
Height = 315
Left = 60
TabIndex = 0
ToolTipText = "Select PNG File"
Top = 45
Width = 3060
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 1155
Top = 4470
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.Label lblPBar
Appearance = 0 'Flat
BackColor = &H0024CACE&
BorderStyle = 1 'Fixed Single
ForeColor = &H80000008&
Height = 210
Left = 60
TabIndex = 43
Tag = "3045"
Top = 5115
Visible = 0 'False
Width = 3045
End
Begin VB.Label lblInfo
Caption = "Processing Time:"
Height = 225
Index = 5
Left = 330
TabIndex = 44
Tag = "Processing Time: "
Top = 5115
Width = 2760
End
End
Attribute VB_Name = "frmPNGmenu"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' For those that know my stuff, I generally add a ton of comments.
' This is for 3 main reasons:
' 1) If this stuff is new to you, hopefully it doubles as a teaching aid
' 2) If you understand it better, then you might be apt to recommend improvements
' 3) So I know what the heck I was thinking when I revisit this in a year or so :)
' Used to close Owner form when owned form is closed
Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_CLOSE As Long = &H10
' used to create offscreen bitmap
Private Declare Function CreateCompatibleBitmap Lib "gdi32.dll" (ByVal hDC As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hDC As Long) As Long
Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hDC As Long) As Long
Private Declare Function BitBlt Lib "gdi32.dll" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As Long, ByVal hDC As Long) As Long
Private Declare Function GetGDIObject Lib "gdi32.dll" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, ByRef lpObject As Any) As Long
Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Private hOldBmp As Long
Private hBmp As Long
Private tDC As Long
' used for simple timing
Private Declare Function GetTickCount Lib "kernel32.dll" () As Long
Private compileTipShown As Boolean
' The routines, when compiled are fast, however, when using progressive display
' and also using a custom progress meter, the difference can be >100 ms depending
' on what code you are processing in the class's Progress event. So we'll
' turn off custom progress meter when progressive display is being used.
Private bUseCustomProgressMeter As Boolean
' the class has an option to CRC check each block/chunk of data received from the
' PNG file. Though this is optional, it is recommended. To make the class relatively
' safe from crashing on corrupted PNG data, On Error statements & hard-coded CRC
' checks on critical chunks are used. The following option is for use on
' non-critical chunks that do not prevent the image from being displayed.
' For example, the "last modified timestamp" chunk
Private Const ValidateNonCriticalData As Boolean = True
' the stdPNG class has optional feedback/events
' If feedback and progressive display are not wanted then,
' do not declare using the WithEvents keyword
' i.e.: Private myPNG As StdPNG
' Following are the 2 Events provided with the class
Private WithEvents myPNG As StdPNG
Attribute myPNG.VB_VarHelpID = -1
Private Sub myPNG_ProgessiveDisplay(ByVal Width As Long, ByVal Height As Long, _
destinationDC As Long, destinationHwnd As Long, _
ByVal WinBkgColor As Long, ByVal AlphaPng As Boolean, _
X As Long, Y As Long, ByVal IsInterlaced As Boolean, _
ByVal useProgression As Boolean)
' ^^ Width & Height are the true PNG sizes in pixels
' ^^ destinationDC, destinationHwnd must be set to use progressive display
' ^^ WinBkgColor is the suggested DC backcolor for the PNG
' ^^ AlphaPng is True if the PNG uses any transparencies
' ^^ X,Y are set to where progressively displayed PNG should be drawn at
' ^^ IsInterlaced is True only if the image is encoded as progressively displayed
' ^^ useProgression is a suggestion only. It will be True under the following cases
' isInterlaced = True
' isInterlaced = False and Width*Height> (ScreenWidth*ScreenHeight)\3
' if you want to use progressive display, you must reply to this event.
' Even if the PNG is not encoded with interlacing, simply passing
' a valid hDC and hWnd value back to this event, the non-interlaced
' PNG will be displayed using a scanner-type progressive display.
' Progressively displayed images cannot be performed if you want to
' simultaneously stretch the image; therefore, there are no options to
' specify a blt width/height.
' This is also the one area where you should check and modify any PNG
' properties you want to possibly change (i.e., palette, progressive display mode)
' NOTE: This event will not be fired if you opted to
' set class's ProgressiveDisplay property to pngNeverProgressive
bUseCustomProgressMeter = True
lblPBar.Visible = True
' progressive display is not available when stretching image
' so we will use our own progress meter
If Val(txtScale(0)) <> 100 Then Exit Sub
If Val(txtScale(1)) <> 100 Then Exit Sub
' basically, don't show a progress meter if we are going to use
' progressive display as that, in itself, acts as a progress meter
If (IsInterlaced = False And chkIL = 1) Or useProgression = True Then
' user wants to always display non-interlaced images w/scanner effect
' or it is suggested to use progression. Note that if the option to
' never use progressive display was set, we wouldn't get this event
bUseCustomProgressMeter = False
destinationDC = Form1.hDC
destinationHwnd = Form1.hwnd
X = Val(txtImgXY(0))
Y = Val(txtImgXY(1))
lblPBar.Visible = False
End If
End Sub
Private Sub myPNG_Progress(ByVal Percentage As Long)
' Whether or not you want to display a progress bar is up to you
' However, displaying a progress bar while also allowing progressive
' display and the image is interlaced, will slow down the routines
' just a bit while this event is being called.
' Percentage is in whole numbers; Percentage/100 for decimals