Make external application 'TopMost'

xjamesfx

Member
Joined
Apr 3, 2011
Messages
12
Programming Experience
Beginner
Hi, Im looking to create a very simple application that you can use to set which window yu want on top.

The user opens my application and chooses from a combobox of currently opened windows, selects one and the selected window will be set to TopMost, so that whatever any other windows are doing that one will always be on top.

Is it at all possible to do this?

Cheers,
James
 
To show a window you will have to use Windows API, this code worked for me:

Private Sub bringWindowToFront(ByVal procName As String)
Dim procArray() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName(procName)
    If procArray.Length > 0 Then
        Dim i As Integer = 0
        For i = 0 To procArray.Length - 1
            If Not procArray(i).MainWindowTitle = "" Then ShowPreviousInstance(procArray(i).MainWindowHandle)
        Next
    End If
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


To get a list of open windows use something like this:

Private Function getOpenWindows() As String()
    Dim l As New List(Of String)
    For Each proc As Process In Process.GetProcesses
        If Not proc.MainWindowTitle = "" Then
            l.Add(proc.MainWindowTitle)
            'Or: l.Add(proc.ProcessName)
        End If
    Next
    Return l.ToArray
End Function


Hope this helps
-Josh
 
Application to make current open windows TopMost

I want to create a program that has a single form with a list of the current windows open and the user can select the window to make TopMost (alot like DeskPins: DeskPins - Free software downloads and software reviews - CNET Downloads)

The problem is i have no idea how to go about doing this, any help would be welcome but if you post any code, could you please give me some instructions on implementing it becuase im very new to vb.

Thanks!
 
Answer is in my previous post, research that.
 
Back
Top