procedure TForm1.WMDrawItem(var Message: TWMDrawItem);
var
Brush1: THandle;
begin
Message.Result := 1;
if Message.Ctl <> but_OwnerDraw.Handle then
inherited else
begin
SelectObject(Message.DrawItemStruct.hDC, but_OwnerDraw.Font.Handle);
if Message.DrawItemStruct.itemState = ODS_DISABLED then
begin
{test the itemState to see if disabled
this is painting for a Disabled button
a Grey color}
SetBkColor(Message.DrawItemStruct.hDC, $00BBBBBB);
FillRect(Message.DrawItemStruct.hDC, Message.DrawItemStruct.rcItem, GetStockObject(LTGRAY_BRUSH));
SetBkMode(Message.DrawItemStruct.hDC,TRANSPARENT);
SetTextColor(Message.DrawItemStruct.hDC,$00DDDDDD);
TextOut(Message.DrawItemStruct.hDC,8,8,PChar(but_OwnerDraw.Caption),Length(but_OwnerDraw.Caption));
SetTextColor(Message.DrawItemStruct.hDC,$00666666);
TextOut(Message.DrawItemStruct.hDC,6,6,PChar(but_OwnerDraw.Caption),Length(but_OwnerDraw.Caption));
end else
begin
{this is painting for a normal button
an Yellow color}
Brush1 := CreateSolidBrush($0000FFFF);
SetBkColor(Message.DrawItemStruct.hDC, $0000FFFF);
FillRect(Message.DrawItemStruct.hDC, Message.DrawItemStruct.rcItem, Brush1);
DeleteObject(Brush1);
TextOut(Message.DrawItemStruct.hDC,6,6,PChar(but_OwnerDraw.Caption),Length(but_OwnerDraw.Caption));
end;
if (Message.DrawItemStruct.itemState and ODS_SELECTED) <> 0 then
DrawEdge(Message.DrawItemStruct.hDC, Message.DrawItemStruct.rcItem, EDGE_SUNKEN, BF_RECT)
else
DrawEdge(Message.DrawItemStruct.hDC, Message.DrawItemStruct.rcItem, EDGE_RAISED, BF_RECT);
if Message.DrawItemStruct.itemState = ODS_FOCUS then
begin
InflateRect(Message.DrawItemStruct.rcItem,-4,-4);
DrawFocusRect(Message.DrawItemStruct.hDC, Message.DrawItemStruct.rcItem);
{make the rcRect smaller and draw a focus Rect}
end;
end;
end;