VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Code to return and change the picture, width, height and position of the start button. V good code,

by Ashley Niblett (1 Submission)
Category: Windows System Services
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Mon 3rd April 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Code to return and change the picture, width, height and position of the start button. V good code, works with all versions of windows.

API Declarations



Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function 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) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hWndChild As Long) As Long
Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long

Private Type POINTAPI
X As Long
Y As Long
End Type

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type

Private Const GW_NEXT = 2
Private Const GW_CHILD = 5
Private Const BM_SETIMAGE = &HF7


Rate Code to return and change the picture, width, height and position of the start button. V good code,



'Tip: press Ctrl + A to select all this code!

Private Function TaskbarHwnd() As Long
    
    Dim MainHwnd As Long, CHwnd As Long
    Dim CLS_NM As String * 14
    
    MainHwnd = GetDesktopWindow
    CHwnd = GetWindow(MainHwnd, GW_CHILD)
    Do While CHwnd <> 0
        GetClassName CHwnd, CLS_NM, 14
        If Left(CLS_NM, 13) = "Shell_TrayWnd" Then
            TaskbarHwnd = CHwnd
            Exit Function
        End If
        CHwnd = GetWindow(CHwnd, GW_NEXT)
    Loop

End Function
Property Get hwnd() As Long
    
    Dim MainHwnd As Long, CHwnd As Long
    Dim CLS_NM As String * 7
    
    MainHwnd = TaskbarHwnd
    CHwnd = GetWindow(MainHwnd, GW_CHILD)
    Do While CHwnd <> 0
        GetClassName CHwnd, CLS_NM, 7
        If Left(CLS_NM, 6) = "Button" Then
            hwnd = CHwnd
            Exit Property
        End If
        CHwnd = GetWindow(CHwnd, GW_NEXT)
    Loop

End Property

'Set picture. ie hPic (LoadPicture("C:\mystart.bmp"))
Property Let hPic(ByVal hPicture As Long)
    
    PostMessage hwnd, BM_SETIMAGE, 0, hPicture

End Property
Property Let Width(ByVal sWidth As Long)
    
    SetWindowPos hwnd, 0, 0, 0, sWidth / 15, Height / 15, 2

End Property

Property Get Width() As Long
    
    Dim tmpRECT As RECT
    
    GetWindowRect hwnd, tmpRECT
    Width = (tmpRECT.Right - tmpRECT.Left) * 15
    
End Property

Property Let Height(ByVal sHeight As Long)
    
    SetWindowPos hwnd, 0, 0, 0, Width / 15, sHeight / 15, 2

End Property

Property Get Height() As Long
    
    Dim tmpRECT As RECT
    
    GetWindowRect hwnd, tmpRECT
    Height = (tmpRECT.Bottom - tmpRECT.Top) * 15

End Property

Property Let Left(ByVal lX As Long)
    
    SetWindowPos hwnd, 0, lX / 15, Top / 15, 0, 0, 1

End Property

Property Get Left() As Long
    
    Dim tmpPLC As WINDOWPLACEMENT
    
    tmpPLC.Length = Len(tmpPLC)
    GetWindowPlacement Start.hwnd, tmpPLC
    
    Left = tmpPLC.rcNormalPosition.Left * 15

End Property
Property Let Top(ByVal lY As Long)
    
    SetWindowPos hwnd, 0, Left / 15, lY / 15, 0, 0, 1

End Property
Property Get Top() As Long
    
    Dim tmpPLC As WINDOWPLACEMENT
    
    tmpPLC.Length = Len(tmpPLC)
    GetWindowPlacement Start.hwnd, tmpPLC
    
    Top = tmpPLC.rcNormalPosition.Top * 15

End Property
Property Let Parent(ByVal hParent As Long)
    
    SetParent hwnd, hParent

End Property
Property Get Parent() As Long
    
    Parent = GetParent(hwnd)

End Property


Download this snippet    Add to My Saved Code

Code to return and change the picture, width, height and position of the start button. V good code, Comments

No comments have been posted about Code to return and change the picture, width, height and position of the start button. V good code,. Why not be the first to post a comment about Code to return and change the picture, width, height and position of the start button. V good code,.

Post your comment

Subject:
Message:
0/1000 characters