-
I have an app with a timer that won't allow the user to close it until the timer has finished. (when the countdown is over, a command button becomes enabled to close the form).
But how can I disable the close (x) in the top right hand corner whilst keeping the rest of the toolbar?
I've tried the code in KB article Q110393 but it doesn't work.
Any ideas?
Simon
-
Why not change the ControlBox property of the form to FALSE?
------------------
Mark "Buzby" Beeton
VB Developer
[email protected]
-
That takes away the icon in the top-left corner and I'd like to keep that :)
Simon
-
Write code in the Unload-event of the form
there you can check if your timer has finished.
If not, set the Cancel-variable to true (or is it false ? -> if it doesn't work with true, it must be false :) )
-
Code that queries the state of the ControlBox is much better done in the QueryUnload event.
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = vbFormControlMenu Then
' g_bProcessFinished is a (perhaps) global variable
' that you would set to true when your long-running
' process is complete.
If Not g_bProcessFinished Then
Beep
MsgBox "Please wait. Process is not finished"
Cancel = True
End If
End If
End Sub
------------------
Marty
What did the fish say when it hit the concrete wall?
> > > > > "Dam!"
[This message has been edited by MartinLiss (edited 02-10-2000).]
-
Thanks Azzmodan! That did the job - how would I go about enabling the (x) again after 5 seconds?
Would this be possible?
Simon
-
This will remove the Close command and the Separator bar from the system menu, redraws the menubar(wich will figure, hee wait a sec, the close is gone, lets gray out that freakn' X thingie)
Add this to a module:
Code:
Option Explicit
Private Const MF_BYPOSITION = &H400
Private Const MF_REMOVE = &H1000
Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Public Sub X_Disable(ByVal hWnd As Long)
Dim lhMenu As Long
Dim lMenuItemCount As Long
lhMenu = GetSystemMenu(hWnd, 0)
If lhMenu Then
lMenuItemCount = GetMenuItemCount(lhMenu)
Call RemoveMenu(lhMenu, lMenuItemCount - 1, MF_REMOVE Or MF_BYPOSITION)
Call RemoveMenu(lhMenu, lMenuItemCount - 2, MF_REMOVE Or MF_BYPOSITION)
Call DrawMenuBar(hWnd)
End If
End Sub
Call it by placing the following code somewhere
Call X_Disable(MyForm.hWnd)
Hope it helps.
------------------
Vincent van den Braken
EMail: [email protected]
ICQ: 15440110
Homepage: http://www.azzmodan.demon.nl