Taskbar Code small problem
Posted: Fri Mar 15, 2013 8:31 pm
I am trying to use a sender.text to read and show a form here is the code for the button click
with the sender in it
and here is the code for bringinig it to front and adding the button in the first place :P
with the sender in it
Code: Select all
Private Sub btnpress(ByVal sender As System.Object, ByVal e As System.EventArgs)
Try
Dim procArray() As System.Diagnostics.Process
procArray = System.Diagnostics.Process.GetProcessesByName(sender.text)
If procArray.Length > 0 Then
ShowPreviousInstance(procArray(0).MainWindowHandle)
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
and here is the code for bringinig it to front and adding the button in the first place :P
Code: Select all
Private Sub BackTrackBrowserButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackTrackBrowserButton1.Click
BackTrackListBox1.Items.Clear()
For Each p As Process In Process.GetProcesses
If p.MainWindowTitle <> "" Then BackTrackListBox1.Items.Add(p.MainWindowTitle)
Next
BackTrackMenuStrip1.Items.Clear()
Dim btnTop As Integer = 0
For i As Integer = 0 To BackTrackListBox1.Items.Count - 1
Dim btn As New ToolStripButton
btn.Text = BackTrackListBox1.Items(i).ToString()
btn.Tag = i
AddHandler btn.Click, AddressOf btnpress
BackTrackMenuStrip1.Items.Add(btn)
btnTop += 30
Next
End Sub
Private SW_RESTORE As Integer = 9
Private Declare Auto Function IsIconic Lib "user32" (ByVal hWnd As IntPtr) As Boolean
Private Declare Auto Function SetForegroundWindow Lib "user32" (ByVal hwnd As IntPtr) As Long
Private Declare Auto Function ShowWindow Lib "user32" (ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As IntPtr
Private Function ShowPreviousInstance(ByVal handle As IntPtr) As Boolean
If handle.ToInt32 <> IntPtr.Zero.ToInt32 Then
Try
If IsIconic(handle) Then
ShowWindow(handle, SW_RESTORE)
End If
SetForegroundWindow(handle)
ShowPreviousInstance = True
Catch ex As System.Exception
ShowPreviousInstance = False
End Try
Else
ShowPreviousInstance = False
End If
End Function