Focus issue

I created an application that displays a form with information sent to it by another computer. This form is alwas active and sits on a small part of the bottom of the screeen. The problem is that at times the app receives and displays informaton it takes focus from the active program. So if i was typing in Word i can loose focus while i am typing.

How can i prevent this problem from happening?
roviAsked:
Who is Participating?
 
junglerover77Commented:
Totally agree with Idel_Mind, if you show your received information in a normal way, this is not gonna happen. Just put a timer and a textbox in a form and try the following code:

Private Sub Form_Load()
    Timer1.Interval = 1000
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    Text1.Text = Now
End Sub

The text of the textbox will change every second, but this application will never grab the focus.

If your application keep grabbing the focus, there must be some special code in your code. Please show your code so that we can help you.

Regards,
Jungle
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
How are you "updating" the information in your form?
0
 
Shiju SasidharanAssoc Project ManagerCommented:
make ur window always on top

Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, y, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const TOPMOST_FLAGS = SWP_NOMOVE Or SWP_NOSIZE

Public Sub MakeNormal(hwnd As Long)
    SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End Sub
Public Sub MakeTopMost(hwnd As Long)
    SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End Sub

'usage
Private Sub Form _Load()
     Call  MakeTopMost(Me.hwnd)
End Sub

0
 
Shiju SasidharanAssoc Project ManagerCommented:
also it is better to remove control boxes from ur form so that user cannot minimize it
provided ur screen will be small enough to be positioned at bottom of the screen
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.