github.com/secoba/wails/v2@v2.6.4/internal/frontend/desktop/windows/winc/w32/uxtheme.go (about)

     1  //go:build windows
     2  
     3  /*
     4   * Copyright (C) 2019 Tad Vizbaras. All Rights Reserved.
     5   * Copyright (C) 2010-2012 The W32 Authors. All Rights Reserved.
     6   */
     7  
     8  package w32
     9  
    10  import (
    11  	"syscall"
    12  	"unsafe"
    13  )
    14  
    15  // LISTVIEW parts
    16  const (
    17  	LVP_LISTITEM         = 1
    18  	LVP_LISTGROUP        = 2
    19  	LVP_LISTDETAIL       = 3
    20  	LVP_LISTSORTEDDETAIL = 4
    21  	LVP_EMPTYTEXT        = 5
    22  	LVP_GROUPHEADER      = 6
    23  	LVP_GROUPHEADERLINE  = 7
    24  	LVP_EXPANDBUTTON     = 8
    25  	LVP_COLLAPSEBUTTON   = 9
    26  	LVP_COLUMNDETAIL     = 10
    27  )
    28  
    29  // LVP_LISTITEM states
    30  const (
    31  	LISS_NORMAL           = 1
    32  	LISS_HOT              = 2
    33  	LISS_SELECTED         = 3
    34  	LISS_DISABLED         = 4
    35  	LISS_SELECTEDNOTFOCUS = 5
    36  	LISS_HOTSELECTED      = 6
    37  )
    38  
    39  // TREEVIEW parts
    40  const (
    41  	TVP_TREEITEM = 1
    42  	TVP_GLYPH    = 2
    43  	TVP_BRANCH   = 3
    44  	TVP_HOTGLYPH = 4
    45  )
    46  
    47  // TVP_TREEITEM states
    48  const (
    49  	TREIS_NORMAL           = 1
    50  	TREIS_HOT              = 2
    51  	TREIS_SELECTED         = 3
    52  	TREIS_DISABLED         = 4
    53  	TREIS_SELECTEDNOTFOCUS = 5
    54  	TREIS_HOTSELECTED      = 6
    55  )
    56  
    57  type HTHEME HANDLE
    58  
    59  var (
    60  	// Library
    61  	libuxtheme uintptr
    62  
    63  	// Functions
    64  	closeThemeData      uintptr
    65  	drawThemeBackground uintptr
    66  	drawThemeText       uintptr
    67  	getThemeTextExtent  uintptr
    68  	openThemeData       uintptr
    69  	setWindowTheme      uintptr
    70  )
    71  
    72  func init() {
    73  	// Library
    74  	libuxtheme = MustLoadLibrary("uxtheme.dll")
    75  
    76  	// Functions
    77  	closeThemeData = MustGetProcAddress(libuxtheme, "CloseThemeData")
    78  	drawThemeBackground = MustGetProcAddress(libuxtheme, "DrawThemeBackground")
    79  	drawThemeText = MustGetProcAddress(libuxtheme, "DrawThemeText")
    80  	getThemeTextExtent = MustGetProcAddress(libuxtheme, "GetThemeTextExtent")
    81  	openThemeData = MustGetProcAddress(libuxtheme, "OpenThemeData")
    82  	setWindowTheme = MustGetProcAddress(libuxtheme, "SetWindowTheme")
    83  }
    84  
    85  func CloseThemeData(hTheme HTHEME) HRESULT {
    86  	ret, _, _ := syscall.Syscall(closeThemeData, 1,
    87  		uintptr(hTheme),
    88  		0,
    89  		0)
    90  
    91  	return HRESULT(ret)
    92  }
    93  
    94  func DrawThemeBackground(hTheme HTHEME, hdc HDC, iPartId, iStateId int32, pRect, pClipRect *RECT) HRESULT {
    95  	ret, _, _ := syscall.Syscall6(drawThemeBackground, 6,
    96  		uintptr(hTheme),
    97  		uintptr(hdc),
    98  		uintptr(iPartId),
    99  		uintptr(iStateId),
   100  		uintptr(unsafe.Pointer(pRect)),
   101  		uintptr(unsafe.Pointer(pClipRect)))
   102  
   103  	return HRESULT(ret)
   104  }
   105  
   106  func DrawThemeText(hTheme HTHEME, hdc HDC, iPartId, iStateId int32, pszText *uint16, iCharCount int32, dwTextFlags, dwTextFlags2 uint32, pRect *RECT) HRESULT {
   107  	ret, _, _ := syscall.Syscall9(drawThemeText, 9,
   108  		uintptr(hTheme),
   109  		uintptr(hdc),
   110  		uintptr(iPartId),
   111  		uintptr(iStateId),
   112  		uintptr(unsafe.Pointer(pszText)),
   113  		uintptr(iCharCount),
   114  		uintptr(dwTextFlags),
   115  		uintptr(dwTextFlags2),
   116  		uintptr(unsafe.Pointer(pRect)))
   117  
   118  	return HRESULT(ret)
   119  }
   120  
   121  func GetThemeTextExtent(hTheme HTHEME, hdc HDC, iPartId, iStateId int32, pszText *uint16, iCharCount int32, dwTextFlags uint32, pBoundingRect, pExtentRect *RECT) HRESULT {
   122  	ret, _, _ := syscall.Syscall9(getThemeTextExtent, 9,
   123  		uintptr(hTheme),
   124  		uintptr(hdc),
   125  		uintptr(iPartId),
   126  		uintptr(iStateId),
   127  		uintptr(unsafe.Pointer(pszText)),
   128  		uintptr(iCharCount),
   129  		uintptr(dwTextFlags),
   130  		uintptr(unsafe.Pointer(pBoundingRect)),
   131  		uintptr(unsafe.Pointer(pExtentRect)))
   132  
   133  	return HRESULT(ret)
   134  }
   135  
   136  func OpenThemeData(hwnd HWND, pszClassList *uint16) HTHEME {
   137  	ret, _, _ := syscall.Syscall(openThemeData, 2,
   138  		uintptr(hwnd),
   139  		uintptr(unsafe.Pointer(pszClassList)),
   140  		0)
   141  
   142  	return HTHEME(ret)
   143  }
   144  
   145  func SetWindowTheme(hwnd HWND, pszSubAppName, pszSubIdList *uint16) HRESULT {
   146  	ret, _, _ := syscall.Syscall(setWindowTheme, 3,
   147  		uintptr(hwnd),
   148  		uintptr(unsafe.Pointer(pszSubAppName)),
   149  		uintptr(unsafe.Pointer(pszSubIdList)))
   150  
   151  	return HRESULT(ret)
   152  }