--
Sincerely,
Farshad Hemmati
Microsoft Visual Basic MVP
CompuCated Technologies
http://www.compucated.com/
-------------------------------------------------------
MAKE YOUR MEMORIES ELECTRONIC
Get Your Photo Album Software Now!
http://www.compucated.com/album/
-------------------------------------------------------
"Steven Grande" <sgr...@dynamicsolutions.com> wrote in message
news:ECE078D19685D3119E980008C7F9E55D3AC79F@CPECMAILE01...
Private Sub Form_Load()
Dim WinClass As String
Dim TaskBarHwnd As Long, lRet As Long, lParam As Long
WinClass = "Shell_TrayWnd"
TaskBarHwnd = FindWindow(WinClass, vbNullString)
If TaskBarHwnd = 0 Then
MsgBox "Could not find the Taskbar!"
Exit Sub
End If
lRet = EnumChildWindows(TaskBarHwnd, AddressOf EnumChildProc, lParam)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim RetVal As Long
If StartButtonhWnd <> 0 Then
RetVal = EnableWindow(StartButtonhWnd, True)
End If
End Sub
You will also need code like this in a Module:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function EnableWindow Lib "user32" _
(ByVal hwnd As Long, ByVal fEnable As Long) As Long
Public Declare Function EnumChildWindows Lib "user32" _
(ByVal hWndParent As Long, ByVal lpEnumFunc As Long, _
ByVal lParam As Long) As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" _
(ByVal hwnd As Long, ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Public StartButtonhWnd As Long
Function EnumChildProc(ByVal lhWnd As Long, ByVal lParam As Long) _
As Long
Dim RetVal As Long
Dim WinClassBuf As String * 255
Dim WinClass As String
RetVal = GetClassName(lhWnd, WinClassBuf, 255)
WinClass = StripNulls(WinClassBuf) ' remove extra Nulls & spaces
If WinClass = "Button" Then
StartButtonhWnd = lhWnd
RetVal = EnableWindow(StartButtonhWnd, False)
EnumChildProc = False ' Stop looking
Else
EnumChildProc = True ' Keep looking
End If
End Function
Public Function StripNulls(OriginalStr As String) As String
' This removes the extra Nulls so String comparisons will work
If (InStr(OriginalStr, Chr(0)) > 0) Then
OriginalStr = Left(OriginalStr, InStr(OriginalStr, Chr(0)) - 1)
End If
StripNulls = OriginalStr
End Function
While this will disable the Start button when the form loads and enable it
again when the from unloads, it does not prevent the user from bringing up
the Start menu using the keyboard. This is why you need the VC++ DLL. This
would need to set a WH_GETMESSAGE hook to capture the WM_SYSCOMMAND
message. Then it needs to take a look at the wParam of that message. If it
is equal to SC_TASKLIST, then it must not pass that message on to the
intended receiver. Again, the hook must either be a system-wide hook or a
thread-specific hook on the thread that would receive that message. You can
get this thread by calling GetWindowThreadProcessId on the hwnd of the
SHELL_TRAYWND (or the desktop).
You may also want to consider having your form cover the Taskbar. Here are
some Knowledge Base articles you may want to read:
Q197585 - HOWTO: Cover the Taskbar with a Window in Visual Basic
Q183009 - HOWTO: Enumerate Windows Using the WIN32 API