How to determine when a user switches from your application to another RRS feed

  • Question

  • The question stands in the title.

    I want to know when a user moves away from my application to another application, I don't care which other application or how he does that, I just want to know when he does it so I can safely hide some windows which are supposed to stay top most in my application.

    Friday, April 3, 2015 7:43 AM


  • An application receives the WM_ACTIVATEAPP  message whenever it's being (de)activated. You can override WndProc and handle the message:

    Public Class Form1
       Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
          Const WM_ACTIVATEAPP As Integer = &H1C
          Select Case m.Msg
             Case WM_ACTIVATEAPP
                Debug.Print(If(m.WParam.ToInt64 = 0, "deactivated", "activated"))
          End Select
       End Sub
    End Class


    • Edited by Armin Zingler Friday, April 3, 2015 11:01 AM
    • Marked as answer by mcosmin Friday, April 3, 2015 11:42 AM
    Friday, April 3, 2015 11:01 AM