khchen / wNim

Nim's Windows GUI Framework
MIT License
326 stars 17 forks source link

wButton background color cannot work #84

Closed leeooox closed 3 years ago

leeooox commented 3 years ago

Hi,

When I try to set the background color of the button in my project, it seems only border color is applied while the area inside border unchanged.

This is a simple code to reproduce the issue. The task is to set the background of button to red color As the picture, the statictext control works well, but button has problem. image

import wNim/[wApp, wFrame, wPanel, wButton,wStaticText]

let app = App()
let frame = Frame(title="Button background color",size=(400,200))
let panel = Panel(frame)
var btn1 = Button(panel,label="OK",pos=(10,10))
var lbl1 = StaticText(panel,label ="some text", pos=(10,50))
btn1.setBackgroundColor(wRed)
lbl1.setBackgroundColor(wRed)

frame.center()
frame.show()
app.mainLoop()
khchen commented 3 years ago

Background color of button don't work for visual styles. Reference: https://docs.microsoft.com/en-us/windows/win32/controls/visual-styles-overview

leeooox commented 3 years ago

Hi @khchen,

Thanks. But how to disable the visual styles in wNim for the purpose of button background display?

khchen commented 3 years ago

Sorry, it's my mistake. Visual styles is not a problem. According to https://docs.microsoft.com/en-us/windows/win32/controls/wm-ctlcolorbtn:

By default, the DefWindowProc function selects the default system colors for the button. Buttons with the BS_PUSHBUTTON, BS_DEFPUSHBUTTON, or BS_PUSHLIKE styles do not use the returned brush. Buttons with these styles are always drawn with the default system colors. Drawing push buttons requires several different brushes-face, highlight, and shadow-but the WM_CTLCOLORBTN message allows only one brush to be returned. To provide a custom appearance for push buttons, use an owner-drawn button. For more information, see Creating Owner-Drawn Controls.

wButton is BS_PUSHBUTTON. So the only way to change it's color is by Creating Owner-Drawn Controls BTW, you can disable visual styles by add -d:nores. However, some controls may not work because I had never tested them. And I believe some codes only make sense with visual styles.