简体   繁体   English

更改平面滚动条的颜色(FlatSB_SetScrollProp 函数中的自定义调色板)

[英]Change colors of flat scroll bars (custom palette in FlatSB_SetScrollProp function)

One of my customers uses the standard flat scroll bars introduced in MSIE 4 inside the list/grid controls in his VB6 app.我的一位客户在其 VB6 应用程序的列表/网格控件内使用 MSIE 4 中引入的标准平面滚动条 Now he wants to implement a dark theme in his app and needs to colorize these flat scroll bars respectively.现在他想在他的应用程序中实现一个深色主题,并需要分别为这些平面滚动条着色。 The FlatSB_SetScrollProp WinAPI function allows us to change color parameters of flat scroll bars. FlatSB_SetScrollProp WinAPI 函数允许我们更改平面滚动条的颜色参数。 I could easily specify the background color of the shaded shaft with the WSB_PROP_HBKGCOLOR/WSB_PROP_VBKGCOLOR values, but we need to change other colors - the background color of the scroll box, the color of arrows on the buttons, etc. FlatSB_SetScrollProp provides us with the ability to specify a custom palette for the scroll bars with the WSB_PROP_PALETTE value, but I couldn't find any working sample in the Internet showing how to do that.我可以使用 WSB_PROP_HBKGCOLOR/WSB_PROP_VBKGCOLOR 值轻松指定阴影轴的背景颜色,但我们需要更改其他颜色 - 滚动框的背景颜色、按钮上箭头的颜色等。 FlatSB_SetScrollProp 为我们提供了能力使用 WSB_PROP_PALETTE 值为滚动条指定自定义调色板,但我在 Internet 上找不到任何显示如何执行此操作的工作示例。 What I found were code snippets like this and this , but obviously they don't work.我发现的是像这样这样的代码片段,但显然它们不起作用。 Can anybody provide a working sample for FlatSB_SetScrollProp with WSB_PROP_PALETTE?有人可以为带有 WSB_PROP_PALETTE 的 FlatSB_SetScrollProp 提供工作示例吗?


Some VB6 source code I used to play with palettes in flat scroll bars:我曾经在平面滚动条中使用调色板的一些 VB6 源代码:

Private Type PALETTEENTRY
   peRed As Byte
   peGreen As Byte
   peBlue As Byte
   peFlags As Byte
End Type

Private Type LOGPALETTE
   palVersion As Integer
   palNumEntries As Integer
   palPalEntry(255) As PALETTEENTRY ' Enough for 256 colors.
End Type

Private Declare Function CreatePalette Lib "gdi32" (ByRef lpLogPalette As LOGPALETTE) As Long

Private Const WSB_PROP_PALETTE = &H800&

Private Declare Function FlatSB_SetScrollProp Lib "comctl32.dll" (ByVal hWnd As Long, ByVal Index As Long, ByVal newValue As Long, ByVal fRedraw As Boolean) As Long

Friend Sub SetCustomPalette()
   Dim LogPal As LOGPALETTE
   Dim hPal As Long
   
   LogPal.palNumEntries = 256
   LogPal.palVersion = &H300
   
   Dim iPalEntry As Long
   For iPalEntry = 0 To 255
      LogPal.palPalEntry(iPalEntry).peRed = iPalEntry
      'LogPal.palPalEntry(iPalEntry).peGreen = iPalEntry
      'LogPal.palPalEntry(iPalEntry).peBlue = iPalEntry
      'LogPal.palPalEntry(iPalEntry).peFlags = 4
   Next
   
   hPal = CreatePalette(LogPal)
   
   Dim lRes As Long
   lRes = FlatSB_SetScrollProp(m_hWnd, WSB_PROP_PALETTE, hPal, True)
End Sub

I checked the results of the CreatePalette and FlatSB_SetScrollProp calls - they were successful.我检查了 CreatePalette 和 FlatSB_SetScrollProp 调用的结果 - 他们成功了。 I tried to fill only the peRed component or all R/G/B of a palette entry, tried all available values for peFlags, but nothing helped.我尝试仅填充 peRed 组件或调色板条目的所有 R/G/B,尝试了 peFlags 的所有可用值,但没有任何帮助。

Perhaps, we also need to update the scroll bars in the target window after setting the palette or do something else to make it work.也许,我们还需要在设置调色板后更新目标窗口中的滚动条或执行其他操作以使其工作。 Any suggestions or ideas regarding this are welcome.欢迎对此提出任何建议或想法。

The FlatSB_SetScrollProp for WSB_PROP_VBKGCOLOR and WSB_PROP_HBKGCOLOR are really the only ones you can change for the scroll bar. WSB_PROP_VBKGCOLOR 和 WSB_PROP_HBKGCOLOR 的 FlatSB_SetScrollProp 实际上是唯一可以为滚动条更改的。 The changing of the color palette will not change any other elements on the scroll bar if changed.如果更改了调色板,则不会更改滚动条上的任何其他元素。

The usage of the palettes is not really recommended any further for applications and in newer window styles the flatsb APIs no longer work.对于应用程序,不再推荐使用调色板,并且在较新的窗口样式中,flatsb API 不再有效。 If you are wanting to use a best fit color from your palette to the requested color you can use the GetNearestPaletteIndex to get the index of the entry for the logical palette and grab the RGB values from that to use as the color for the VBKGCOLOR and HBKGCOLOR.如果您想将调色板中的最适合颜色用于请求的颜色,您可以使用 GetNearestPaletteIndex 获取逻辑调色板条目的索引并从中获取 RGB 值以用作 VBKGCOLOR 和 HBKGCOLOR 的颜色.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM