10 Replies - 794 Views - Last Post: 31 August 2013 - 04:45 AM Rate Topic: -----

#1 penny_075  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 26-August 13

Remove warning

Posted 29 August 2013 - 01:41 PM

I've piced together code from tutorials and code that I have written that moves the curser by traking your hand on a black surface.


Everything works ok but theres a warning code in reff to Me.cursor.Position code below

 Me.Cursor.Position = New Point(xx1, yy1) 



Heres my project ive tried adding option expelict but it caused more errors



I found this code online ( I did not create it )
it access your webcam and streams the video feed to a picture box

              
‘
‘WEB CAM CODE
‘Connects to webcam shows output in picturebox1
‘
‘

Public Class Form1
Const WM_CAP As Short = &H400S
Const WM_CAP_DRIVER_CONNECT As Integer = WM_CAP + 10
Const WM_CAP_DRIVER_DISCONNECT As Integer = WM_CAP + 11
Const WM_CAP_EDIT_COPY As Integer = WM_CAP + 30
Const WM_CAP_SET_PREVIEW As Integer = WM_CAP + 50
Const WM_CAP_SET_PREVIEWRATE As Integer = WM_CAP + 52
Const WM_CAP_SET_SCALE As Integer = WM_CAP + 53
Const WS_CHILD As Integer = &H40000000
Const WS_VISIBLE As Integer = &H10000000
Const SWP_NOMOVE As Short = &H2S
Const SWP_NOSIZE As Short = 1
Const SWP_NOZORDER As Short = &H4S
Const HWND_BOTTOM As Short = 1
Dim iDevice As Integer = 0             ‘  Current device ID
Dim hHwnd As Integer                   ‘  Handle to preview window
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Object) As Integer
Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
Declare Function DestroyWindow Lib "user32" (ByVal hndw As Integer) As Boolean
Declare Function capCreateCaptureWindowA Lib "avicap32.dll" (ByVal lpszWindowName As String, ByVal dwStyle As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Short, ByVal hWndParent As Integer, ByVal nID As Integer) As Integer
Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriver As Short, ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, ByVal cbVer As Integer) As Boolean

Private Sub LoadDeviceList()
Dim strName As String = Space(100)
Dim strVer As String = Space(100)
Dim bReturn As Boolean
Dim x As Integer = 0

        '  
        '  Code Below Loads the  name of all available devices into the lstDevices 
        '

Do

        '  
        '  code  below gets the Driver Name and Version 
        '
bReturn = capGetDriverDescriptionA(x, strName, 100, strVer, 100)
        '  
        '  If  statement checks if there is a device and adds  the name to the list 
        '

If bReturn Then ListBox1.Items.Add(strName.Trim)
x += 1
Loop Until bReturn = False
End Sub


Private Sub OpenPreviewWindow()
 Dim ScreenResolutionWidth As Integer = Screen.PrimaryScreen.Bounds.Width  ‘ verable for ScreenResolutionWidth
Dim ScreenResolutionHight As Integer = Screen.PrimaryScreen.Bounds.Height  ‘verable for ScreenResolutionHeight

‘
‘Code used to determin screen resolution timer below moves a curse on resolution of 1300 X 700 or greater
‘
If ScreenResolutionWidth < 1300 Or ScreenResolutionHight < 700 Then
MsgBox("Higher Sreen Resolution Required 1300, 700 Or Higher", vbOKCancel + vbCritical, "Mushi")  ‘Warns User to change Resolution

Call Shell("rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,3") ‘ Opens Shell to user change color
Application.Exit() ‘closes application 
End If


 
 

        ' 
        ' Open Preview window in picturebox 
        '
hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 640, 480, PictureBox1.Handle.ToInt32, 0)

        If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) Then 
            ' 
            'Set the preview scale 
            ' 
            SendMessage(hHwnd, WM_CAP_SET_SCALE, True, 0) 
 
            ' 
            'Set the preview rate in milliseconds 
            ' 
            SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0) 
 
            ' 
            'Start previewing the image from the camera 
            ' 
            SendMessage(hHwnd, WM_CAP_SET_PREVIEW, True, 0) 
 
            ' 
            ' Resize window to fit in picturebox 
            ' 
            SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, PictureBox1.Width, PictureBox1.Height, SWP_NOMOVE Or SWP_NOZORDER)
 
        Else 

            ' 
            '  If  there is an Error connecting to device close window send error message
            '  

DestroyWindow(hHwnd)
Dim testMsg As Integer
testMsg = MsgBox("An Error Has Occurred. Please check your webcam to make sure it is properly conneted", vbOKCancel + vbCritical, "Mushi") ‘ gives error when system cannot connect to a webcam
Application.Exit() ‘ exit upon error
End If
End Sub


Private Sub ClosePreviewWindow()
        ' 
        ' Disconnect from device 
        '
SendMessage(hHwnd, WM_CAP_DRIVER_DISCONNECT, iDevice, 0)
        ' 
        ' close window 
        '
DestroyWindow(hHwnd)
End Sub


Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
‘
‘Starts the preview window when form 1 loads
‘
LoadDeviceList()
OpenPreviewWindow()

‘
‘Enables timer 1
‘

Timer1.Enabled = True
End Sub




The next section is the tracks hand moves the mouse



