点击窗口的按钮,在主窗口的WM_COMMAND放断点会中断,但如果用Application.OnMessage去拦截却拦截不了,不知为什么。
解决方案 »
- ADOConnection 数据库是否存在
- 小弟 用IdTcpServer写 多客户端往一个服务器端传文件,但是服务器只相应了一个连接,为什么?麻烦各位大虾看看 .急!!!!
- 如何用Delphi来模拟Flash上传文件的功能?
- 讨论:网络数据库的安全性与客户端程序的角色
- 已经安装使用了的SQL Server如何设置大小写敏感?
- 在delphi7中怎么使窗口最小化后显示到任务栏上?????
- 怎样在D5下使用TXMLDocument
- 怎么在Delphi中操作Exchange Server中的用户,请大家帮忙啊!
- 高分求救!!各位大侠中有谁用过WINSOCK开发过服务器端的程序。
- Delphi RTSP视频传输及播放程序设计
- 用image动态显示图像问题
- 实现点击button1后,每隔10秒钟自动按键H,再点击button1,停止,不知道问题出在哪里
begin case Message.cmdtype of
SC_CLOSE :
begin
self.WindowState := wsMinimized;
hide;
exit;
end else inherited;
end;end;
var
h1,h2: HWND;
begin
if Msg.message = WM_COMMAND then
ShowMessage('ok');
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage('ok');
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := Self.Proc;
end;这样会拦截不到WM_COMMAND的消息,不知为什么
1.非队列消息是直接发到window procedure上的
2.队列消息是发送到线程队列上,而后由线程所实现的消息泵来Getmessage与Dispatch来处理,最终发到相应的window procedure上
刚回到家.这个其实也简单,举个例子吧: SendMessage,PostMessage 同时发送消息到指定窗口,但两个有很大的不同:The PostMessage function places (posts) a message in the message queue associated with the thread that created the specified window and then returns without waiting for the thread to process the message.The SendMessage function sends the specified message to a window or windows. The function calls the window procedure for the specified window and does not return until the window procedure has processed the message.一个进入消息队列,就会在 onMessage中截获到。 一个直接发送到指定窗口,直接进到wndProc.这也是为什么 WM_Syscommand 你截获不到的原因
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
FOldWndProc: TWndMethod; procedure OnMsg(var tMsg: TMsg; var Handled: Boolean);
procedure FormMsg(var tMsg: TMessage); public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage:= Self.OnMsg; FOldWndProc:= Self.WindowProc;
Self.WindowProc:= FormMsg;
end;procedure TForm1.FormMsg(var tMsg: TMessage);
begin
if tMsg.Msg = WM_COMMAND then
begin
ShowMessage('WM_COMMAND');
end
else if tMsg.Msg = WM_SYSCOMMAND then
begin
ShowMessage('WM_SYSCOMMAND');
end; FOldWndProc(tMsg);
end;procedure TForm1.OnMsg(var tMsg: TMsg; var Handled: Boolean);
begin
if tMsg.message = WM_SYSCOMMAND then
ShowMessage('aaaa'); Handled:= false;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage('Button Click!');
end;end.
The WM_COMMAND message is sent when the user selects a command item from a menu, when a control sends a notification message to its parent window, or when an accelerator keystroke is translated. 你忘了一件事 Tapplication 在DELPHI裏面也是一個窗體。 不過 width,height 都為0,如果你能給它裝上個菜單什麼的顯示出來,他也是會響應WM_Command 的
討論問題要看清楚
---------------------------------------------无论什么窗口的消息,只要进入消息列表,都会触发OnMessage的。看代码:function TApplication.ProcessMessage(var Msg: TMsg): Boolean;
var
Handled: Boolean;
begin
Result := False;
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;
end;
lz,答案已經很明了了。而且etomahawk 也給你指出wm_command是如何產生的。
一直以前好像没有人来重载隐藏窗体的window procedure吧!
大家一直以前都是在给LZ做这样的解释:
当发生消息时,有的消息是直接postmessage到消息队列,有的消息是直接发往到窗口过程,而下面代码也是在UI线程中做的消息获取及分发处理,在获取消息后,分发前,可以用一个用户自定义的函数来对消息进行过滤!function TApplication.ProcessMessage(var Msg: TMsg): Boolean;
var
Handled: Boolean;
begin
Result := False;
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;
end;//这个是过滤消息过程!
procedure TForm1.Proc(var Msg: TMsg; var Handled: Boolean);
var
h1,h2: HWND;
begin
if Msg.message = WM_COMMAND then
ShowMessage('ok');
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage('ok');
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := Self.Proc;
end;
http://topic.csdn.net/u/20090109/09/dbbef109-dc17-4d5e-8b0a-6806aa8a5fc5.html这贴就结贴吧。