|
-
Oct 28th, 2000, 01:53 PM
#1
Thread Starter
Fanatic Member
Is there any way of making the Form be hiden or end as soon as the user clicks on another window or the desktop.
This would act very like the volumn control on the smallicons part of the task bar.
Thanks
Rob
-
Oct 28th, 2000, 02:47 PM
#2
I am a newbie - but does "Unload ME" do the trick??
Hope this helps
-
Oct 28th, 2000, 02:49 PM
#3
Hyperactive Member
Have you tried using the Lost Focus procedure of the form and place something like
Sub Form_LostFocus()
Me.Unload
End Sub
Sub Form_Unload ()
Set Formname=nothing
End Sub
Thanks in advance for any help provided.
VB 6 Enterprise Edition SP4
ADO, SQL 7/2000, ASP and some JavaScript

>> Life goes on, but for how long? <<
If you can smile when things go wrong, you have someone in mind to blame
-
Oct 28th, 2000, 10:06 PM
#4
parkes, there is no such thing as Me.Unload. You have to use the Unload statement. Unload Me.
THEROB, there are a few ways of doing this, you can do it the easy way, with a timer and API (GetForegroundWindow):
Code:
Declare Function GetForegroundWindow Lib "user32.dll" () As Long
Private Sub Timer1_Click()
Dim hforewnd As Long
Dim handl As Long
handl = Me.hWnd
hforewnd = GetForegroundWindow()
If handl <> hforewnd Then
Unload Me
'Me.WindowState = 1
'Or
'Me.Hide
Else
End If
End Sub
Or you can Subclass which will detect whether the form has lost focus. This is the best way to go rather than the first example.
Code:
'Module code:
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
Unload Form1
Set Form1 = Nothing
'^You can change this
'Minimized:
'Form1.WindowState = 1
'Hidden:
'Form1.Hide
End Select
End Function
'Form code:
Private Sub Form_Load()
StartSubclassing Me.hWnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
StopSubclassing
End Sub
Careful when Subclassing, it crashes VB if used wrong.
NEVER USE THE END STATEMENT WHILE SUBCLASSING.
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
|