|
-
Dec 28th, 2001, 05:37 PM
#1
Thread Starter
New Member
Color under cursor ???
How can I know who color is under cursor (mouse) ???
Thanx !
Ko Zna Zna Ko Nezna Naucice
-
Dec 28th, 2001, 06:39 PM
#2
Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Simple as that... Just add this API to your project and call with the appropraite varibles to recieve your RGB in long form.
VB Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.Caption = GetPixel(Form1.hdc, X / 15, Y / 15)
End Sub
The 15 is the twips per pixel on my form. Screen.TwipsPerPixelX (Y) ...
Hope that this helps
NOMAD
-
Dec 28th, 2001, 06:58 PM
#3
If you don't want to "bother" with API you can just use the point function for Picture box or Form... This will only work when you are over a form or picture box... I think, I haven't tested it just remember looking into it.
NOMAD
-
Dec 28th, 2001, 07:52 PM
#4
Good Ol' Platypus
To get it for the entirety of the screen, use this snippet that I've written.
VB Code:
Private Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Long
Private Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Function ColourUnderCursor() As Long
Dim lPoint As POINTAPI
GetCursorPos lPoint
ColourUnderCursor = GetPixel(GetDc(GetDesktopWindow), lPoint.x, lPoint.y)
End Function
It requires the declaration of GetCursorPos, GetDesktopWindow, GetDc, and GetPixel. It also requires the PointAPI Type, all of which are included above the function.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Dec 29th, 2001, 10:59 AM
#5
Thread Starter
New Member
Thanx
OK thanx fo this !! but i have a prblem !
I have 2 Picture box ( Picture1 and Picture 2) ..I need when i move mouse in Picture1 ...then Picture2.BackColor = ColourUnderCursor !!!!
How can I do this .... Thanx
Ko Zna Zna Ko Nezna Naucice
-
Dec 30th, 2001, 12:31 AM
#6
Good Ol' Platypus
Make a timer control and set it's refresh to, say, 50ms (the Interval property). In the timer subroutine, add this code:
VB Code:
Picture2.BackColor = ColourUnderCursor
It's as simple as that!
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|