-
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
-
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
-
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
-
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