Hi Nicola,
Demo of toggling owner-drawn button. It's all new to me, and required some google and msdn:
the key points are
style=WS_CHILD | BS_OWNERDRAW
and
case WM_CTLCOLORBTN
...
'$ filename "t.exe"
'uses RTL64
$ EscapeKeyEnd
uses WinUtil
MainWindow 640,480,WS_OVERLAPPEDWINDOW
'STANDARD CHILD WINDOWS STYLES
==============================
'
'Button button.
'ComboBox combo box.
'Edit edit box.
'ListBox list box.
'MDIClient MDI client window.
'ScrollBar scroll bar.
'Static static control.
function WndProc(sys hwnd, uMsg, wParam, lParam) as long callback
=================================================================
indexbase 0
RECT rcClient;
sys i,id,idmenu,style
static sys hchw[0x200] 'child windows
string s,stys
static int bcolor=0xaabbee
select umsg
case WM_CREATE
idmenu=0
'
SetWindowText hwnd,"Owner Draw Button and Edit Box"
'https://docs.microsoft.com/en-us/windows/win32/controls/wm-ctlcolorbtn
style=WS_CHILD | BS_OWNERDRAW
stys="button"
hchw[0]=CreateWindowEx(0,stys, null, style, 0,0,0,0, hwnd, 100, inst, null)
style=WS_CHILD | WS_BORDER | WS_VISIBLE
stys="edit"
hchw[1]=CreateWindowEx(0,stys, null, style, 0,0,0,0, hwnd, 101, inst, null)
ShowWindow(hchw[i], SW_SHOW)
case WM_CTLCOLORBTN
sys hdc=wparam
sys hwn=lparam
RECT rec
if hwn=hchw[0]
GetClientRect hwn,@rec
sys hbr=CreateSolidBrush bcolor
FillRect hdc,@rec,hbr
SetBkColor hdc,bcolor
SetTextColor hdc,0x90
DrawText hDC,"Press",-1,@rec,0x25
DeleteObject hbr
return hbr
endif
case WM_COMMAND
int id=loword wparam
int cmd=hiword wparam
select id
case 100
'print str cmd
bcolor=1-bcolor 'TOGGLE
SetWindowText hchw[0],"ok"
end select
case WM_SIZE // main window changed size
RECT rc
GetClientRect(hwnd, &rc)
'child window, position x,y size x.y, show
MoveWindow(hchw[0], 10,10, 80, 40, TRUE)
MoveWindow(hchw[1], 10,60, rc.right-20, rc.bottom-70, TRUE)
case WM_DESTROY:
PostQuitMessage 0
case else
return DefWindowProc(hwnd, uMsg, wParam, lParam)
end select
'
end function