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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to enable/disable a windows object(EX. Start Menu)

Windows API

How to enable/disable a windows object(EX. Start Menu)

by  percent  Posted    (Edited  )

This FAQ will show you some example code on how to enable & disable objects

[color green]'First you need to declare the API functions you will be using{[/color]
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, ByVal fEnable As Long) As Long
[color green]'};[/color]

[color green]'This function will get the handle of the start menu and enable it or disable it depending on the value of the Status value[/color]
Private Function Enable_WindowsXP_StartButton(Status as Boolean)
Dim zhWnd As Long
zhWnd = FindWindowEx(0&, 0&, "Shell_TrayWnd", vbNullString): zhWnd = FindWindowEx(zhWnd, 0&, "Button", vbNullString)[color green]'This uses the class of the object to find the objects handle[/color]
Call EnableWindow(zhWnd, Status)[color green]'Runs the API to enable or disable the object[/color]
End Function


[color green]'Use The Above Function In The Manner Below[/color]
Call Enable_WindowsXP_StartButton(False)[color green] 'To Disable Start Menu[/color]

Call Enable_WindowsXP_StartButton(True)[color green] 'To Disable Start Menu[/color]

[color red]*This code was made while using windows xp - so is not Guaranteed to work in other OS versions*[/color]
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top