Tuesday, December 16, 2008

[vb6] Make the toolbar buttons flat

If you have Visual Basic 6, you have the option of creating a toolbar with flat-style buttons. If you have earlier versions of VB, you'll have to do it yourself, like this:
    Public Declare Function FindWindowEx& Lib "user32" Alias "FindWindowExA" _
(ByVal hWndParent As Long, ByVal hWndChildAfter As Long, _
ByVal lpClassName As String, ByVal lpWindowName As String)
Public Declare Function SendMessageBynum& Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long)
Public Const WM_USER& = &H400
Public Const TBSTYLE_FLAT& = &H800
Public Const TB_SETSTYLE& = (WM_USER + 56)
Public Const TB_GETSTYLE& = (WM_USER + 57)
Public Const TBCLASSNAME = "ToolbarWindow32"

'Make a toolbar flat style
Public Sub MakeFlat(Tb As Toolbar)

Dim Style&, TbHandle&

TbHandle = FindWindowEx(Tb.hwnd, 0&, TBCLASSNAME, vbNullString)
If TbHandle = 0 Then Debug.Print "Error"

Style = SendMessageBynum(TbHandle, TB_GETSTYLE, 0&, 0&)
Style = Style Or TBSTYLE_FLAT

Call SendMessageBynum(TbHandle, TB_SETSTYLE, 0, Style)

End Sub

No comments:

Post a Comment