ImportsSystemImportsSystem.Drawing
ImportsSystem.Windows.Forms
PublicClass Form1
InheritsSystem.Windows.Forms.Form
' Constant value was found in the "windows.h" header file.PrivateConst WM_ACTIVATEAPP AsInteger=&H1C
Private appActive AsBoolean=True<STAThread()> _
SharedSub Main()
Application.Run(New Form1())EndSub'MainPublicSubNew()MyBase.New()
InitializeComponent()Me.Size=NewSystem.Drawing.Size(300,300)Me.Text="Form1"Me.Font =NewSystem.Drawing.Font("Microsoft Sans Serif",18.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))EndSubProtectedOverridesSub OnPaint(ByVal e As PaintEventArgs)' Paint a string in different styles depending on whether the' application is active.If(appActive)Then
e.Graphics.FillRectangle(SystemBrushes.ActiveCaption,20,20,260,50)
e.Graphics.DrawString("Application is active",Me.Font, SystemBrushes.ActiveCaptionText,20,20)Else
e.Graphics.FillRectangle(SystemBrushes.InactiveCaption,20,20,260,50)
e.Graphics.DrawString("Application is Inactive",Me.Font, SystemBrushes.ActiveCaptionText,20,20)EndIfEndSub<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand,Name:="FullTrust")> _
ProtectedOverridesSub WndProc(ByRef m As Message)' Listen for operating system messagesSelect Case(m.Msg)' The WM_ACTIVATEAPP message occurs when the application' becomes the active application or becomes inactive.Case WM_ACTIVATEAPP
' The WParam value identifies what is occurring.
appActive =(m.WParam.ToInt32()<>0)' Invalidate to get new text painted.Me.Invalidate()EndSelectMyBase.WndProc(m)EndSubEndClass