Solved

Move mouse to a certain color

Posted on 2004-04-07
8
152 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
  • 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

820 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