Solved

Move mouse to a certain color

Posted on 2004-04-07
8
154 Views
Last Modified: 2010-05-02
I would like to be able to put a color in a textbox (example #FFFFFF) and have the mouse move to that color?

Does anyone know the code to do somthing like that?
0
Comment
Question by:reggiewolf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
8 Comments
 
LVL 11

Expert Comment

by:jmwheeler
ID: 10776781
I'm not 100% clear on what you are trying to accomplish.  You want to enter a color in a textbox and have the mouse to that color but where is that color?  Is it a different control with a background color or the forms background color.  Please be more specific.
0
 

Author Comment

by:reggiewolf
ID: 10776960
I Am trying to find out how to move the mouse to a given Pixel. Like a given Colored Pixel. For instence lets say RED how can i get the mouse to only look for red colors on a BOX that is like 50x50 around the mouse.. how can i get the Mouse to go strait to the Red colored Pixel.
0
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 50 total points
ID: 10777937
This could be a start for you.. set the form's borderstyle to 0 and try it. Reason is.. you have to get the x/y position of the PictureBox relative to the screen (to set the mouse cursor to) and caption bar sizes vary... (I think you'll need to use GetSysMetrics to get it's size)


Form1:
=========

Option Explicit

Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Sub Command1_Click()
    Call GotoPixel(Picture1, RGB(0, 0, 0))
End Sub
Private Sub Command2_Click()
    Call GotoPixel(Picture1, RGB(255, 255, 255))
End Sub
Private Sub Form_Load()
    Picture1.BorderStyle = 0
    Picture1.Picture = LoadPicture("c:\test.bmp")
End Sub
Private Sub GotoPixel(ByRef PicBox As PictureBox, lRGB As Long)
    Dim lPosX As Long, lPosY As Long
    Dim PicX As Long, PicY As Long
    'Get the X/Y pixel positions of the PictureBox relative to the screen
    'resolution
    PicX = (Me.Left / Screen.TwipsPerPixelX) + (PicBox.Left / Screen.TwipsPerPixelX)
    PicY = (Me.Top / Screen.TwipsPerPixelY) + (PicBox.Top / Screen.TwipsPerPixelY)
    'Loop through our PictureBox.. this searches from top to bottom of each pixel going
    'from left to right
    For lPosX = 1 To PicBox.Width
        For lPosY = 1 To PicBox.Height
            'Check the current pixel.. if it matches the one we specify.. position
            'the cursor at that location
            If GetPixel(PicBox.hdc, lPosX, lPosY) = lRGB Then
                Call SetCursorPos(PicX + lPosX, PicY + lPosY)
                Exit Sub
            End If
        Next lPosY
    Next lPosX
End Sub
0
 

Author Comment

by:reggiewolf
ID: 10778569
How would you make it realtime?
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10779872
What do you mean by "realtime"? If it's in a TextBox event or Command Button event.. there's no real difference.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question