Help:Detecting changes in application focus 
Author Message
 Help:Detecting changes in application focus

ick
LoseFocus and GotFocus come with all VB Forms at NO EXTRA CHARGE.
{*filter*}ing use the {*filter*}ing thangs that are {*filter*}ing obvious on the {*filter*}ing code
pane.

--

Respectfully,
Timothy J. Bruce

Pursuant to US Code, Title 47, Chapter 5, Subchapter II, Sec. 227,
any and all nonsolicited commercial E-mail sent to this address is
subject to a download and archival fee in the amount of $500 US.
E-mailing denotes acceptance of these terms.



Sat, 29 Apr 2000 03:00:00 GMT  
 Help:Detecting changes in application focus

Quote:
>Unfortunately, those events only fire when focus is changed within the
>application, not when the application itself loses or gains focus.  With
>VB5 you should be able to subclass the VB "invisible" window (its a
>GetWindow enumeratable parent to your main form) that intercepts all
>Windows messages and look for WM_ACTIVATEAPP.  A wParam of TRUE means the
>app is being activated, and FALSE, means deactivated.

Exactly how would trap the WM in VB?  Could you post a code snipet, I
didn't realize this was possible from VB.

Thanx!

Quote:



>> LoseFocus and GotFocus come with all VB Forms at NO EXTRA CHARGE.
>> {*filter*}ing use the {*filter*}ing thangs that are {*filter*}ing obvious on the {*filter*}ing
>code
>> pane.

My first kill filter ever in a programming news group...

 Key fingerprint =  D3 D2 32 2C 28 B9 0B 05  A4 0B C5 5E 20 FE D7 C6



Sun, 30 Apr 2000 03:00:00 GMT  
 Help:Detecting changes in application focus

Hi Slick!

Quote:
> Exactly how would trap the WM in VB?  Could you post a code snipet, I
> didn't realize this was possible from VB.

VB5:

********Into the Startform of the App*********
Private Sub Form_Load()
  HookHdl = SetWindowsHookExA(4, AddressOf CallWndProc, App.hInstance,
App.ThreadID)
End Sub

Private Sub Form_Unload(Cancel As Integer)
  UnhookWindowsHookEx HookHdl
End Sub
***************************************************

***************Into a Module***************
Type CWPSTRUCT
  lParam As Long
  wParam As Long
  Message As Long
  Hwnd As Long
End Type

Public Declare Function SetWindowsHookExA& Lib "user32" (ByVal idHook&,
ByVal lpfn&, ByVal hmod&, ByVal ThrID&)
Public Declare Function CallNextHookEx& Lib "user32" (ByVal hHook&, ByVal
nCode&, ByVal wParam&, lParam As Any)
Public Declare Function UnhookWindowsHookEx& Lib "user32" (ByVal hHook&)

Public HookHdl&

Public Function CallWndProc&(ByVal nCode&, ByVal wParam&, Inf As CWPSTRUCT)
  On Error Resume Next
  If nCode < 0 Then CallWndProc = CallNextHookEx(HookHdl, 4, wParam, Inf)
  Select Case Inf.Hwnd
    Case Form1.Hwnd
      Select Case Inf.Message
       'Case &H6   'WM_ACTIVATE

        Case &H1C  'WM_ACTIVATEAPP
          Debug.Print Inf.wParam '0 = InActive
       'Case OtherMessageForThisWindow

      End Select
   'Case OtherWindowHandleInApp

  End Select
End Function
********************************************************

Olaf

P.S. Be careful with the Stop-Button in the IDE (GPF because no UnHook)



Sun, 30 Apr 2000 03:00:00 GMT  
 Help:Detecting changes in application focus

Okay, a hook makes sense.  I thougt you were saying that there was a
hidden window that VB allowed you to trap the WMs directly..


Quote:
>Hi Slick!

>> Exactly how would trap the WM in VB?  Could you post a code snipet, I
>> didn't realize this was possible from VB.

>VB5:

>********Into the Startform of the App*********
>Private Sub Form_Load()
>  HookHdl = SetWindowsHookExA(4, AddressOf CallWndProc, App.hInstance,
>App.ThreadID)
>End Sub

>Private Sub Form_Unload(Cancel As Integer)
>  UnhookWindowsHookEx HookHdl
>End Sub
>***************************************************

>***************Into a Module***************
>Type CWPSTRUCT
>  lParam As Long
>  wParam As Long
>  Message As Long
>  Hwnd As Long
>End Type

>Public Declare Function SetWindowsHookExA& Lib "user32" (ByVal idHook&,
>ByVal lpfn&, ByVal hmod&, ByVal ThrID&)
>Public Declare Function CallNextHookEx& Lib "user32" (ByVal hHook&, ByVal
>nCode&, ByVal wParam&, lParam As Any)
>Public Declare Function UnhookWindowsHookEx& Lib "user32" (ByVal hHook&)

>Public HookHdl&

>Public Function CallWndProc&(ByVal nCode&, ByVal wParam&, Inf As CWPSTRUCT)
>  On Error Resume Next
>  If nCode < 0 Then CallWndProc = CallNextHookEx(HookHdl, 4, wParam, Inf)
>  Select Case Inf.Hwnd
>    Case Form1.Hwnd
>      Select Case Inf.Message
>       'Case &H6   'WM_ACTIVATE

>        Case &H1C  'WM_ACTIVATEAPP
>          Debug.Print Inf.wParam '0 = InActive
>       'Case OtherMessageForThisWindow

>      End Select
>   'Case OtherWindowHandleInApp

>  End Select
>End Function
>********************************************************

>Olaf

>P.S. Be careful with the Stop-Button in the IDE (GPF because no UnHook)


 Key fingerprint =  D3 D2 32 2C 28 B9 0B 05  A4 0B C5 5E 20 FE D7 C6



Sun, 30 Apr 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Help:Detecting changes in application focus

2. Help:Detecting changes in application focus

3. Help:Detecting changes in application focus

4. detecting when application has lost focus

5. Detect Lost Focus of VB Application

6. Detecting previous instance of application and setting focus to it

7. Detecting previous instance of application and setting focus to it

8. A question about detecting a focus change...

9. Desperately trying to detect the focus change.

10. A question about detecting a focus change...

11. Detect when the focus changes...

12. How to detect focus changed?

 

 
Powered by phpBB® Forum Software