borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (newst)Next Topic (RS 232???) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Application Deactivate
Poster Message
RayZore
Level: Scholar

Registered: 22-08-2003
Posts: 34

icon Application Deactivate

Hi All

I've got a rather frustrating problem. I've got a project
with a MDI Form and a Child Form. On the child form is a timer that starts a rather resource intensive task, I want to switch off the timer when the application becomes inactive.

I can trap this event if the form is minimized but what do I trap if the app is deactivated when someone alt-tabs to a different program.

Cheers

Ray


____________________________
I'd rather be fishing

08-07-2005 at 11:41 AM
View Profile Send Email to User Show All Posts | Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1681
icon Re: Application Deactivate

You need to subclass MDI form for WM_ACTIVATE message

' MDI form code

Option Explicit

Const GWL_WNDPROC = (-4)

Private Sub MDIForm_Load()
    hWndProc = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Private Sub MDIForm_Unload(Cancel As Integer)
    SetWindowLong Me.hwnd, GWL_WNDPROC, hWndProc
End Sub



'module code

Option Explicit

Const WM_ACTIVATE = &H6

Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) 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 SetClipboardViewer Lib "user32" (ByVal hwnd As Long) As Long

Public hWndProc As Long

Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    WindowProc = CallWindowProc(hWndProc, hwnd, uMsg, wParam, lParam)
    
    If uMsg = WM_ACTIVATE Then
        Select Case wParam
            Case 0
                Debug.Print "Deactivated"
            Case 1
                Debug.Print "Activated"
            Case 2
                Debug.Print "Activated with mouse"
        End Select
    End If
End Function


____________________________
If you find the answer helpful, please mark this topic as solved.

10-07-2005 at 06:03 PM
View Profile Send Email to User Show All Posts | Quote Reply
RayZore
Level: Scholar

Registered: 22-08-2003
Posts: 34
icon Re: Application Deactivate

Thanks Goran.

I'll try your method. Hopefully without the headaches I've had subclassing forms in the past.



____________________________
I'd rather be fishing

13-07-2005 at 09:10 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : Application Deactivate
Previous Topic (newst)Next Topic (RS 232???) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder