The problem is, it didn't fail. So i ask, if i use the right api call. Or is there a better way to copy a string to a other textbox on a foreight form/app, then the "SendMessageW" API call?
Seek51
Posts
-
Send String/Text to a other window [vb.net / API] -
Send String/Text to a other window [vb.net / API]Hello, I want to send a message/test to a other windows. It should save me many time in putting me many time strings/textes in MS Project, Outlook, ... ... Therefore i want to use the Windwos API in VB.net. I tried it in this way, but it doesn't work. I get the windows handle, but the text isn't set at notepad or in a other window.
Private Sub tmr_Worktimer_Tick(sender As Object, e As EventArgs) Handles tmr_Worktimer.Tick
If IsKeyPressed(Keys.VK_SHIFT) Then
Dim aPoint As New POINTAPI
GetCursorPos(aPoint)
Dim hWnd As IntPtr = WindowFromPoint(aPoint.x, aPoint.y)
SetForegroundWindow(hWnd)
SetWindowTextUnicode(hWnd, WM_SETTEXT, IntPtr.Zero, "Test")
End If
End SubMy API Calls are:
Public Structure Keys
Const VK_BACK As Short = &H8 ' Backspace key
Const VK_TAB As Short = &H9 ' Tab key
Const VK_RETURN As Short = &HD ' Enter key
Const VK_SHIFT As Short = &H10 ' Shift key
Const VK_CONTROL As Short = &H11 ' STRG key
Const VK_MENU As Short = &H12 ' Alt key
Const VK_CAPITAL As Short = &H14 ' Caps Lock
Const VK_ESCAPE As Short = &H1B ' Escape
Const VK_SPACE As Short = &H20 ' Space
Const VK_PRIOR As Short = &H21 ' PageUp
Const VK_NEXT As Short = &H22 ' PageDown
End StructurePublic Function GetAsyncKeyState(ByVal vKey As Int32) As Short End Function
Public Function IsKeyPressed(ByVal KeyToCheck As Short) As Boolean
Dim res As Short
res = GetAsyncKeyState(KeyToCheck)
If res < 0 Then ' -32768 Then
IsKeyPressed = True
Else
IsKeyPressed = False
End If
End FunctionPublic Structure POINTAPI Dim x As Integer Dim y As Integer End Structure Public Function GetCursorPos(ByRef lpPoint As POINTAPI) As Boolean End Function Public Function WindowFromPoint(xPoint As Integer, yPoint As Integer) As IntPtr End Function Public Function SetForegroundWindow(hWnd As IntPtr) As Boolean End Fun