Skip to content

Instantly share code, notes, and snippets.

@xxdoc
Forked from facebookegypt/gist:5666803
Created October 3, 2018 07:13
Show Gist options
  • Save xxdoc/cddc2e105896e4a9f9012689bb1da81f to your computer and use it in GitHub Desktop.
Save xxdoc/cddc2e105896e4a9f9012689bb1da81f to your computer and use it in GitHub Desktop.
Color Picker Source Code Download Visual Basic 6.0
'Source : http://evry1.net/VB6/
'Subject : Visual Basic 6.0 How to create and understand
'Color Picker Appliaction
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Option Explicit
Private Type pointapi
Px As Long
Py As Long
End Type
Private Declare Function GetCursorPos Lib "user32" _
(lpPoint As pointapi) As Long
Private Declare Function GetPixel Lib "gdi32" _
(ByVal hdc As Long, ByVal x As Long, _
ByVal y As Long)As Long
Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" _
(ByVal lpDriverName As String,ByVal lpDeviceName As String, _
ByVal lpOutput As String, lpInitData As Any) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Dim PosXY As pointapi
Private Function LongToRGB(lColor As Long) As String
Dim iRed As Long, iGreen As Long, iBlue As Long
iRed = lColor Mod 256
iGreen = ((lColor And &HFF00) / 256&) Mod 256&
iBlue = (lColor And &HFF0000) / 65536
LongToRGB = Format$(iRed, "000") & ",_
" & Format$(iGreen, "000") & ", _
" & Format$(iBlue, "000")
End Function
Private Function GetPixelColor(x As Long, _
y As Long, _
Optional HexCode As Boolean = False) As String
Dim DC As Long
DC = CreateDC("DISPLAY", vbNullString, vbNullString, 0&)
GetPixelColor = Format$(GetPixel(DC, x, y), "00000000") 'long
DeleteDC DC
End Function
Private Sub Form_Load()
Me.BackColor = &HFF&
Timer1.Enabled = 1
End Sub
Private Sub Form_Resize()
Label1.Top = Me.ScaleHeight - Label1.Height
Label2.Top = Me.ScaleHeight - Label2.Height
Label3.Top = Me.ScaleHeight - Label3.Height
End Sub
Private Sub Label1_Click()
End
End Sub
Private Sub Label2_Click()
End
End Sub
Private Sub Timer1_Timer()
GetCursorPos PosXY
Label1.Caption = "X : " & PosXY.Px
Label2.Caption = "Y : " & PosXY.Py
Label3.Caption = "RGB : " & LongToRGB(GetPixelColor(PosXY.Px, PosXY.Py))
Picture1.BackColor = GetPixelColor(PosXY.Px, PosXY.Py)
End Sub
'See more at:
'http://vb6access2003.blogspot.com/2012/04/visual-basic-60-color-picker.html#sthash.DTfjFVv4.dpuf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment