본문 바로가기
개발언어/VB

ToolBar API (그림, 색깔지정)

by 엔돌슨 2008. 4. 8.
반응형
 Toolbar 색깔, 이미지 지정 API

 

코드

  1. Public Declare Function SetClassLong Lib "user32" Alias "SetClassLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwnewlong As Long) As Long
    Public Declare Function OleTranslateColor Lib "oleaut32.dll" (ByVal lOleColor As Long, ByVal lHPalette As Long, ByRef lColorRef As Long) As Long
    Public Declare Function CreateSolidBrush Lib "gdi32.dll" (ByVal crColor As Long) As Long
    Public Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
    Public Declare Function CreatePatternBrush Lib "gdi32.dll" (ByVal hBitmap As Long) As Long
    Public Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, lpRect As Long, ByVal bErase As Long) As Long

    Public Const GCL_HBRBACKGROUND As Long = -10

    Public Function GDI_TranslateColor(OleClr As OLE_COLOR, Optional hPal As Integer = 0) As Long
    ' used to return the correct color value of OleClr as a long
    If OleTranslateColor(OleClr, hPal, GDI_TranslateColor) Then
    GDI_TranslateColor = &HFFFF&
    End If
    End Function

    Public Function GDI_CreateSoildBrush(bColor As OLE_COLOR) As Long
    'Create a Brush form a picture handle
    GDI_CreateSoildBrush = CreateSolidBrush(GDI_TranslateColor(bColor))
    End Function

    Public Sub SetToolbarBG(hwnd As Long, hBmp As Long)
    'Set the toolbars background image
    DeleteObject SetClassLong(hwnd, GCL_HBRBACKGROUND, CreatePatternBrush(hBmp))
    InvalidateRect 0&, 0&, False
    End Sub

    Public Sub SetToolbarBK(hwnd As Long, hColor As OLE_COLOR)
    ' Set a toolbars Backcolor
    DeleteObject SetClassLong(hwnd, GCL_HBRBACKGROUND, GDI_CreateSoildBrush(hColor))
    InvalidateRect 0&, 0&, False
    End Sub

 

 

함수호출
  • SetToolbarBK는 배경색
  1. Call SetToolbarBK(Toolbar1.hwnd, vbYellow)

 

  • SetToolbarBG는 배경이미지 
  1. SetToolbarBG Toolbar1.hwnd, Image1.Picture

 

 

출처는 하뱅과 중국블로그 입니다. 중국블로그에 전체소스와 중국어로 작성된 데모도 있네요. 정작 필요한 부분은 위에 선언부와 호출함수 딱2개 뿐이지만요 ^^

 

 

 

 

 

 

 

 

이 글은 스프링노트에서 작성되었습니다.