I wish to build to program which is able snap a point in windows or i should say get a coordinate of that point based on the given color. Do anyone have idea how to do it? Thanks for help.
Printable View
I wish to build to program which is able snap a point in windows or i should say get a coordinate of that point based on the given color. Do anyone have idea how to do it? Thanks for help.
Do you meen search through a graphic (picbox etc or screen) looking for a certain colour?
yes. I think WinAPI can do it but i dont know which command to use. Please give me an example code if you can. Thanks again for help.
use the GetPixel API (or you can use the point method of pictureboxes/forms).
That won't help much - he needs to know how.
Ok, add the declaration from the API viewer as you would any other API call. Then, use the function like below. Remember you'll also have to get the PointAPI declaration from the Types field of the API viewer:The code hasn't been tested, but should work. Just go through the Ret() array, just Ret(0) if you aren't expecting more than 1 match. You might use it like this:VB Code:
Function SearchForColour(ByRef mPic As PictureBox, ByRef Ret() As PointAPI, ByRef Colour As Long) Dim X As Long Dim Y As Long Dim Count As Long mPic.ScaleMode = 3 'vbPixels For Y = 0 To mPic.ScaleHeight For X = 0 To mPic.ScaleWidth If GetPixel(X, Y, mPic.hDC) = Colour Then Count = Count + 1 Redim Preserve Ret(0 To Count - 1) As PointAPI With Ret(Count - 1) .X = X .Y = Y End With Next X Next YVB Code:
Dim myArr() As PointAPI Dim I As Long On Error Goto NoBlack SearchForColour Picture1, myArr, RGB(0, 0, 0) For I = LBound(myArr) To UBound(myArr) Msgbox "Pure Black found at X: " & myArr(I).X & " Y: " & myArr(I).Y & ".", , "Black Found!" Next I NoBlack: Msgbox "No Pure Black in Picturebox!", , "No Black!"
Don't forget the Extra type used there!
VB Code:
Public Type POINTAPI x As Long y As Long End Type
I think those example is sufficient for me to build the program. I appreciate the advises from you guys and thanks a lot. :)
SLH - ;)Quote:
Ok, add the declaration from the API viewer as you would any other API call. Then, use the function like below. Remember you'll also have to get the PointAPI declaration from the Types field of the API viewer:
:eek: :rolleyes:
Ah well, may have saved him some time.... or not :)