Focus issue

Posted on 2006-05-17
Last Modified: 2010-05-01
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?
Question by:rovi
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    How are you "updating" the information in your form?
    LVL 6

    Accepted Solution

    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.

    LVL 14

    Expert Comment

    by:Shiju Sasidharan
    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

    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

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

    LVL 14

    Expert Comment

    by:Shiju Sasidharan
    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

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now