How to make a window active in vb.net












-1















So I'm working on a program that types into an open application that has no api. So I need to select that window so my program will type into it. I'm using this code and it can't find the proccess.



Dim windowHandle As IntPtr = FindWindow("LolClient", "League of Legends (TM) Client")
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As IntPtr
SetForegroundWindow(windowHandle)

SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait(ComboBox1.Text)
SendKeys.SendWait("{Enter}")









share|improve this question























  • You should try looking into the Process Class, in many cases it's much easier to work with.

    – tinstaafl
    Jan 10 '14 at 0:24
















-1















So I'm working on a program that types into an open application that has no api. So I need to select that window so my program will type into it. I'm using this code and it can't find the proccess.



Dim windowHandle As IntPtr = FindWindow("LolClient", "League of Legends (TM) Client")
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As IntPtr
SetForegroundWindow(windowHandle)

SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait(ComboBox1.Text)
SendKeys.SendWait("{Enter}")









share|improve this question























  • You should try looking into the Process Class, in many cases it's much easier to work with.

    – tinstaafl
    Jan 10 '14 at 0:24














-1












-1








-1








So I'm working on a program that types into an open application that has no api. So I need to select that window so my program will type into it. I'm using this code and it can't find the proccess.



Dim windowHandle As IntPtr = FindWindow("LolClient", "League of Legends (TM) Client")
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As IntPtr
SetForegroundWindow(windowHandle)

SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait(ComboBox1.Text)
SendKeys.SendWait("{Enter}")









share|improve this question














So I'm working on a program that types into an open application that has no api. So I need to select that window so my program will type into it. I'm using this code and it can't find the proccess.



Dim windowHandle As IntPtr = FindWindow("LolClient", "League of Legends (TM) Client")
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As IntPtr
SetForegroundWindow(windowHandle)

SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait(ComboBox1.Text)
SendKeys.SendWait("{Enter}")






vb.net windows






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 9 '14 at 23:59









SuicidalCookieSuicidalCookie

1613




1613













  • You should try looking into the Process Class, in many cases it's much easier to work with.

    – tinstaafl
    Jan 10 '14 at 0:24



















  • You should try looking into the Process Class, in many cases it's much easier to work with.

    – tinstaafl
    Jan 10 '14 at 0:24

















You should try looking into the Process Class, in many cases it's much easier to work with.

– tinstaafl
Jan 10 '14 at 0:24





You should try looking into the Process Class, in many cases it's much easier to work with.

– tinstaafl
Jan 10 '14 at 0:24












1 Answer
1






active

oldest

votes


















6














Try this:



Public Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Integer) As Integer
Public Declare Auto Function FindWindow Lib "user32.dll" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function IsIconic Lib "user32.dll" (ByVal hwnd As Integer) As Boolean
Public Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer

Public Const SW_RESTORE As Integer = 9
Public Const SW_SHOW As Integer = 5


Sub FocusWindow(ByVal strWindowCaption As String, ByVal strClassName As String)
Dim hWnd As Integer
hWnd = FindWindow(strClassName, strWindowCaption)

If hWnd > 0 Then
SetForegroundWindow(hWnd)

If IsIconic(hWnd) Then 'Restore if minimized
ShowWindow(hWnd, SW_RESTORE)
Else
ShowWindow(hWnd, SW_SHOW)
End If
End If
End Sub


To show the "Calculator" you can call FocusWindow("Calculator", Nothing) or FocusWindow(Nothing, "CalcFrame")






share|improve this answer
























  • Thank you! This was the missing link for my project.

    – LPChip
    Mar 24 '17 at 14:23











  • How would you select the window by process name rather than by window title?

    – Mark S
    Mar 11 at 14:14












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21033736%2fhow-to-make-a-window-active-in-vb-net%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









6














Try this:



Public Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Integer) As Integer
Public Declare Auto Function FindWindow Lib "user32.dll" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function IsIconic Lib "user32.dll" (ByVal hwnd As Integer) As Boolean
Public Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer

Public Const SW_RESTORE As Integer = 9
Public Const SW_SHOW As Integer = 5


Sub FocusWindow(ByVal strWindowCaption As String, ByVal strClassName As String)
Dim hWnd As Integer
hWnd = FindWindow(strClassName, strWindowCaption)

If hWnd > 0 Then
SetForegroundWindow(hWnd)

