Results 1 to 4 of 4

Thread: New Start Button

  1. #1

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815

    Talking New Start Button

    Hi!

    I have this code:

    Code:
    Const WS_CHILD = &H40000000
    Const WM_LBUTTONDOWN = &H201
    Const WM_LBUTTONUP = &H202
    Const SW_HIDE = 0
    Const SW_NORMAL = 1
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    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 FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
    Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
    Dim tWnd As Long, bWnd As Long, ncWnd As Long
    Private Sub Form_Load()
        Dim R As RECT
        'Get the taskbar's window handle
        tWnd = FindWindow("Shell_TrayWnd", vbNullString)
        'Get the start-button's window handle
        bWnd = FindWindowEx(tWnd, ByVal 0&, "BUTTON", vbNullString)
        'Get the start button's position
        GetWindowRect bWnd, R
        'Create a new button
        ncWnd = CreateWindowEx(ByVal 0&, "BUTTON", "Start", WS_CHILD, 0, 0, R.Right - R.Left, R.Bottom - R.Top, tWnd, ByVal 0&, App.hInstance, ByVal 0&)
        'Show our button
        ShowWindow ncWnd, SW_NORMAL
        'Hide the start button
        ShowWindow bWnd, SW_HIDE
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
        'show the start button
        ShowWindow bWnd, SW_NORMAL
        'destroy our button
        DestroyWindow ncWnd
    End Sub

    Can anyone tell me how i can run code when the new start button is clicked??

    Thanx for any help
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

  2. #2
    Megatron
    Guest
    You need to SubClass your window and catch the WM_COMMAND message:

    Add to a Module
    VB Code:
    1. Public Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
    2. Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    3. Public Const GWL_WNDPROC = (-4)
    4. Public Const WM_COMMAND = &H111
    5. Public WndProcOld As Long
    6. Public ncWnd As Long
    7.  
    8. Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    9.    
    10.     If (wMsg = WM_COMMAND) And (lParam = ncWnd) Then
    11.         MsgBox "You clicked the Button!"
    12.     End If
    13.    
    14.     WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
    15. End Function
    16.  
    17. Sub SubClassWnd(hwnd As Long)
    18.     WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
    19. End Sub
    20.  
    21. Sub UnSubclassWnd(hwnd As Long)
    22.     SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
    23.     WndProcOld& = 0
    24. End Sub

    Make sure you declare ncWnd as public, so the Module can access it.

  3. #3
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    Here's a link to a couple of examples of using\changing the Start button. They may or may not be helpfull....

    There's also an example showing how to retrieve the dimensions of the Windows Taskbar.

    http://www.geocities.com/coding1984/vbbeginner.htm

  4. #4

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815

    Thumbs up

    Thanx
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

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