Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6656471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:38:51+00:00 2026-05-26T01:38:51+00:00

I have a window that I need to activate and the window name does

  • 0

I have a window that I need to activate and the window name does not work in AppActivate(“WindowName”) because this does not work with partial captions etc… and the window name will be different depending on user. That being said I am able to use “GetwindowhandlefromPartialCaption” to retrieve the # value of the window name or handle. Is there a way to convert this or extract the name from the handle ID to use with AppActivate?

The code I’m using to get the handle ID is as follows:

 Public Class Form1



<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function GetWindowText(ByVal hwnd As IntPtr, ByVal lpString As StringBuilder, ByVal cch As Integer) As Integer
End Function

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function GetWindowTextLength(ByVal hwnd As IntPtr) As Integer
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SetWindowText(ByVal hwnd As IntPtr, ByVal lpString As String) As Boolean
End Function
Declare Auto Function GetWindow Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal uCmd As UInt32) As IntPtr


Private Function GetHandleFromPartialCaption(ByRef lWnd As Long, ByVal sCaption As String) As Boolean
    Dim lhWndP As Long
    GetHandleFromPartialCaption = False

    lhWndP = FindWindow(vbNullString, vbNullString) 'PARENT WINDOW
    Do While lhWndP <> 0
        Dim length As Integer = GetWindowTextLength(lhWndP)
        If length > 0 Then
            Dim sStr As New StringBuilder("", length + 1)
            GetWindowText(lhWndP, sStr, sStr.Capacity)
            If sStr.ToString.Contains(sCaption) Then
                GetHandleFromPartialCaption = True
                lWnd = lhWndP
                Exit Do
            End If
        End If

        lhWndP = GetWindow(lhWndP, GetWindow_Cmd.GW_HWNDNEXT)
    Loop
End Function

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


    Dim lhWndP As Long
    If GetHandleFromPartialCaption(lhWndP, "Navilink") = True Then
        MsgBox("Found Window Handle: " & lhWndP, vbOKOnly + vbInformation)
    Else
        MsgBox("Window 'Target App -'", vbOKOnly + vbExclamation)
    End If



End Sub

Private Function GetAllHandleCaptions(ByRef lWnd As Long) As Boolean
    Dim lhWndP As Long

    lhWndP = GetWindow(lWnd, GetWindow_Cmd.GW_CHILD)
    Do While lhWndP <> 0
        Dim length As Integer = GetWindowTextLength(lhWndP)
        If length > 0 Then
            Dim sStr As New StringBuilder("", length + 1)
            GetWindowText(lhWndP, sStr, sStr.Capacity)
            TextBox1.Text = TextBox1.Text + sStr.ToString() + " - " + lhWndP.ToString(+System.Environment.NewLine)
        End If

        lhWndP = GetWindow(lhWndP, GetWindow_Cmd.GW_HWNDNEXT)
    Loop
End Function



 End Class

The simple code I would love to get working is as follows:

 ' Grab the text highlighted in the other program.
Private Sub Command1_Click()
' Activate the other program.
AppActivate ("Applicationname")

' Clear the clipboard.
Clipboard.Clear

' Press Control.
keybd_event VK_CONTROL, 0, 0, 0
DoEvents

' Press C.
keybd_event VK_C, 1, 0, 0
DoEvents

' Release Control.
keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0
DoEvents

' Get the text from the clipboard.
Text1.Text = Clipboard.GetText

I think it should work if i can somehow use the code to get the window text again and pass
that to the AppActivate. Just not sure how to do it.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:38:51+00:00Added an answer on May 26, 2026 at 1:38 am

    AppActivate calls SetForegroundWindow , so you can try calling it yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If not, then does WinRT have its own Garbage Collector? I ask this because
I have a program that I need to run under *nix and windows. because
I am fairly new to jQuery and I have this overlay window that pops
I have an openGL window that is 640x480 that I need to center in
We have various php projects developed on windows (xampp) that need to be deployed
I have a long URL on a web page in Windows that I need
I have a Windows CGI created with Delphi 2007 using CGIExpert that I need
I have a large database table that I need to display on a Windows
I am a windows dev, but I have recently found that I need to
I have a window that is set with NSBorderlessWindowMask, and also kCGDesktopWindowLevel. When a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.