Solved

Move mouse to a certain color

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month8 days, 6 hours left to enroll

617 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