Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27329

VS 2010 How to find window and set focus on a specific part of it?

$
0
0
So i'm trying to set focus on a specific part of a window. After i did a little search, i found the following code..

Code:

Private Declare Function FindWindow _
        Lib "user32" _
        Alias "FindWindowA" _
      (ByVal lpClassName As String, _
        ByVal lpWindowName As String) As Long
 
Private Declare Function ShowWindow _
        Lib "user32" _
      (ByVal hwnd As Long, _
        ByVal nCmdShow As Long) As Long
 
Private Const SW_SHOWNORMAL = 1
Private Const SW_SHOWMINIMIZED = 2
Private Const SW_SHOWMAXIMIZED = 3
 
Private Sub Command1_Click()
Dim lHwnd As Long
    lHwnd = FindWindow("RichEdit20W", vbNullString)
 
    If lHwnd <> 0 Then
        MsgBox "Chat is open!", vbInformation, "Notepad"
        ShowWindow lHwnd, SW_SHOWNORMAL
    Else
        MsgBox "Notepad isn't open!", vbInformation, "Window not found."
    End If
End Sub


When i run it, it detect the window i am looking for, but i get this Exception whenever it reaches this line

Code:

lHwnd = FindWindow("RichEdit20W", vbNullString)

and this is the exception

A call to PInvoke function 'flooder!flooder.Form1::ShowWindow' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

Can anyone please check the code? and is there any other way to set a focus on a specific part of a window?
thanks!!

Viewing all articles
Browse latest Browse all 27329

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>