If the function succeeds, the return value specifies the previous background color as a COLORREF value.
If the function fails, the return value is CLR_INVALID.
...
So, the command is implemented and am I not using it correctly?
Or not?
:-\
https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror
'$ 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
// Standard Button and Color (Owner Drawn) Button
$ filename "Std_and_ClrBtn.exe"
'uses rtl32
'uses rtl64
$ EscapeKeyEnd
uses WinUtil
% EDGE_RAISED=5
% EDGE_SUNKEN=10
% BF_RECT=15
% WM_DRAWITEM=43
% ETO_OPAQUE=2
% ETO_CLIPPED=4
% ODS_SELECTED=1
% GWL_HINSTANCE -6
type SIZE
long cx
long cy
end type
type DRAWITEMSTRUCT
UINT CtlType
UINT CtlID
UINT itemID
UINT itemAction
UINT itemState
sys hwndItem
sys hDC
RECT rcItem
sys itemData 'ulong_ptr
end type
% IDB_BUTTON 100
sys hWndStdButton
% IDC_OWNERDRAWN 1000
sys hWndClrButton
MainWindow 240, 120 , WS_OVERLAPPEDWINDOW
function WndProc(sys hwnd, uint MainMsg, sys wParam, lParam) as sys callback
select case MainMsg
case WM_CREATE
SetWindowText(hwnd, "Buttons")
sys hInstance = GetWindowLongPtr(hWnd, GWL_HINSTANCE)
hWndStdButton = CreateWindowEx(
0,
"BUTTON",
"Standard Button",
WS_VISIBLE or WS_CHILD,
10, 10,
120, 24,
hWnd,
IDB_BUTTON,
hInstance,
NULL)
hWndClrButton = CreateWindowEx(
0,
"BUTTON",
NULL,
WS_CHILD or BS_OWNERDRAW,
10, 40,
120, 24,
hWnd,
IDC_OWNERDRAWN,
GetWindowLongPtr(hWnd, GWL_HINSTANCE),
NULL)
if not hWndClrButton then
MessageBox(NULL, "Button Creation Failed.", "Error", MB_OK or MB_ICONERROR)
return 0
end if
ShowWindow(hWndClrButton, SW_SHOW)
case WM_DRAWITEM
select case wParam
case IDC_OWNERDRAWN
'get the pointer to the item-drawing info
DRAWITEMSTRUCT *ptDrawItem
&ptDrawItem=lParam
' alternative
'DRAWITEMSTRUCT ptDrawItem at lParam
SIZE siz
string text
text = "Color Button"
GetTextExtentPoint32(ptDrawItem.hDC, text, len(text), &siz)
SetTextColor(ptDrawItem.hDC, WHITE)
SetBkColor(ptDrawItem.hDC, RED)
ExtTextOut(ptDrawItem.hDC,
((ptDrawItem.rcItem.right - ptDrawItem.rcItem.left) - siz.cx) \ 2,
((ptDrawItem.rcItem.bottom - ptDrawItem.rcItem.top) - siz.cy) \ 2,
ETO_OPAQUE or ETO_CLIPPED, &ptDrawItem.rcItem, text, len(text), NULL)
uint edge
if ptDrawItem.itemState and ODS_SELECTED then
edge = EDGE_SUNKEN
else
edge = EDGE_RAISED
end if
DrawEdge(ptDrawItem.hDC, &ptDrawItem.rcItem,
edge, BF_RECT)
end select
case WM_COMMAND
select case loword(wParam)
case IDB_BUTTON
select case hiword(wParam)
case BN_CLICKED
MessageBox(NULL, "Selected Standard Button", "Standard Button", MB_OK or MB_ICONINFORMATION)
end select
case IDC_OWNERDRAWN
select case hiword(wParam)
case BN_CLICKED
MessageBox(NULL, "Selected Color Button", "Color Button", MB_OK or MB_ICONINFORMATION)
end select
end select
case WM_CLOSE
DestroyWindow(hWnd)
case WM_DESTROY
PostQuitMessage(0)
case else
return DefWindowProc(hWnd, MainMsg, wParam, lParam)
end select
return 0
end function