‘
‘Picture box 1 to picture box 2 image transfer  
‘Verifies location of light pixel searches from bottom right hand to left and increases search to 
'till reaches top left of picture box 2 if can’t find lighter color timer resets if find color move mouse 
'to aprox location reset timer

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim R, B, G,   yy, xx, yy1, xx1,  
 
 
TextBox1.Text = Cursor.Position.X   ‘  display of mouse location x cord
TextBox2.Text = Cursor.Position.Y  ‘  display of mouse location y cord
Dim data As IDataObject
‘
‘Takes the image from picture box 1 and copies it to picture box 2 as a bitmap
‘
Dim bmap As Image
SendMessage(hHwnd, WM_CAP_EDIT_COPY, 0, 0)
data = Clipboard.GetDataObject()
bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Image)
Dim img As New Bitmap(PictureBox2.Image)
 
bmap.RotateFlip(RotateFlipType.Rotate180FlipY)    ‘Rotates the image to match hand movements left is left right is right

PictureBox2.Image = bmap
R = 0
B = 0
G = 0
Dim pixel    ‘variable used to get pixel 

 ‘
‘ nested For used to verify the location of  the lighter pixel then move the mouse to its approximate grid location
‘note  approximate grid cords will not match the  exact x and y cords for screen resolution  Ie 20 ,366 pixal location  ‘will generate a diff mouse move location  other than  20 , 366
For yy = 460 To 1 Step -20
For xx = 1 To 640 Step 40
 pixel = img.GetPixel(xx, yy)
  
R = pixel.R
B = pixel.B
G = pixel.G

‘ values lighter than black serface can track any color with threasholds higher than 100 red blue and green

If  R > 100 And B > 100 And G > 100 Then   
‘ adjustment  y axis to move mouse up when your hand moves forward and down when you retract your hand
yy1 = 460 - yy
yy1 = yy1 * 2
xx1 = xx * 2.3

‘ Moves mouse to approximate x.y cord of pixel with theashold of  R >  100 And B > 100 And G1 > 100  Please ‘help  I cant figure out how to remove this warning
‘

Me.Cursor.Position = New Point(xx1, yy1)   
yy = 1
Exit  For
End  If
Next  xx
If  yy = 1 Then
Exit For
End  If
Next  yy
End  Sub
End  Class
 


Please help if im submitting this wrong let me know how I can fix it

Is This A Good Question/Topic? 0
  • +

Replies To: Remove warning

#2 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 448
  • View blog
  • Posts: 3,103
  • Joined: 12-January 10

Re: Remove warning

Posted 29 August 2013 - 01:43 PM

you need to post the error
Was This Post Helpful? 0
  • +
  • -

#3 penny_075  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 26-August 13

Re: Remove warning

Posted 29 August 2013 - 02:18 PM

View PostDarenR, on 29 August 2013 - 01:43 PM, said:

you need to post the error



should i remove the other code and just show the warning and the code that is causing the warning?
I can repost it just looking for help
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,155
  • Joined: 12-June 08

Re: Remove warning

Posted 29 August 2013 - 02:20 PM

Yes.. posting the error and relevant code is always helpful.
Was This Post Helpful? 0
  • +
  • -

#5 penny_075  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 26-August 13

Re: Remove warning

Posted 29 August 2013 - 02:25 PM

View Postmodi123_1, on 29 August 2013 - 02:20 PM, said:

Yes.. posting the error and relevant code is always helpful.



Ok Im going to remove this post and repost


Thanks
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,155
  • Joined: 12-June 08

Re: Remove warning

Posted 29 August 2013 - 02:31 PM

What? Why? Just post it here.. Keep the thread together.
Was This Post Helpful? 0
  • +
  • -

#7 penny_075  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 26-August 13

Re: Remove warning

Posted 29 August 2013 - 02:41 PM

Ok I will post here

thanks again
Was This Post Helpful? 0
  • +
  • -

#8 penny_075  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 26-August 13

Re: Remove warning

Posted 29 August 2013 - 08:05 PM

Sorry its late no access to vb at work horrible I know

here's MY error

access of shared member, constant member, enum member or nested type through an instance, qualifying expression will not be evaluated



Posted Image
Was This Post Helpful? 0
  • +
  • -

#9 penny_075  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 26-August 13

Re: Remove warning

Posted 30 August 2013 - 07:20 PM

No answer yet

Do you guys have any questions about it

If you need to see how it works

I posted a video on YouTube fast forward to the end to seek how it works

you tube link


Maybe seeing it will help.

or if you can tell me how I can replace this code with something else

 Me.Cursor.Position = New Point(xx1, yy1)    


Thanks again
Was This Post Helpful? 0
  • +
  • -

#10 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1052
  • View blog
  • Posts: 4,077
  • Joined: 02-July 08

Re: Remove warning

Posted 30 August 2013 - 10:00 PM

How about:

Windows.Forms.Cursor.Position = New Point(xx1, yy1)

Was This Post Helpful? 1
  • +
  • -

#11 penny_075  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 26-August 13

Re: Remove warning

Posted 31 August 2013 - 04:45 AM

View Post_HAWK_, on 30 August 2013 - 10:00 PM, said:

How about:

Windows.Forms.Cursor.Position = New Point(xx1, yy1)




Works Perfectly No warnings no Errors. Happy day You have made my weekend friend and its a 3 day weekend.
Love this forum
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1