Skip to content

Instantly share code, notes, and snippets.

@facebookegypt
Created June 4, 2016 20:45
Show Gist options
  • Select an option

  • Save facebookegypt/1a51be4e83780884e725e98349b0ba6c to your computer and use it in GitHub Desktop.

Select an option

Save facebookegypt/1a51be4e83780884e725e98349b0ba6c to your computer and use it in GitHub Desktop.
'Ahmed Samir - Software developer
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 / 256&) Mod 256&
iBlue = lColor / 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_Click()
Text1.BackColor = RGB(0, 0, 0)
End Sub
Private Sub Form_Load()
Timer1.Enabled = 1
End Sub
Private Sub Form_MouseMove(Button As Integer, _
Shift As Integer, _
X As Single, Y As Single)
Me.MousePointer = 99
Me.MousePointer = vbCustom
Me.MouseIcon = LoadPicture(App.Path & "\PSCP1.cur")
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment