Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable Alt-Tab and "Windows" buttons

Status
Not open for further replies.

Adric

Programmer
Jun 25, 2001
24
US
Does anyone know how do disable the alt-tab command and the windows button while a programme is running. I dont want the user to be able to access the start menu without closing the programme or be able to switch programmes.
 
Hi Adric,
try this code

Code:
Declare Function GetMenuItemCount Lib "user32" _
(ByVal hMenu As Long) As Long
Declare Function GetSystemMenu Lib "user32" _
(ByVal hwnd As Long, ByVal bRevert As Long) As Long
Declare Function DrawMenuBar Lib "user32" _
(ByVal hwnd As Long) As Long
Declare Function RemoveMenu Lib "user32" _
(ByVal hMenu As Long, ByVal nPosition As Long, _
ByVal wFlags As Long) As Long

Public Const MF_BYPOSITION = &H400&
Public Const MF_REMOVE = &H1000&

'in the Form...

Private Sub Form_Load()
	Dim hSysMenu As Long
	Dim nCnt As Long

	Me.Show

	' Get handle to the form's system menu 
	hSysMenu = GetSystemMenu(Me.hwnd, False)

	If hSysMenu Then
		' Get Systemmenu's menucount
		nCnt = GetMenuItemCount(hSysMenu)

		If nCnt Then
			RemoveMenu hSysMenu, nCnt - 1, 
			MF_BYPOSITION Or MF_REMOVE

			RemoveMenu hSysMenu, nCnt - 2, _
			MF_BYPOSITION Or MF_REMOVE ' Remove the seperator

			DrawMenuBar Me.hwnd 
			'menubar's refresh to disable close

		End If
	End If
End Sub
 
Well, is there any way to get the program to void all key presses made by the user?
 
OOPS!
I'm very Sorry! I did not read the question properly...! I was thinking that you wanted to code for disabling the Close...

Well If you want to handle disble all the KeyEvents then you need to define your own Callback function and associate it with you Form window.
The API function TranslateMessage does the Job of Translating it..
Check MSDN online for more help.
You trap all the key related events and then Stop the Delegation.

I'll come back with the Code soon.

Atul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top