locked
hide or lock start botton RRS feed

  • Question

  • Hi,
    Anyone could help me with the code for hide/show start botton or lock it, because i'm building an application for public use and i want hide start menu to avoid problems.

    i allready have been on the net looking for that but the code i found doesn't or im doing some thing wrong. The code i found many times is this:
    Declarations:
    Private Declare Function FindWindow Lib "user32" Alias _
    
       "FindWindowA" (ByVal lpClassName As String, _
    
       ByVal lpWindowName As String) As Long
    
       
    
    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 ShowWindow Lib "user32" _
    
        (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

    code lines:
    Public Function hideStartButton()
    
       'This Function Hides the Start Button'
    
       OurParent& = FindWindow("Shell_TrayWnd", "")
    
       OurHandle& = FindWindowEx(OurParent&, 0, "Button",  _
    
           vbNullString)
    
       ShowWindow OurHandle&, 0
    
    End Function
    
    
    
    Public Function showStartButton()
    
       'This Function Shows the Start Button'
    
       OurParent& = FindWindow("Shell_TrayWnd", "")
    
       OurHandle& = FindWindowEx(OurParent&, 0, "Button", _
    
            vbNullString)
    
    
    
       ShowWindow OurHandle&, 5
    
    End Function

    and it didn't do anything.
    The code has to work on Win XP and newest, under instroction of VBnet 2008 or 2010b2 (this last is only for test =) )

    Thanks... to any response

    TcoUpLoad (work with Vb6 and VbNet)
    • Edited by Tcomsn Monday, October 26, 2009 2:38 PM edition of some lines
    Monday, October 26, 2009 2:36 PM

Answers

  • Hi,

    paste this inside your form code:


        Private Declare Auto Function ShowWindow Lib "user32.dll" _
      (ByVal hWnd As IntPtr, _
        ByVal nCmdShow As Int32) As Int32
    
        Private Declare Auto Function FindWindowEx Lib "user32.dll" _
         (ByVal hwndParent As IntPtr, _
          ByVal hwndChildAfter As IntPtr, _
          ByVal lpszClass As String, _
          ByVal lpszWindow As String) As IntPtr
    
        Private Const SW_HIDE As Int32 = 0
        Private Const SW_RESTORE As Int32 = 9
        Private Enum Visualibility
            HIDE = 0
            SHOW = 1
        End Enum
        Private Sub StartButton_HideOrShow(ByVal HideOrShow As Visualibility)
            Dim ParentClass As String = "Shell_TrayWnd"
            Dim ChildClass As String = "Button"
            Dim hwnd As IntPtr = FindWindowEx(IntPtr.Zero, IntPtr.Zero, ParentClass, Nothing)
            If (Not hwnd.Equals(IntPtr.Zero)) Then
                hwnd = FindWindowEx(hwnd, IntPtr.Zero, ChildClass, Nothing)
                If (Not hwnd.Equals(IntPtr.Zero)) Then
                    Select Case HideOrShow
                        Case Visualibility.HIDE
                            Call ShowWindow(hwnd, SW_HIDE)
                        Case Visualibility.SHOW
                            Call ShowWindow(hwnd, SW_RESTORE)
                    End Select
                End If
            End If
        End Sub

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    • Proposed as answer by Shariq Ayaz Monday, October 26, 2009 9:07 PM
    • Unproposed as answer by Tcomsn Tuesday, October 27, 2009 1:15 AM
    • Marked as answer by Tcomsn Tuesday, October 27, 2009 11:08 AM
    Monday, October 26, 2009 2:54 PM
  • Hi,

    'Show the StartButton
    StartButton_HideOrShow(Visualibility.SHOW)
    
    'Hide the StartButton
    StartButton_HideOrShow(Visualibility.HIDE)
    

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    • Proposed as answer by Shariq Ayaz Monday, October 26, 2009 8:54 PM
    • Unproposed as answer by Tcomsn Tuesday, October 27, 2009 1:26 AM
    • Marked as answer by Tcomsn Tuesday, October 27, 2009 11:08 AM
    Monday, October 26, 2009 7:44 PM

