Question[Help]GetAsyncKeyState

Posts 1–8 of 8 · Page 1 of 1
[Help]GetAsyncKeyState
I Need help with the Cross Hair Tut it says If KeyPress im trying to change it to If getAsyncKeyState (VK_F11) Turn on..

but it says VK_F11 isnt Declaired.. can someone help me.. here is the code

[php]Public Class Form1
Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Int32) As UShort

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call PutWindowOnTop(Form2)
Form2.Show()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call PutWindowOnTop(Form2)
Form2.Hide()

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If GetAsyncKeyState(VK_F11) Then
Call PutWindowOnTop(Form2)
Form2.Show()
End If
End Sub
End Class[/php]
Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick 
       
dim f11 as boolean

        f11 = GetAsyncKeyState(Keys.F11)

        If f11 = True Then
            Call PutWindowOnTop(Form2) 
            Form2.Show() 
        End If 
end sub
ok ty.. also 1 other thing.. with the module i get an error

[php]Module Module1

Private Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, _
ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Const HWND_TOPMOST = -1
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1


Public Function PutWindowOnTop(ByVal pFrm As Form)
Dim lngWindowPosition As Long

LngWindowPosition = SetWindowPos(pFrm.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)

End Function

End Module[/php]


RED color = error

Error 1 'hwnd' is not a member of 'System.Windows.Forms.Form'. C:\Users\I Love Amanda\AppData\Local\Temporary Projects\Cross Hair\Module1.vb 15 42 Cross Hair
@blubb, good workaround, you shouldn't however need a flag


hwnd in vb.net is Handle

So form1.handle

didn't i answer that already?
Nope.. well not sure. :S sorry if u did


form1.handle or

module1.handle?
Someone pm(ed) me same question, thought it was you

pfrm.hwnd should be me.handle or if it's in a module it should be the formname.handle so pfrm.handle or form1.handle
So where it says "(pFrm.hwnd,"

i change the (pFrm.hwnd,) to module1.handle..

Sorry im alittle confused
Sorry For Double Post.. when i de.bug everything i only get a little tiny Dot..

Here is all codes for forms/modules

Form 1
[php]ublic Class Form1
Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Int32) As UShort

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call PutWindowOnTop(Form2)
Form2.Show()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call PutWindowOnTop(Form2)
Form2.Hide()

End Sub

Dim f11 As Boolean

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

f11 = GetAsyncKeyState(Keys.F11)

If f11 = True Then
Call PutWindowOnTop(Form2)
Form2.Show()
End If
End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If GetAsyncKeyState(Keys.F12) Then
Call PutWindowOnTop(Form2)
Form2.Hide()
End If
End Sub
End Class[/php]

Form 2


Module Form

[php]Module Module1

Private Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, _
ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Const HWND_TOPMOST = -1
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1


Public Function PutWindowOnTop(ByVal pFrm As Form)
Dim lngWindowPosition As Long

lngWindowPosition = SetWindowPos(pFrm.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)


End Function

End Module
[/php]

and all it shows is a tiny little Dot Top left corner :S

Posts 1–8 of 8 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us