Results 1 to 3 of 3

Thread: How can I tell if a form is active?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    8

    Post

    I am writing a program that generates graphic patterns on one half of the screen that I can not allow to be covered by anything. I have code in place that keeps the mouse icon out of the images, and code that keeps any of my program's other forms out of the area. The problem is if Windows pops up a message box, due to an error or a "Net Send" message from the network administrator, it centers itself on the screen and covers part of my image until I happen to notice it. BAD!
    I am trying to find a way to stop this.

    My plan was to have a timer keep checking to see if my form is the active form, because the message boxes become active when they appear. If my form is not avtive, it would use SendKeys to send Esc to the message and get rid of it. The problem is, I can't seem to find a way to determine if my form is active. I tried form1.deactivate, but the Windows Message boxes don't trigger it.
    I also tried an API function I found, but it is VERY unstable, and any error anywhere im my program causes it to all lock up and die. I am running NT4 if that helps any....
    Any Ideas??????

    Thanks!
    Glenn


  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Use can use the GetForeGroundWindow API to get the Currently Active Window, eg.
    Code:
    Private Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Long
    
    Private Sub Timer1_Timer()
        If GetForeGroundWindow<>Hwnd Then 
            'Your Form is NOT Active
        Else
            'Your For IS Active
        End If
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    8

    Post

    THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU!

    It worked WONDERFULLY!

    Glenn

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width