In our company we use a very potent descendant of TCustomButton.
For a new application I want a button that basically behaves like a "Speedbtn", which has no TabStop and especially don't steals the focus of other controls like for example a TEdit. I would love if I'm able to just maniuplate our descendant of the TCustomButton, so that I don't have to write a whole new button coomponent, for which I would have to implement many things that our descendant of TCustomButton already offers (like Corporate Design etc.)
I'm aware that this isn't an easy task, because as far as I understand, the decision that the click on the button triggers the message to focus himself ( which steals the focus of the Tedit), depends on the registry in windows ("TCustomButton.CreateParams" ??).
If a possible solution is too much of a hack, i probably won't even use it in our system, but I still would be pretty interested in it, because I'm a curious person :).
Anyway here's my example: I have a TForm which only contains a TEdit and a descendant of TCustomButton, which already has lost the functionality (which it orignally had by being a descendant of TButtonControl) to get the focus if WM_LBUTTONDOWN or WM_LBUTTONDBLCLK comes by in WndProc.
type
TMyBtn = class (TCustomButton)
//
// ... A lot of self-written stuff
//
protected
procedure WndProc(var Message: TMessage); override;
public
//
// ... A lot of self-written Properties
//
end;
type
TForm2 = class(TForm)
Edit1: TEdit;
Button1: TMyBtn;
end;
implementation
procedure TMyBtn.WndProc(var Message: TMessage);
var
hProc : procedure (var Message: TMessage) of object;
begin
// Skip TButtonControl.WndProc and call
// TWinControl.WndProc instead if Message type
// is WM_LBUTTONDOWN or WM_LBUTTONDBLCLK
if not (csDesigning in ComponentState) then
begin
case Message.Msg of
WM_LBUTTONDOWN, WM_LBUTTONDBLCLK:
begin
TMethod(hProc).Code := @TWinControl.WndProc;
TMethod(hProc).Data := Self;
hProc( Message);
exit;
end;
end;
end;
inherited WndProc(Message);
end;
What can I do, that the TEdit doesn't lose the focus if the TEdit has the focus and i click on the descendant of TCustomButton ( other than disabling the button or refocusing the TEdit etc.)
Many Thanks for any help in advance.
If I didn't manage to describe my question properly, feel free to ask me any questions.