|
-
May 4th, 2000, 12:10 AM
#1
Does anyone know how to detect if a program has lost all focus? I want to minimize it if it has lost its focus. For example, if I have my app loaded and I click on the Microsoft Internet Explorer window, my program would have no focus at all and would minimize itself.
-
May 4th, 2000, 03:51 AM
#2
In the Form's LostFocus event place the following code.
Me.WindowState = 1
-
May 4th, 2000, 04:17 AM
#3
Fanatic Member
And I've got a far more complex solution that does just the same
as Megatron's:
Code:
'In BAS Module
Option Explicit
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal ndx As Long, ByVal newValue As Long) As Long
Private 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
' This is used with the SetWindowLong API function.
Const GWL_WNDPROC = -4
Public Const WM_KILLFOCUS = &H8
' --------------------------------------------
Dim saveHWnd As Long ' The handle of the subclassed window.
Dim oldProcAddr As Long ' The address of the original window procedure
Sub StartSubclassing(ByVal hWnd As Long)
saveHWnd = hWnd
oldProcAddr = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WndProc)
End Sub
Sub StopSubclassing()
SetWindowLong saveHWnd, GWL_WNDPROC, oldProcAddr
End Sub
Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
' Send the message to the original window procedure, and then
' return Windows the return value from the original procedure.
WndProc = CallWindowProc(oldProcAddr, hWnd, uMsg, wParam, lParam)
Select Case uMsg
Case WM_KILLFOCUS
YourForm.WindowState = 1
End Select
End Function
'------------------------
'In Form Module
Private Sub Form_Load()
StartSubclassing Me.hWnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
StopSubclassing
End Sub
Tihihihi.
A bit more complex?
I think so.
A bit more useful?
No. 
-
May 4th, 2000, 08:07 AM
#4
Thanks guys, I know about the Form_LostFocus thing..but thats only for if one of the form's controls are clicked, than the form loses focus. V(ery) Basic's code is the one I was looking for, but I thank both of you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|