Solved

Move mouse to a certain color

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VB6 convert MSHFlexgrid1 cells 7 52
Use Multiple Forms 4 38
VBA error replacing data 6 35
Visual Studio 2005 text editor 10 23
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now