This is related to the question How to show a check box in TListView header column?.
I want to use the code from this answer by @Sertac Akyuz
. (I need this to work in WinXP also)
But I want to make the header CheckBox to not steal focus from the ListView or other active controls.
A fast workaround is to set the focus always to the ListView in the ListHeaderWndProc
:
...
FListHeaderChk.Checked := not FListHeaderChk.Checked;
ListView1.SetFocus;
// code that checks/clears all items
But this is kinda ugly. Because the CheckBox is first focused and then the focus goes back to the ListView. also If I click the CheckBox and drag the mouse outside the CheckBox it fails to receive the BN_CLICKED
message.
I have also tried:
TCheckBox = class(StdCtrls.TCheckBox)
private
procedure WMMouseActivate(var Message: TWMMouseActivate); message WM_MOUSEACTIVATE;
protected
procedure CreateParams(var Params: TCreateParams); override;
public
procedure DefaultHandler(var Message); override;
end;
procedure TCheckBox.WMMouseActivate(var Message: TWMMouseActivate);
begin
Message.Result := MA_NOACTIVATE; // no effect!
end;
procedure TCheckBox.CreateParams(var Params: TCreateParams);
const
WS_EX_NOACTIVATE = $08000000;
begin
inherited;
Params.ExStyle := Params.ExStyle or WS_EX_NOACTIVATE; // no effect!
end;
procedure TCheckBox.DefaultHandler(var Message);
begin
case TMessage(Message).Msg of
WM_SETFOCUS:
begin
if IsWindow(TWMSetFocus(Message).FocusedWnd) then
begin
TMessage(Message).Result := 1; // ???
// inherited // ???
Windows.SetFocus(TWMSetFocus(Message).FocusedWnd);
Exit;
// Checkbox fails to receive `BN_CLICKED` message
end;
end;
end;
inherited;
end;
Nothing works. What am I missing?
TabStop := False
. That was obvious. Using owner-drawn header is a good alternative, but this wont answer the question, and what is the fun about that? ;) – Nez