Click here to Skip to main content
15,796,456 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
PinnedHOW TO ANSWER A QUESTION Pin
Chris Maunder16-Jul-09 4:09
cofounderChris Maunder16-Jul-09 4:09 
PinnedHow to get an answer to your question Pin
Chris Maunder16-Jul-09 4:05
cofounderChris Maunder16-Jul-09 4:05 
QuestionSend String/Text to a other window [vb.net / API] Pin
Seek514-Dec-23 22:01
Seek514-Dec-23 22:01 
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.



BASIC
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 Sub



My API Calls are:
BASIC
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 Structure

 <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
    Public 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 Function
	
	    <System.Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential)>
    Public Structure POINTAPI
        Dim x As Integer
        Dim y As Integer
    End Structure
	
	    <DllImport("user32.dll", ExactSpelling:=True, SetLastError:=True)>
    Public Function GetCursorPos(ByRef lpPoint As POINTAPI) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function
	
	    <DllImport("user32.dll")>
    Public Function WindowFromPoint(xPoint As Integer, yPoint As Integer) As IntPtr
    End Function
	
	    <DllImport("user32.dll")>
    Public Function SetForegroundWindow(hWnd As IntPtr) As Boolean
    End Function
	
	    Friend Const WM_SETTEXT As Integer = 12

    <DllImport("user32.dll", EntryPoint:="SendMessageW", CharSet:=CharSet.Unicode)>
    Public Function SetWindowTextUnicode(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr
    End Function



Any ideas? Is there a other way to send the string/text?
AnswerRe: Send String/Text to a other window [vb.net / API] Pin
Richard MacCutchan4-Dec-23 23:15
mveRichard MacCutchan4-Dec-23 23:15 
GeneralRe: Send String/Text to a other window [vb.net / API] Pin
Seek515-Dec-23 0:55
Seek515-Dec-23 0:55 
GeneralRe: Send String/Text to a other window [vb.net / API] Pin
Richard MacCutchan5-Dec-23 1:01
mveRichard MacCutchan5-Dec-23 1:01 
GeneralRe: Send String/Text to a other window [vb.net / API] Pin
jschell5-Dec-23 6:12
jschell5-Dec-23 6:12 
AnswerRe: Send String/Text to a other window [vb.net / API] Pin
jschell5-Dec-23 6:15
jschell5-Dec-23 6:15 
AnswerRe: Send String/Text to a other window [vb.net / API] Pin
Gerry Schmitz5-Dec-23 7:30
mveGerry Schmitz5-Dec-23 7:30 
AnswerRe: Send String/Text to a other window [vb.net / API] Pin
Andre Oosthuizen5-Dec-23 9:43
mveAndre Oosthuizen5-Dec-23 9:43 
QuestionLibVLCSharp hosted in mcr.microsoft.com/dotnet/aspnet:6.0 Docker image inside a linux context Pin
etodemerzel30-Nov-23 12:29
etodemerzel30-Nov-23 12:29 
AnswerRe: LibVLCSharp hosted in mcr.microsoft.com/dotnet/aspnet:6.0 Docker image inside a linux context Pin
Gerry Schmitz30-Nov-23 16:53
mveGerry Schmitz30-Nov-23 16:53 
QuestionHow to "update" old .NET code to current versions Pin
lewist5730-Nov-23 11:38
lewist5730-Nov-23 11:38 
QuestionRe: How to "update" old .NET code to current versions Pin
Ralf Meier30-Nov-23 12:26
professionalRalf Meier30-Nov-23 12:26 
AnswerRe: How to "update" old .NET code to current versions Pin
Gerry Schmitz30-Nov-23 16:44
mveGerry Schmitz30-Nov-23 16:44 
AnswerRe: How to "update" old .NET code to current versions Pin
Richard Deeming30-Nov-23 22:50
mveRichard Deeming30-Nov-23 22:50 
AnswerRe: How to "update" old .NET code to current versions Pin
Richard MacCutchan30-Nov-23 23:09
mveRichard MacCutchan30-Nov-23 23:09 
AnswerRe: How to "update" old .NET code to current versions Pin
lewist571-Dec-23 3:50
lewist571-Dec-23 3:50 
GeneralRe: How to "update" old .NET code to current versions Pin
Richard MacCutchan1-Dec-23 4:34
mveRichard MacCutchan1-Dec-23 4:34 
GeneralRe: How to "update" old .NET code to current versions Pin
lewist571-Dec-23 4:53
lewist571-Dec-23 4:53 
GeneralRe: How to "update" old .NET code to current versions Pin
Richard MacCutchan1-Dec-23 5:27
mveRichard MacCutchan1-Dec-23 5:27 
GeneralRe: How to "update" old .NET code to current versions Pin
Andre Oosthuizen1-Dec-23 23:09
mveAndre Oosthuizen1-Dec-23 23:09 
GeneralRe: How to "update" old .NET code to current versions Pin
Richard MacCutchan1-Dec-23 23:18
mveRichard MacCutchan1-Dec-23 23:18 
GeneralRe: How to "update" old .NET code to current versions Pin
Andre Oosthuizen1-Dec-23 23:59
mveAndre Oosthuizen1-Dec-23 23:59 
GeneralRe: How to "update" old .NET code to current versions Pin
Dave Kreskowiak1-Dec-23 6:18
mveDave Kreskowiak1-Dec-23 6:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.