none
How do I determine if another app has its window minimized RRS feed

  • Question

  • I need to know if a user has used another app and minimized it before continuing, how do I do this

    Wednesday, January 23, 2013 4:41 AM

Answers

  • I upgraded the app to get main window handles of multiple instances of a single application like notepad for example. Anyhow it still is confused with multiple instances of Internet Explorer in minimized state it still returns a false for each window handle which is wrong. Anyhow supposedly Wuser32 and Explorer are always running so they are disregarded and I added Internet Explorer to be disregarded since it returns inaccurate information.

    Public Class Form1
    
        Private Declare Auto Function IsIconic Lib "user32.dll" (ByVal hwnd As IntPtr) As Boolean
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            RichTextBox1.Text = ""
    
            Dim pr As New List(Of Process)(System.Diagnostics.Process.GetProcesses)
            For Each Item As Process In pr
                If Not Item.MainWindowHandle.ToInt32 = 0 Then
                    If Not Item.ProcessName = "Wuser32" And Not Item.ProcessName = "explorer" And Not Item.ProcessName = "iexplore" Then
                        RichTextBox1.AppendText(Item.ProcessName & "..." & Item.MainWindowHandle.ToString & "..." & Item.MainWindowTitle.ToString & "..." & IsIconic(Item.MainWindowHandle).ToString & vbCrLf)
    
                    End If
                End If
            Next
    
        End Sub
    
        Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged
    
        End Sub
    
    End Class



    You've taught me everything I know but not everything you know.


    • Edited by Mr. Monkeyboy Wednesday, January 23, 2013 9:20 AM
    • Marked as answer by x38class Saturday, January 26, 2013 8:54 AM
    Wednesday, January 23, 2013 9:09 AM

