我在窗体里加入了ApplicationEvents控件,然后在OnMessage事件里判断
procedure TForm1.AppEventsMessage(var Msg: tagMSG; var Handled: Boolean);
begin
if Msg.hwnd = StringGrid1.Handle then
begin
if Msg.message = WM_HSCROLL then
begin
Edit1.Text := 'abc';
end;
end;
end;但是这个做法不成功,请高手指点一下,谢谢。
procedure TForm1.AppEventsMessage(var Msg: tagMSG; var Handled: Boolean);
begin
if Msg.hwnd = StringGrid1.Handle then
begin
if Msg.message = WM_HSCROLL then
begin
Edit1.Text := 'abc';
end;
end;
end;但是这个做法不成功,请高手指点一下,谢谢。
http://www.zjmf.com/A06/A0607/A060703/200512/2973.html
TForm1 = class(TForm)
...
private
oldProc: TWndMethod;
procedure MyProc(var Message: TMessage);
procedure TForm1.FormCreate(Sender: TObject);
var
mask: Word;
begin
OldProc := StringGrid1.WindowProc;
StringGrid1.WindowProc := self.MyProc;
procedure TForm1.FormDestroy(Sender: TObject);
begin
StringGrid1.WindowProc := OldProc;
end;procedure TForm1.MyProc(var Message: TMessage);
begin
if ((Message.Msg = WM_VSCROLL) or (Message.Msg = WM_HSCROLL) or
(Message.msg = WM_Mousewheel)) then
Memo1.Lines.Add(TimeToStr(now)); OldProc(Message);
end;
怎么你的会呢?
我在D7下面Form1和StringGrid1都触发MyProc
可以这样把窗体的消息给处理了
TForm1 = class(TForm)
private
{ Private declarations }
protected
procedure WndProc(var Message: TMessage); override;
public
{ Public declarations }
end;
procedure TForm1.WndProc(var Message: TMessage);
begin
if (message.Msg = WM_HScroll) or (message.Msg = WM_VScroll)
or (message.Msg = WM_MouseWheel) then else
inherited;
end;