• Contributions
  • Changing the Title bar color in LuaRT 1.9.0 using the C module

Code:

local ui = require("ui")
local c = require("c")

local dwm = c.Library("dwmapi.dll")

-- Define a struct for the widget and a function to convert pointers to hex
local Widget = c.Struct("ip", "type", "hwnd")
local function pointer_to_hex(ptr)
    return string.format("0x%X", ptr)
end

-- Define constants for DWM and window styles
local DWMWA_CAPTION_COLOR = 35  -- Attribute for title bar color
local RGB_BLUE = 0x00dc9021   -- Blue color in RGB (hex format)

-- DWM function for setting window attributes
dwm.DwmSetWindowAttribute = "(pIpI)I"

-- Function to set the title bar color of the given window
local function set_titlebar_color(MAINWINDOW)
    local handle = Widget(MAINWINDOW).hwnd
    local rgb = c.Value("uint32_t", RGB_BLUE)
    -- Set the title bar color using DWM
    dwm.DwmSetWindowAttribute(handle, DWMWA_CAPTION_COLOR, rgb, 4)
end

-- Create a window and set its title bar color
local win = ui.Window("A Test")
set_titlebar_color(win)

-- Run the UI window
ui.run(win):wait()
```

I strongly recommend integrating the c module into the core, because the c module is basic and powerful!

Powered by: FreeFlarum.
(remove this footer)