继承自TComponent的类如何响应消息?
我要做一个在非客户区的按扭控件。注:是控件,不单是绘制一个按扭并响应消息。
现在是继承自TComponent的类,但是要如何响应消息?
[解决办法]
明明说的非客户区,不好意思.
楼主的意思是不是一个控件,然后在具有客户区的Parent(如Form)上绘制东西并响应?如何是的话,从TGraphicControl开始继承
[解决办法]
实现各个响应消息的函数。
[解决办法]
在承至TComponent的...私用以 Windows API 之 AllocateHWnd() 函式建立易藏窗口消息...作法如同 VCL 程序架的全域藏窗口 Application......
[解决办法]
在原文 Charlie Calvert's Borland C++ Builder 4 Unleashed: The Comprehensive Solution 有 LZ 所要的技料...不例是 C++Builder 的...我手上有一本台出版社所行的中本...名 C++ Builder 4 Unleashed 深入出...不定是不是中大地所行的 C++ Builder 4 核心幕中本......
[解决办法]
在外部进程上绘图和响应?还是本进程?
[解决办法]
参考 Buttons.TSpeedButton 应该可以满足你的要求,继承自TGraphicControl
[解决办法]
看起来是非客户区,其实可能是客户区。
[解决办法]
第一种会不会比较省事?
[解决办法]
Type
TFormMessage = class(TComponent)
private
fParentForm : TForm;
fOldProc : TWndMethod;
procedure MessageProc(var Message: TMessage);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure SetForm(const Value: TForm);
end;
{ TFormMessage }
constructor TFormMessage.Create(AOwner: TComponent);
begin
inherited;
while AOwner<>NIL do begin
if AOwner is TForm then begin
SetForm(TForm(AOwner));
Break;
end;
AOwner := AOwner.Owner;
end;
end;
destructor TFormMessage.Destroy;
begin
SetForm(NIL);
inherited;
end;
procedure TFormMessage.SetForm(const Value: TForm);
begin
if Value = fParentForm then exit;
if fParentForm <> NIL then begin
fParentForm.WindowProc := fOldProc;
fParentForm := NIL;
fOldProc := NIL;
end;
if Value <> NIL then begin
fParentForm := Value;
fOldProc := Value.WindowProc;
Value.WindowProc := MessageProc;
end;
end;
procedure TFormMessage.MessageProc(var Message: TMessage);
var
bCallDefault : Boolean;
begin
bCallDefault := True;
if Message.Msg = WM_NCCALCSIZE then begin
//该消息的处理代码
//bCallDefault := False; //覆盖选项
fParentForm.Caption := fParentForm.Caption + 'a';
end;
if bCallDefault and Assigned(fOldProc) then fOldProc(Message);
end;