Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Program LostFocus Ques

Posted on 2002-05-28
3
Medium Priority
?
278 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 200 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

963 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