|
-
Jun 19th, 2015, 11:26 AM
#1
Thread Starter
New Member
[RESOLVED] for each line in textbox as string not working properly
hello, i made some code to show and hide virtualbox from the taskbar. but it currently works with 2 textboxes and 2 buttons and i want it to only use 1 textbox and not be limited to 2 inputs to hide the taskbar icon.
my code is the following:
Code:
Imports System.Runtime.InteropServices
Imports System.Threading
Public Class Form1
' This is 2 functions from user32.dll (1 for finding the application and 1 to set it to foreground with focus)
<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 SetForegroundWindow(ByVal hWnd As IntPtr) As Long
End Function
Private Sub Button1_Click(sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim lpszParentClass As String = "QWidget"
Dim lpszParentWindow As String = TextBox1.Text
Dim ParenthWnd As New IntPtr(0)
Dim lpszParentClass2 As String = "QWidget"
Dim lpszParentWindow2 As String = TextBox2.Text
Dim ParenthWnd2 As New IntPtr(0)
ParenthWnd2 = FindWindow(lpszParentClass2, lpszParentWindow2)
ParenthWnd = FindWindow(lpszParentClass, lpszParentWindow)
For Each p As System.Diagnostics.Process In System.Diagnostics.Process.GetProcessesByName("virtualbox")
If p.MainWindowTitle.Contains(TextBox1.Text) Then
TaskBarManager.HideProcessFromTaskBar(p.Id)
If ParenthWnd.Equals(IntPtr.Zero) Then
Else
SetForegroundWindow(ParenthWnd2)
TaskBarManager.HideProcessFromTaskBar(p.Id)
End If
End If
If p.MainWindowTitle.Contains(TextBox2.Text) Then
TaskBarManager.HideProcessFromTaskBar(p.Id)
If ParenthWnd2.Equals(IntPtr.Zero) Then
Else
SetForegroundWindow(ParenthWnd)
TaskBarManager.HideProcessFromTaskBar(p.Id)
End If
End If
Next
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim lpszParentClass As String = "QWidget"
Dim lpszParentWindow As String = TextBox1.Text
Dim ParenthWnd As New IntPtr(0)
Dim lpszParentClass2 As String = "QWidget"
Dim lpszParentWindow2 As String = TextBox2.Text
Dim ParenthWnd2 As New IntPtr(0)
ParenthWnd2 = FindWindow(lpszParentClass2, lpszParentWindow2)
ParenthWnd = FindWindow(lpszParentClass, lpszParentWindow)
For Each p As System.Diagnostics.Process In System.Diagnostics.Process.GetProcessesByName("virtualbox")
If p.MainWindowTitle.Contains(TextBox1.Text) Then
TaskBarManager.ShowProcessInTaskBar(p.Id)
If ParenthWnd.Equals(IntPtr.Zero) Then
Else
SetForegroundWindow(ParenthWnd2)
TaskBarManager.ShowProcessInTaskBar(p.Id)
End If
End If
If p.MainWindowTitle.Contains(TextBox2.Text) Then
TaskBarManager.ShowProcessInTaskBar(p.Id)
If ParenthWnd2.Equals(IntPtr.Zero) Then
Else
SetForegroundWindow(ParenthWnd)
TaskBarManager.ShowProcessInTaskBar(p.Id)
End If
End If
Next
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = My.Settings.textbox1
TextBox2.Text = My.Settings.textbox2
End Sub
Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
My.Settings.textbox1 = TextBox1.Text
End Sub
Private Sub TextBox2_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox2.TextChanged
My.Settings.textbox2 = TextBox2.Text
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
MsgBox(" there are 2 textboxes in the bottom, type the full window name in there, for example 'kali linux [Running] - Oracle VM VirtualBox' there is a second textbox wich is for if you have virtualbox setup with 2 virtual displays else just ignore it. if you have 2 displays put for example 'kali linux [Running] - Oracle VM VirtualBox : 1' in the first to hide the icon of the first virtual display, and for example 'kali linux [Running] - Oracle VM VirtualBox : 2' in the second display to hide the second display also! the textboxes will stay the same if you close and reopen the program and hiding the icon's keeps working after you closed the progarm. just make shure you type everything correct becouse i was to lazy to make errors and error mangagement ;p")
End Sub
End Class
Public Class TaskBarManager
<ComImport(), Guid("56fdf342-fd6d-11d0-958a-006097c9a090"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface ITaskbarList
Sub HrInit()
Sub AddTab(<[In]()> ByVal hWnd As IntPtr)
Sub DeleteTab(<[In]()> ByVal hWnd As IntPtr)
Sub ActivateTab(<[In]()> ByVal hWnd As IntPtr)
Sub SetActiveAlt(<[In]()> ByVal hWnd As IntPtr)
End Interface
<ComImport()> _
<Guid("56fdf344-fd6d-11d0-958a-006097c9a090")> _
Public Class CoTaskbarList
End Class
Public Shared Sub HideProcessFromTaskBar(ByVal PID As Integer)
Dim taskbarList As ITaskbarList = DirectCast(New CoTaskbarList(), ITaskbarList)
taskbarList.HrInit()
taskbarList.DeleteTab(Process.GetProcessById(PID).MainWindowHandle)
End Sub
Public Shared Sub ShowProcessInTaskBar(ByVal PID As Integer)
Dim taskbarList As ITaskbarList = DirectCast(New CoTaskbarList(), ITaskbarList)
taskbarList.HrInit()
taskbarList.AddTab(Process.GetProcessById(PID).MainWindowHandle)
End Sub
End Class
but all that is important is this (unless you know a way to make this easier becouse it is messy and a kind of hacky way to do it :/ )
Code:
Private Sub Button1_Click(sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim lpszParentClass As String = "QWidget"
Dim lpszParentWindow As String = TextBox1.Text
Dim ParenthWnd As New IntPtr(0)
Dim lpszParentClass2 As String = "QWidget"
Dim lpszParentWindow2 As String = TextBox2.Text
Dim ParenthWnd2 As New IntPtr(0)
ParenthWnd2 = FindWindow(lpszParentClass2, lpszParentWindow2)
ParenthWnd = FindWindow(lpszParentClass, lpszParentWindow)
For Each p As System.Diagnostics.Process In System.Diagnostics.Process.GetProcessesByName("virtualbox")
If p.MainWindowTitle.Contains(TextBox1.Text) Then
TaskBarManager.HideProcessFromTaskBar(p.Id)
If ParenthWnd.Equals(IntPtr.Zero) Then
Else
SetForegroundWindow(ParenthWnd2)
TaskBarManager.HideProcessFromTaskBar(p.Id)
End If
End If
If p.MainWindowTitle.Contains(TextBox2.Text) Then
TaskBarManager.HideProcessFromTaskBar(p.Id)
If ParenthWnd2.Equals(IntPtr.Zero) Then
Else
SetForegroundWindow(ParenthWnd)
TaskBarManager.HideProcessFromTaskBar(p.Id)
End If
End If
Next
End Sub
all of the above code already works but i am limited to hiding only 2 icons in the taskbar...
what i need to do is:
1: seperate each line in a textbox and dim it as a string (with for each)
2: now i need to set the foreground window in p to the first window, the multiline textbox contains the exact name of each windowtitle that needs to be hidden. (findwindow(nothing,textoflineintextbox) )
3: now i need to hide the main window of the virtualboxprocess (p) with taskbarmanager.hideprocessfromtaskbar(p.id)
4: the result should be that it will read the first line of the textbox and then sets the window with that windowtitle to the foreground (actually make it the main/parent window) and hide it in the taskbar. then continue to the next line in the textbox and again set the window with the windowtitle of that line to the foreground/make it main/parent window and hide it in the taskbar until it did all the lines in the multiline textbox. please help me out and sorry that i can't show the code i made when i tried this (if you want i could try to make the code thadt i used to try this, it shouldn't be that hard) but for some unknown reason would still only hide the main window. please help me out and ask me what i mean. if you dont get it, it is actually pretty simple but i can't really explain it that good i think.
anyways thanks in advance!
-
Jun 19th, 2015, 12:40 PM
#2
Re: for each line in textbox as string not working properly
Which part did you have a problem with?
If you want to read the lines, use the lines list.
Code:
For Each lin As String In TextBox1.Lines
Debug.Print(lin)
Next
Last edited by passel; Jun 19th, 2015 at 12:51 PM.
-
Jun 19th, 2015, 01:04 PM
#3
Thread Starter
New Member
Re: for each line in textbox as string not working properly
WOW THANK YOU SO MUTCH!!! i first tried to use
For Each line In TextBox1.Text.Split(vbNewLine)
and it worked with messageboxes ect... but it did not with my program... anyways, didn't seem to be that hard after all... i just did something wrong lel.
-
Jun 19th, 2015, 02:02 PM
#4
Re: for each line in textbox as string not working properly
 Originally Posted by N1C39UY
WOW THANK YOU SO MUTCH!!! i first tried to use
For Each line In TextBox1.Text.Split(vbNewLine)
and it worked with messageboxes ect... but it did not with my program... anyways, didn't seem to be that hard after all... i just did something wrong lel.
If you of read msdn textbox class you would see it has a lines property.
Code:
For Each line In TextBox1.Lines
-
Jun 20th, 2015, 07:36 AM
#5
Thread Starter
New Member
Re: [RESOLVED] for each line in textbox as string not working properly
i was reading in textbox1.text and not textbox1 oh and btw it's still kind of buggy but i will have to do with it.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|