Results 1 to 4 of 4

Thread: Keep your app Always Selected?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Posts
    137

    Lightbulb

    How can u keep your app Always Selected? Say if another program interferes and switches avtiveness to itself, how do you get your app automatically selected back?
    Something like this for example:
    Private Sub Timer1_Timer()
    If Form1.NotSelected = True Then
    Form1.Select
    Else
    End Sub
    (BTW, this code doesn't work)

    Can someone please help?

    Thanx,
    Mikelo


  2. #2
    Guest
    Use the SetForegroundWindow and GetForegroundWindow api functions.

    Code:
    Declare Function GetForegroundWindow Lib "user32.dll" () As Long
    
    Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Long) As Long 
    
    Private Sub Timer1_Timer()
    Dim hforewnd As Long
    Dim handl As Long
        handl = Me.hWnd
        hforewnd = GetForegroundWindow()
        If handl <> hforewnd Then
          SetForegroundWindow handl
        Else
        End If
    End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Posts
    137

    Talking Thanx so much......

    Thank you Sooo much, i have been looking for this code for a while now and no websites had it.

    Thanx,
    Mikelo

  4. #4
    Guest
    You can use this code as well:

    Code:
    Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos"_
      (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
      ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
      ByVal cy As Long, ByVal wFlags As Long) As Long
    
    Global Const SWP_NOMOVE = 2 
    Global Const SWP_NOSIZE = 1 
    Global Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE 
    Global Const HWND_TOPMOST = -1 
    Global Const HWND_NOTOPMOST = -2
    
    
    Private Sub Timer1_Timer()
    ontop& = SetWindowPos (Me.hWnd, HWND_TOPMOST, _
    0, 0, 0, 0, FLAGS) 
    End Sub

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