All replies

  • What if the user has another app and it is hidden or has an opacity of 0? And are you trying to display a list of minimized applications on the desktop?

    You've taught me everything I know but not everything you know.

    Wednesday, January 23, 2013 5:16 AM
  • Hi x38class,

    You can follow this link , it may help you :
    http://stackoverflow.com/questions/11065026/get-window-state-of-another-process

    And you can convert code from C# to VB from this link:

    http://www.developerfusion.com/tools/convert/csharp-to-vb/

    ---------------------------------

    I hope this post helps you , Mohamed Elghamry


    Wednesday, January 23, 2013 7:07 AM
  • This will tell you whether desktop applications are minimized or not (true or false) by their process name. Although I noticed if I had two instances of Internet Explorer running it only shows one instance and if both instances of IE are minimized it returns false which is wrong.

    Anyhow

    Public Class Form1
    
        Private Declare Auto Function IsIconic Lib "user32.dll" (ByVal hwnd As IntPtr) As Boolean
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            RichTextBox1.Text = ""
    
            Dim processes As Process() = Process.GetProcesses()
    
            For Each item In processes
                If item.MainWindowTitle.Length > 0 Then
                    Dim hWnd As IntPtr = Process.GetProcessesByName(item.ProcessName.ToString)(0).MainWindowHandle
                    RichTextBox1.AppendText(item.ProcessName.ToString & " " & IsIconic(hWnd).ToString & vbCrLf)
                End If
            Next
    
        End Sub
    
        Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged
    
        End Sub
    
    End Class

    This is with on instance of IE running in minimized state and my application Test20 in normal state.


    You've taught me everything I know but not everything you know.

    Wednesday, January 23, 2013 7:22 AM
  • I upgraded the app to get main window handles of multiple instances of a single application like notepad for example. Anyhow it still is confused with multiple instances of Internet Explorer in minimized state it still returns a false for each window handle which is wrong. Anyhow supposedly Wuser32 and Explorer are always running so they are disregarded and I added Internet Explorer to be disregarded since it returns inaccurate information.

    Public Class Form1
    
        Private Declare Auto Function IsIconic Lib "user32.dll" (ByVal hwnd As IntPtr) As Boolean
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            RichTextBox1.Text = ""
    
            Dim pr As New List(Of Process)(System.Diagnostics.Process.GetProcesses)
            For Each Item As Process In pr
                If Not Item.MainWindowHandle.ToInt32 = 0 Then
                    If Not Item.ProcessName = "Wuser32" And Not Item.ProcessName = "explorer" And Not Item.ProcessName = "iexplore" Then
                        RichTextBox1.AppendText(Item.ProcessName & "..." & Item.MainWindowHandle.ToString & "..." & Item.MainWindowTitle.ToString & "..." & IsIconic(Item.MainWindowHandle).ToString & vbCrLf)
    
                    End If
                End If
            Next
    
        End Sub
    
        Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged
    
        End Sub
    
    End Class



    You've taught me everything I know but not everything you know.


    • Edited by Mr. Monkeyboy Wednesday, January 23, 2013 9:20 AM
    • Marked as answer by x38class Saturday, January 26, 2013 8:54 AM
    Wednesday, January 23, 2013 9:09 AM
  • Thanks for that, will try it out and get back to you
    Thursday, January 24, 2013 4:54 AM
  • OK, works fine for me as I know only one app is running, however

    Using task manager these items appear there, however I now need to know if an app is running which is not shown in task manager/applications but task manager/processes

    This item is shown in the rhs of the task bar where the speaker control is, ie minimized but in the task bar

    How do I get to know if a PROCESS is running, rather than an application

    Saturday, January 26, 2013 4:30 AM
  • Your app works fine, if you run taskmanager you will find the items you listed as Applications

    If you click processes you will find many items, one of which will be winlogon.exe

    of the other processes shown I want to find out if my chosen app  is in the process list

    So, yes my question now is being expanded to check running processes (only if they are running, not minimized)

    Saturday, January 26, 2013 6:05 AM
  • Sorry about my previous two posts. I was replying regarding a completely different thread.

    So now you want to check all running process to find out if your chosen app is in the process list? O.K.

    Sorry for the confusion. I'll get back to you on that.


    You've taught me everything I know but not everything you know.

    Saturday, January 26, 2013 6:36 AM
  • Public Class Form1
    
        Private Declare Auto Function IsIconic Lib "user32.dll" (ByVal hwnd As IntPtr) As Boolean
    
    
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ListBox1.Sorted = True
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim psList() As Process
            Try
                psList = Process.GetProcesses()
    
                For Each p As Process In psList
                    ListBox1.Items.Add(p.ProcessName & "............." & p.Id.ToString)
                Next p
    
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Sub
    
        Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
    
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            TextBox2.Text = ""
            Dim psList() As Process
            Try
                psList = Process.GetProcessesByName(TextBox1.Text)
    
                If psList.Length > 0 Then
                    For Each P In psList
                        TextBox2.AppendText(P.ProcessName & "....." & P.Id.ToString & ".....")
                        If IsIconic(P.MainWindowHandle) = True Then
                            TextBox2.AppendText("is in minimized state" & vbCrLf)
                        ElseIf IsIconic(P.MainWindowHandle) = False Then
                            TextBox2.AppendText("is not in minimized state" & vbCrLf)
                        End If
                    Next
                Else
                    TextBox2.Text = "App is not in process list"
                End If
            Catch ex As Exception
                TextBox2.Text = ex.Message
            End Try
        End Sub
    
        Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
    
        End Sub
    
        Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
    
        End Sub
    
        Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
    
        End Sub
    
        Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
    
        End Sub
    
        Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click
    
        End Sub
    End Class


    You've taught me everything I know but not everything you know.

    Saturday, January 26, 2013 7:33 AM
  • Looks just what I need, thanks

    Will copy & test in my app and get back in about 18 hours

    I must say, your efforts in trying to assist is most welcome & appreciated

    Saturday, January 26, 2013 8:52 AM
  • Thanks.

    You've taught me everything I know but not everything you know.

    Saturday, January 26, 2013 9:15 AM
  • It's a slow process for me to get back to this issue, although most of your code is fine, I now find another problem I hope you can help with

    What I need to know now is whether a process is minimzed in the task bar, not the general area where, say notepad would reside. I have an app called eraser which is shown in the rhs of the taskbar as an icon, not an application like notepad.

    I aslo have my Virgin Mobile internet connection shown as an icon in the task bar (RHS) when it is minimized, not in the general middle taskbar area

    Wednesday, February 13, 2013 4:47 AM
  • It's a slow process for me to get back to this issue, although most of your code is fine, I now find another problem I hope you can help with

    What I need to know now is whether a process is minimzed in the task bar, not the general area where, say notepad would reside. I have an app called eraser which is shown in the rhs of the taskbar as an icon, not an application like notepad.

    I aslo have my Virgin Mobile internet connection shown as an icon in the task bar (RHS) when it is minimized, not in the general middle taskbar area


    Please start a new thread for this question. Thanks.

    You've taught me everything I know but not everything you know.

    Wednesday, February 13, 2013 4:58 AM