Solved

Program LostFocus Ques

Posted on 2002-05-28
3
265 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…

770 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