All replies

  • Hi,

    paste this inside your form code:


        Private Declare Auto Function ShowWindow Lib "user32.dll" _
      (ByVal hWnd As IntPtr, _
        ByVal nCmdShow As Int32) As Int32
    
        Private Declare Auto Function FindWindowEx Lib "user32.dll" _
         (ByVal hwndParent As IntPtr, _
          ByVal hwndChildAfter As IntPtr, _
          ByVal lpszClass As String, _
          ByVal lpszWindow As String) As IntPtr
    
        Private Const SW_HIDE As Int32 = 0
        Private Const SW_RESTORE As Int32 = 9
        Private Enum Visualibility
            HIDE = 0
            SHOW = 1
        End Enum
        Private Sub StartButton_HideOrShow(ByVal HideOrShow As Visualibility)
            Dim ParentClass As String = "Shell_TrayWnd"
            Dim ChildClass As String = "Button"
            Dim hwnd As IntPtr = FindWindowEx(IntPtr.Zero, IntPtr.Zero, ParentClass, Nothing)
            If (Not hwnd.Equals(IntPtr.Zero)) Then
                hwnd = FindWindowEx(hwnd, IntPtr.Zero, ChildClass, Nothing)
                If (Not hwnd.Equals(IntPtr.Zero)) Then
                    Select Case HideOrShow
                        Case Visualibility.HIDE
                            Call ShowWindow(hwnd, SW_HIDE)
                        Case Visualibility.SHOW
                            Call ShowWindow(hwnd, SW_RESTORE)
                    End Select
                End If
            End If
        End Sub

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    • Proposed as answer by Shariq Ayaz Monday, October 26, 2009 9:07 PM
    • Unproposed as answer by Tcomsn Tuesday, October 27, 2009 1:15 AM
    • Marked as answer by Tcomsn Tuesday, October 27, 2009 11:08 AM
    Monday, October 26, 2009 2:54 PM
  • HI Sir haslacher !
    How to Your code Work



    Monday, October 26, 2009 7:23 PM
  • Hi,

    'Show the StartButton
    StartButton_HideOrShow(Visualibility.SHOW)
    
    'Hide the StartButton
    StartButton_HideOrShow(Visualibility.HIDE)
    

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    • Proposed as answer by Shariq Ayaz Monday, October 26, 2009 8:54 PM
    • Unproposed as answer by Tcomsn Tuesday, October 27, 2009 1:26 AM
    • Marked as answer by Tcomsn Tuesday, October 27, 2009 11:08 AM
    Monday, October 26, 2009 7:44 PM
  • Hiding any of the Windows Shell is a bad idea, it takes away the user's control which I have learned is a bad thing to do. I would suggest leaving it alone, however, if you are wanting to make it disappear for a full screen effect; that's fine. But anything other than that it really not good. 
    Thanks, Callum Kerr. Website: http://www.regpro.co.uk Xbox Live Gamertag: callum151000
    Monday, October 26, 2009 8:23 PM
  • i know is not good but is to a public place here who use it dont know much that go to hi5 and msn... so it's ok. lol

    But i tryed and it didn't work.

     Private Sub StartButton_HideOrShow(ByVal HideOrShow As Visualibility)
            Dim ParentClass As String = "Shell_TrayWnd"
            Dim ChildClass As String = "Button"
            Dim hwnd As IntPtr = FindWindowEx(IntPtr.Zero, IntPtr.Zero, ParentClass, Nothing)
            If (Not hwnd.Equals(IntPtr.Zero)) Then
                hwnd = FindWindowEx(hwnd, IntPtr.Zero, ChildClass, Nothing)
                If (Not hwnd.Equals(IntPtr.Zero)) Then
                    Select Case HideOrShow
                        Case Visualibility.HIDE
                            Call ShowWindow(hwnd, SW_HIDE)
                        Case Visualibility.SHOW
                            Call ShowWindow(hwnd, SW_RESTORE)
                    End Select
                End If
            End If
        End Sub

    At this line:
    Dim hwnd As IntPtr = FindWindowEx(IntPtr.Zero, IntPtr.Zero, ParentClass, Nothing)

    to the hwnd variable has given the value 65628 but 2 lines after it change to 0, so the select case is never executed. have any ideia what could be wrong?
    • Edited by Tcomsn Tuesday, October 27, 2009 1:26 AM bold something
    Monday, October 26, 2009 9:34 PM
  • Hi Tcomsn,

    hi have tested this code under Win XP Prof. SP3 and it worked like a charme. Did you use your api declaration or the one i provided ?
    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    Tuesday, October 27, 2009 6:35 AM
  • Hi,
    I used your code at the first attempt. At the 2nd attemp a comment the line
    hwnd = FindWindowEx(hwnd, IntPtr.Zero, ChildClass, Nothing
    )
    
    The result was the hide of all taskbar! =) Something is not quite well

    TcoUpLoad (work with Vb6 and VbNet)
    Tuesday, October 27, 2009 10:41 AM
  • Hi again,

    what OS are you running ?
    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    Tuesday, October 27, 2009 10:43 AM
  • XP Sp3

    TcoUpLoad (work with Vb6 and VbNet)
    Tuesday, October 27, 2009 10:53 AM
  • And you also used this api declarations :

        Private Declare Auto Function ShowWindow Lib "user32.dll" _
      (ByVal hWnd As IntPtr, _
        ByVal nCmdShow As Int32) As Int32
    
        Private Declare Auto Function FindWindowEx Lib "user32.dll" _
         (ByVal hwndParent As IntPtr, _
          ByVal hwndChildAfter As IntPtr, _
          ByVal lpszClass As String, _
          ByVal lpszWindow As String) As IntPtr
    ?
    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    Tuesday, October 27, 2009 10:56 AM
  • i eliminate de underscores on those private declarations and works... or maybe iam not was quite awake yesterday to see the magic appening... lol

    TcoUpLoad (work with Vb6 and VbNet)
    Tuesday, October 27, 2009 11:08 AM