If IsIconic(hWnd) Then 'Restore if minimized
ShowWindow(hWnd, SW_RESTORE)
Else
ShowWindow(hWnd, SW_SHOW)
End If
End If
End Sub


To show the "Calculator" you can call FocusWindow("Calculator", Nothing) or FocusWindow(Nothing, "CalcFrame")






share|improve this answer
























  • Thank you! This was the missing link for my project.

    – LPChip
    Mar 24 '17 at 14:23











  • How would you select the window by process name rather than by window title?

    – Mark S
    Mar 11 at 14:14
















6














Try this:



Public Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Integer) As Integer
Public Declare Auto Function FindWindow Lib "user32.dll" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function IsIconic Lib "user32.dll" (ByVal hwnd As Integer) As Boolean
Public Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer

Public Const SW_RESTORE As Integer = 9
Public Const SW_SHOW As Integer = 5


Sub FocusWindow(ByVal strWindowCaption As String, ByVal strClassName As String)
Dim hWnd As Integer
hWnd = FindWindow(strClassName, strWindowCaption)

If hWnd > 0 Then
SetForegroundWindow(hWnd)

If IsIconic(hWnd) Then 'Restore if minimized
ShowWindow(hWnd, SW_RESTORE)
Else
ShowWindow(hWnd, SW_SHOW)
End If
End If
End Sub


To show the "Calculator" you can call FocusWindow("Calculator", Nothing) or FocusWindow(Nothing, "CalcFrame")






share|improve this answer
























  • Thank you! This was the missing link for my project.

    – LPChip
    Mar 24 '17 at 14:23











  • How would you select the window by process name rather than by window title?

    – Mark S
    Mar 11 at 14:14














6












6








6







Try this:



Public Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Integer) As Integer
Public Declare Auto Function FindWindow Lib "user32.dll" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function IsIconic Lib "user32.dll" (ByVal hwnd As Integer) As Boolean
Public Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer

Public Const SW_RESTORE As Integer = 9
Public Const SW_SHOW As Integer = 5


Sub FocusWindow(ByVal strWindowCaption As String, ByVal strClassName As String)
Dim hWnd As Integer
hWnd = FindWindow(strClassName, strWindowCaption)

If hWnd > 0 Then
SetForegroundWindow(hWnd)

If IsIconic(hWnd) Then 'Restore if minimized
ShowWindow(hWnd, SW_RESTORE)
Else
ShowWindow(hWnd, SW_SHOW)
End If
End If
End Sub


To show the "Calculator" you can call FocusWindow("Calculator", Nothing) or FocusWindow(Nothing, "CalcFrame")






share|improve this answer













Try this:



Public Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Integer) As Integer
Public Declare Auto Function FindWindow Lib "user32.dll" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function IsIconic Lib "user32.dll" (ByVal hwnd As Integer) As Boolean
Public Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer

Public Const SW_RESTORE As Integer = 9
Public Const SW_SHOW As Integer = 5


Sub FocusWindow(ByVal strWindowCaption As String, ByVal strClassName As String)
Dim hWnd As Integer
hWnd = FindWindow(strClassName, strWindowCaption)

If hWnd > 0 Then
SetForegroundWindow(hWnd)

If IsIconic(hWnd) Then 'Restore if minimized
ShowWindow(hWnd, SW_RESTORE)
Else
ShowWindow(hWnd, SW_SHOW)
End If
End If
End Sub


To show the "Calculator" you can call FocusWindow("Calculator", Nothing) or FocusWindow(Nothing, "CalcFrame")







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 10 '14 at 0:47









Dan TerkildsenDan Terkildsen

19614




19614













  • Thank you! This was the missing link for my project.

    – LPChip
    Mar 24 '17 at 14:23











  • How would you select the window by process name rather than by window title?

    – Mark S
    Mar 11 at 14:14



















  • Thank you! This was the missing link for my project.

    – LPChip
    Mar 24 '17 at 14:23











  • How would you select the window by process name rather than by window title?

    – Mark S
    Mar 11 at 14:14

















Thank you! This was the missing link for my project.

– LPChip
Mar 24 '17 at 14:23





Thank you! This was the missing link for my project.

– LPChip
Mar 24 '17 at 14:23













How would you select the window by process name rather than by window title?

– Mark S
Mar 11 at 14:14





How would you select the window by process name rather than by window title?

– Mark S
Mar 11 at 14:14




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21033736%2fhow-to-make-a-window-active-in-vb-net%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas