Solved

Program LostFocus Ques

Posted on 2002-05-28
3
266 Views
Last Modified: 2008-02-01
How to know that the user goto another application without exit from my prog.
in other hand: how to know that my application lost focus.

elzohy
0
Comment
Question by:elzohry
3 Comments
 

Accepted Solution

by:
RuslanM earned 50 total points
ID: 7040508
Here code how to do it with WM_ACTIVATE events:

'Code For Form1
Option Explicit

Private Sub Form_Load()
    OldWindowProc = SetWindowLong( _
        hwnd, GWL_WNDPROC, _
        AddressOf NewWindowProc)
End Sub


'Code For Module1
Option Explicit

Public OldWindowProc As Long

Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Const GWL_WNDPROC = (-4)

Public Const WM_ACTIVATE = &H6
Public Const WA_ACTIVE = 1
Public Const WA_CLICKACTIVE = 2
Public Const WA_INACTIVE = 0

' *********************************************
' Look for WM_ACTIVATE.
' *********************************************
Public Function NewWindowProc(ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    If msg = WM_ACTIVATE Then
        If (wParam = WA_ACTIVE Or wParam = WA_CLICKACTIVE) Then
            Form1.Caption = "Active!"
        Else
            Form1.Caption = "Inactive"
        End If
    End If

    NewWindowProc = CallWindowProc( _
        OldWindowProc, hwnd, msg, wParam, _
        lParam)
End Function
0
 
LVL 5

Expert Comment

by:gwgaw
ID: 7041055
You could use a timer control and the GetActiveWindow api.

Private Declare Function GetActiveWindow Lib "user32" () As Long

Private Sub Timer1_Timer()
If GetActiveWindow = Me.hWnd Then
    Me.Caption = "me"
Else
    Me.Caption = "not me"
End If
End Sub

gwgaw
0
 

Author Comment

by:elzohry
ID: 7041085
Thanks for all
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Computer crashes, following error message in event manager 5 243
Hide vba in gp 7 106
How to read File Date Created using VB6 8 52
Collapse and expand table in Word 2010 2 39
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

820 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