What is the RGB value of the colour of Excel's scroll bars
This code should work for any location on the screen:
Option Explicit
Private Declare Sub Sleep _
Lib "kernel32" _
(ByVal dwMilliseconds As Long)
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 GetDC _
Lib "user32" _
(ByVal hwnd As Long) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Public Sub ColorUnderCursor()
Dim pCursorPos As POINTAPI
Dim lngColorUnderCursor As Long
Dim R As Long
Dim G As Long
Dim B As Long
' Sleep two seconds to allow cursor
' to move somewhere useful
Sleep 2000
GetCursorPos pCursorPos
lngColorUnderCursor = _
GetPixel(GetDC(0&), _
pCursorPos.x, pCursorPos.y)
SplitRGB lngColorUnderCursor, R, G, B
MsgBox CStr(lngColorUnderCursor) & _
":" & vbCrLf & _
"R=" & CStr(R) & vbCrLf & _
"G=" & CStr(G) & vbCrLf & _
"B=" & CStr(B)
End Sub
Sub SplitRGB( _
ByVal RGBValue As Long, _
ByRef R As Long, _
ByRef G As Long, _
ByRef B As Long _
)
R = RGBValue And 255
G = RGBValue \ 256 And 255
B = RGBValue \ 256 ^ 2 And 255
End Sub
|