hi all,
im kinda new to vb and i have code that unhides a hidden from on a key press
for some reason though this code only works when running th app through by,
ie. it wont work in the standalone program. Source code can be downloaded
from http://www.geocities.com/thecubical/temp.zip
source code
----------------------from form--------------------------
Private Sub Command1_Click()
Dim ip As String
ip = InputBox("Please enter the ip to send the message to", "Ip to send
to")
Winsock1.Close 'must close to stop error
Winsock1.Connect ip, 123 'connect to ip and port
End Sub
Private Sub Form_Load()
Winsock2.Close 'must close to stop error
Winsock2.LocalPort = 123
Winsock2.Listen 'listen for incoming messages
'set a keyboard hook
hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc,
App.hInstance, App.ThreadID)
End Sub
Private Sub Winsock1_Close()
On Local Error Resume Next
Winsock1.Close 'close winsock on error
End Sub
Private Sub Winsock1_Connect()
Dim message As String
message = InputBox("Please enter the message to send", "Type your
message")
Winsock1.SendData message 'send the message to client
End Sub
Private Sub Winsock2_Close()
Winsock2.Close 'boof
Winsock2.Listen 'boof
End Sub
Private Sub Winsock2_ConnectionRequest(ByVal requestID As Long)
'boof
If Winsock2.State <> sckConnected Then
Winsock2.Close
End If
'end boof
Winsock2.Accept requestID 'accept connection to server
End Sub
Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
Dim arriving_message As String
Winsock2.GetData arriving_message 'accept a message from server
MsgBox arriving_message 'print message in msgbox
End Sub
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String,
ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal
HelpContext As Long, CancelDisplay As Boolean)
MsgBox "Error " & Description, vbOKOnly + vbExclamation
End Sub
Private Sub Winsock1_SendComplete()
Winsock1.Close 'when server finished sending message
close connection
End Sub
Private Sub Winsock2_Error(ByVal Number As Integer, Description As String,
ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal
HelpContext As Long, CancelDisplay As Boolean)
On Local Error Resume Next ' boof
MsgBox "Error " & Description, vbOKOnly + vbExclamation
Winsock2.Listen 'boof
End Sub
Private Sub Winsock2_SendComplete()
On Local Error Resume Next
Winsock1.Close 'when client finished getting message
close connection
End Sub
Private Sub Form_Unload(Cancel As Integer)
'remove the windows-hook
UnhookWindowsHookEx hHook
Winsock1.Close 'close winsocks on exit
Winsock2.Close
End Sub
------------------------from module---------------------
'In a module
Public Const WH_KEYBOARD = 2
Public Const VK_SHIFT = &H10
Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal
ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As
Integer
Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA"
(ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal
dwThreadId As Long) As Long
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As
Long
Public hHook As Long
Public Function KeyboardProc(ByVal idHook As Long, ByVal wParam As Long,
ByVal lParam As Long) As Long
'if idHook is less than zero, no further processing is required
If idHook < 0 Then
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
Else
'check if SHIFT-S is pressed
If (GetKeyState(VK_SHIFT) And &HF0000000) And wParam = Asc("S") Then
'show the result
Form1.Show
ElseIf (GetKeyState(VK_SHIFT) And &HF0000000) And wParam = Asc("D")
Then
Form1.Hide
End If
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
End If
End Function
----------------------------------------------------------
thanks for any help