CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2000
    Location
    Colombo,Srilanka
    Posts
    50

    Close start Button

    Hi gurus,
    I want to cloase the start button from My application.

    How can I do this.

    THankx in Advance.

    Dinesh Asanka

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Close start Button

    I tried this on WinnT and it worked...

    http://www.planet-source-code.com/xq...s/ShowCode.htm

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Another solution


    '**************************************
    'This code rises from the johining of two
    'examples, one from planet-source-code (By: DoWnLoHo)
    'the other from vbnet by Randy Birch,
    '**************************************
    'You can disable the start button for mouse.
    'to disable it for keyboard without destroing the button, you
    'have to make window perform another action which will override the menu
    '(ie: menu would appear, but it is immediatly hidden by something else)
    'to test this, add a command button to a form,
    'and set the keypreview of form to true. as long as your form
    'holds the focus, it will disable the start button keydown.
    'to give constantly focus to this form, you may
    'add a timer (interval = 200ms) and add the
    'me.setfocus
    'instruction in timer event. But this is not a clean solution, so
    'let's wait for a truly Guru note....


    private Declare Sub keybd_event Lib "User32" (byval bVk as Byte, byval bScan as Byte, byval dwFlags as Long, byval dwExtraInfo as Long)

    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 EnableWindow Lib "User32" (byval hWnd as Long, byval fEnable as Long) as Long

    private Const VK_LWIN = &H5B
    private Const KEYEVENTF_KEYUP = &H2
    private Const VK_APPS = &H5D

    private Declare Sub SetWindowPos Lib "User32" (byval hWnd as Long, byval hWndInsertAfter as Long, byval X as Long, byval Y as Long, byval cx as Long, byval cy as Long, byval wFlags as Long)
    private Const HWND_TOPMOST = -1
    private Const SWP_NOSIZE = &H1
    private Const SWP_NOMOVE = &H2
    private Const SWP_NOACTIVATE = &H10
    private Const SWP_SHOWWINDOW = &H40


    Dim blnEnabled as Boolean





    private Sub EnableStartButton(optional Enabled as Boolean = true)
    'this will enable/disable any window wit
    ' h a little modifaction
    Dim lHwnd as Long 'declare variables
    'find start button hWnd
    lHwnd& = FindWindowEx(FindWindow("Shell_TrayWnd", ""), 0&, "Button", vbNullString)
    'call the enablewindow api and do the wh
    ' at needs to be done
    Call EnableWindow(lHwnd&, CLng(Enabled))
    End Sub


    private Sub Command1_Click()
    If blnEnabled then
    Command1.Caption = "disable start button"
    else
    Command1.Caption = "enable start button"
    End If
    Call EnableStartButton(blnEnabled)
    blnEnabled = Not blnEnabled
    End Sub
    '------------------------------------------------------------
    'private Sub Command2_Click()
    '' "Show Start menu" = &H5B
    ' Dim VK_ACTION as Long
    ' VK_ACTION = &H5B
    ' Call keybd_event(VK_LWIN, 0, 0, 0)
    ' Call keybd_event(VK_ACTION, 0, 0, 0)
    ' Call keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)
    'End Sub
    '-------------------------------------------------------------
    private Sub Form_KeyDown(KeyCode as Integer, Shift as Integer)
    Dim VK_ACTION as Long
    'intercept the keyboard
    If blnEnabled then
    If KeyCode = &H5B then 'startbutton key pressed
    'send message to do another acttion
    'ie:
    ' "Show Window Explorer" = &H45
    ' "Show find window" = &H46
    ' "Minimize all window" = &H4D
    ' "Show run window" = &H52
    ' "caret key 94" = &H5E
    ' "Show Help" = &H70
    ' to show start menu by code: "Show Start menu" = &H5B
    'but if you add this, you 'll need to associate the following key
    'with some action that perform a stronger action than &H5E
    '(ie: the minimize all window key)
    VK_ACTION = &H5E
    Call keybd_event(VK_LWIN, 0, 0, 0)
    Call keybd_event(VK_ACTION, 0, 0, 0)
    Call keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)
    End If
    End If
    End Sub

    private Sub Form_Load()
    SetWindowPos me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE

    Command1.Caption = "disable start button"
    blnEnabled = false
    End Sub
    private Sub Form_Resize()
    If me.WindowState = vbMinimized then
    me.WindowState = vbNormal
    End If
    End Sub






    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  4. #4
    Join Date
    Sep 2001
    Posts
    16

    Re: Close start Button

    Hi,
    If u want to close a button in the application u can do it by setting the property Visible to false.ie.,
    start.visible=false
    Bye
    sunil


  5. #5
    Join Date
    Sep 2001
    Posts
    16

    Re: Close start Button

    Hi
    Sorry I couldnt understand the question properly and has given a stupid solution.



  6. #6
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Close start Button

    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Public 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
    Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long


    Sub HideStartButton()
    Dim Handle As Long, FindClass As Long
    FindClass& = FindWindow("Shell_TrayWnd", "")
    Handle& = FindWindowEx(FindClass&, 0, "Button", vbNullString)
    ShowWindow Handle&, 0
    End Sub


    Sub ShowStartButton()
    Dim Handle As Long, FindClass As Long
    FindClass& = FindWindow("Shell_TrayWnd", "")
    Handle& = FindWindowEx(FindClass&, 0, "Button", vbNullString)
    ShowWindow Handle&, 1
    End Sub
    'Put this code in the form


    Private Sub Command1_Click()
    HideStartButton
    End Sub


    Private Sub Command2_Click()
    ShowStartButton
    End Sub



    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  7. #7
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: No "stupid answers"

    I do believe there are not "stupid ansewrs", at least misunderstanding main point one. Which means: your answer may not have reached this question point, but may be valuable for someone else...
    Have a nice day,
    Cesare

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  8. #8
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Nice trick but...

    ...I can still access the menu via keyboard...
    Nice trick, in any case!
    HAve happy coding, Iouri

    Cesare Imperiali

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured