1.重载WndProc函数
2.写一个自己的处理函数,然后把这个函数赋给Application.OnMessage
这两种方法一样吗?如果一样的话,哪种方法比较好?
13 个解决方案
#1
怎么没有人?
#2
还是没人?
#3
Application.OnMessage在WndProc之前,也就是说如果你同时用到了这两种方法,那么OnMessage会先触发,然后到达WndProc;
#4
同意楼上的的说 法
#5
而且OnMessage只会收到进队列的消息
不进队的消息收不到
不进队的消息收不到
#6
什么消息进队,什么消息不进队?
#7
我认为wndProc好用,不过也可以想捕捉哪个消息就写哪个,
procedure ONWMKeyPress(var msg: TMsg);message WM_KeyPress;
procedure ONWMKeyPress(var msg: TMsg);message WM_KeyPress;
#8
Look at Delphi's Source
#9
我看<<windows程序设计>>说的是
与用户输入有关的消息,象WM_KEYDOWN,WM_KEYUP,WM_LBUTTONDOWN,WM_MOUSEMOVE等
还有WM_TIMER,WM_PAINT,WM_QUIT这些
另外的消息就是直接发给窗口过程的,不放入到消息队列中这些消息可以由API函数发出
比如当用CreateWindow时就给窗口过程发一WM_CREATE消息,看VCL源代码可以看到
if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then
begin
Result := True;
if Msg.Message <> WM_QUIT then
begin
Handled := False;
if Assigned(FOnMessage) then FOnMessage(Msg, Handled);
if not IsHintMsg(Msg) and not Handled and not IsMDIMsg(Msg) and
not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end
else
FTerminate := True;
end;
PeekMessage是从消息队列中取消息,取到的话才传到OnMessage
与用户输入有关的消息,象WM_KEYDOWN,WM_KEYUP,WM_LBUTTONDOWN,WM_MOUSEMOVE等
还有WM_TIMER,WM_PAINT,WM_QUIT这些
另外的消息就是直接发给窗口过程的,不放入到消息队列中这些消息可以由API函数发出
比如当用CreateWindow时就给窗口过程发一WM_CREATE消息,看VCL源代码可以看到
if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then
begin
Result := True;
if Msg.Message <> WM_QUIT then
begin
Handled := False;
if Assigned(FOnMessage) then FOnMessage(Msg, Handled);
if not IsHintMsg(Msg) and not Handled and not IsMDIMsg(Msg) and
not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end
else
FTerminate := True;
end;
PeekMessage是从消息队列中取消息,取到的话才传到OnMessage
#10
gzz
#11
OnMessge每秒中会被触发上千次,在这个事件中作条件判断可能会影响整个程序的执行效率,而且OnMessage不能取到不进队消息, 还是重载Wndproc好一些
#12
ggzz
#13
past的话真是令人顿开茅塞
#1
怎么没有人?
#2
还是没人?
#3
Application.OnMessage在WndProc之前,也就是说如果你同时用到了这两种方法,那么OnMessage会先触发,然后到达WndProc;
#4
同意楼上的的说 法
#5
而且OnMessage只会收到进队列的消息
不进队的消息收不到
不进队的消息收不到
#6
什么消息进队,什么消息不进队?
#7
我认为wndProc好用,不过也可以想捕捉哪个消息就写哪个,
procedure ONWMKeyPress(var msg: TMsg);message WM_KeyPress;
procedure ONWMKeyPress(var msg: TMsg);message WM_KeyPress;
#8
Look at Delphi's Source
#9
我看<<windows程序设计>>说的是
与用户输入有关的消息,象WM_KEYDOWN,WM_KEYUP,WM_LBUTTONDOWN,WM_MOUSEMOVE等
还有WM_TIMER,WM_PAINT,WM_QUIT这些
另外的消息就是直接发给窗口过程的,不放入到消息队列中这些消息可以由API函数发出
比如当用CreateWindow时就给窗口过程发一WM_CREATE消息,看VCL源代码可以看到
if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then
begin
Result := True;
if Msg.Message <> WM_QUIT then
begin
Handled := False;
if Assigned(FOnMessage) then FOnMessage(Msg, Handled);
if not IsHintMsg(Msg) and not Handled and not IsMDIMsg(Msg) and
not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end
else
FTerminate := True;
end;
PeekMessage是从消息队列中取消息,取到的话才传到OnMessage
与用户输入有关的消息,象WM_KEYDOWN,WM_KEYUP,WM_LBUTTONDOWN,WM_MOUSEMOVE等
还有WM_TIMER,WM_PAINT,WM_QUIT这些
另外的消息就是直接发给窗口过程的,不放入到消息队列中这些消息可以由API函数发出
比如当用CreateWindow时就给窗口过程发一WM_CREATE消息,看VCL源代码可以看到
if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then
begin
Result := True;
if Msg.Message <> WM_QUIT then
begin
Handled := False;
if Assigned(FOnMessage) then FOnMessage(Msg, Handled);
if not IsHintMsg(Msg) and not Handled and not IsMDIMsg(Msg) and
not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end
else
FTerminate := True;
end;
PeekMessage是从消息队列中取消息,取到的话才传到OnMessage
#10
gzz
#11
OnMessge每秒中会被触发上千次,在这个事件中作条件判断可能会影响整个程序的执行效率,而且OnMessage不能取到不进队消息, 还是重载Wndproc好一些
#12
ggzz
#13
past的话真是令人顿开茅塞