unit HookMain;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls; type
THookForm = class(TForm)
SendBtn: TButton;
GroupBox1: TGroupBox;
LogList: TListBox;
DoLog: TCheckBox;
ExitBtn: TButton;
Button1: TButton;
procedure SendBtnClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ExitBtnClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
function AppWindowHook(var Message: TMessage): Boolean;
end; var
HookForm: THookForm; implementation {$R *.DFM} procedure THookForm.FormCreate(Sender: TObject);
begin
Application.HookMainWindow(AppWindowHook);
end; procedure THookForm.FormDestroy(Sender: TObject);
begin
Application.UnhookMainWindow(AppWindowHook);
end; function THookForm.AppWindowHook(var Message: TMessage): Boolean;
const
LogStr = 'Message ID: $%x, WParam: $%x, LParam: $%x';
begin
Result := True;
if DoLog.Checked then
with Message do
LogList.Items.Add(Format(LogStr, [Msg, WParam, LParam]));
end; procedure THookForm.SendBtnClick(Sender: TObject);
begin
SendMessage(Application.Handle, WM_NULL, , );
end; procedure THookForm.ExitBtnClick(Sender: TObject);
begin
Close;
end; procedure THookForm.Button1Click(Sender: TObject);
begin
ShowMessage('ddd');
end; end.

理论解释:

Enables a native Windows dialog box to receive messages sent to the application's main window.

Use HookMainWindow to ensure that a native Windows dialog box behaves correctly as a child of the application, not as a stand-alone window. For example, switching among applications with Alt+Tab treats the application as a single task after calling HookMainWindow, rather than treating the native Windows dialog box as a separate task.

When the window identified by the Handle property receives relevant dialog messages, it passes them to the dialog procedure passed as the Hook parameter.

There is no problem with leaving a dialog box hooked into the main window, even for extended periods. However, should the dialog box close, call the UnhookMainWindow method to release the hook.

Application.HookMainWindow完全替代了原来的窗口过程(但是好像也会继续传递)的更多相关文章

  1. Delphi自定义窗口过程WinProc

    unit ScWndProc; interface uses Forms, Messages; const DDGM_FOOMSG = WM_USER; //自定义消息 implementation ...

  2. 窗口过程 Wndproc

    操作系统向应用程序发送一系列消息,如左键按下和左键抬起,应用程序将通过GetMessage等方法 Wndproc应用例子最终将消息提交到窗口过程(WndProc)指向一个应用程序定义的窗口过程的指针. ...

  3. win32程序通过LPCREATESTRUCT中的lpCreateParams传递参数给窗口过程函数

    win32窗口程序中如果需要给窗口过程函数传递自定义参数,可以通过LPCREATESTRUCT结构体中的lpCreateParams进行传递. 创建窗口实例函数: m_hWnd = CreateWin ...

  4. ATL中窗口句柄与窗口过程的关联方法

    ATL中采用了一种动态生成机器指令的方式进行窗口句柄与窗口对象进行关联,以是详细分析: CWindowImpl会在第一次调用Create时注册窗口类,该窗口类是的信息是在CWindowImpl的子类中 ...

  5. C#调用WinAPI及窗口过程

    C#调用WINAPI及Windows窗口消息的发与送 最近在做一个餐饮项目(C#Winform),其中有一块是做点菜宝接口的对接,点菜宝的厂商提供了一个WX.exe的驱动程序,这个驱动程序无直接打开, ...

  6. 窗口过程 - Windows程序设计(SDK)006

    窗口过程 让编程改变世界 Change the world by program 内容节选: Windows 把这样一个窗口分为了客户区和非客户区,这里边白色的这一大片就是客户区,而这些标题栏.菜单栏 ...

  7. win32编程中消息循环和WndProc()窗口过程函数

    原文地址:https://blog.csdn.net/zxxSsdsd/article/details/45504383 在win32程序的消息循环函数中  while (GetMessage (&a ...

  8. MSG结构体和WndProc窗口过程详解

    MSG结构体和WndProc窗口过程对于Windows编程非常重要,如果不了解它们,可以说就没有学会Windows编程. MSG结构体 MSG 结构体用来表示一条消息,各个字段的含义如下: typed ...

  9. 从普通函数到对象方法 ------Windows窗口过程的面向对象封装

    原文地址:http://blog.csdn.net/linzhengqun/article/details/1451088 从普通函数到对象方法 ------Windows窗口过程的面向对象封装 开始 ...

随机推荐

  1. LeetCode_Reverse Integer

    Reverse digits of an integer. Example1: x = , Example2: x = -, class Solution { public: int reverse( ...

  2. ubuntu12中设置PATH环境变量的几种方法(三种办法)

    如果在Ubuntu12系统中自行安装了一些软件,特别是使用tar.gz文件包安装的软件,通常会放在/usr/local或者/opt,甚至放在/home下,但是如果要调用或执行时,必须加上完整的路径才可 ...

  3. Silverlight信息加密 - 通过Rfc2898DeriveBytes类使用基于HMACSHA1的伪随机数生成器实现PBKDF2

    原文: http://blog.csdn.net/xuyue1987/article/details/6706600 在上一篇文章当中,介绍到了通过Silverlight获取web.config中的值 ...

  4. 05_Elasticsearch 单模式下API的增删改查操作

    05_Elasticsearch 单模式下API的增删改查操作 安装marvel 插件: zjtest7-redis:/usr/local/elasticsearch-2.3.4# bin/plugi ...

  5. SQL 如何表示引号

    SELECT ename || '''' || ' 的工作是 ' || ' ' || job || '''' AS msg FROM emp WHERE deptno = 10; ' '' ' 第一个 ...

  6. 【转】vsftp 遇到错误 500 OOPS: vsftpd: refusing to run with writable root inside chroot()--不错

    原文网址:http://linux.it.net.cn/e/server/ftp/2015/0227/13554.html 当我们限定了用户不能跳出其主目录之后,使用该用户登录FTP时往往会遇到这个错 ...

  7. jQuery autocomplete 使用

    推荐 :http://www.cnblogs.com/Peter-Zhang/archive/2011/10/22/2221147.html eg: $("#txtGrand"). ...

  8. struts2——简单登陆实例

    从今天开始,一起跟 各位聊聊java的三大框架——SSH.先从Struts开始说起,Struts对MVC进行了很好的封装,使用Struts的目的是为了帮助我们减少在 运用MVC设计模型来开发Web应用 ...

  9. List数据集动态排序

    List<Type> datas = new List<Type>; datas = datas.OrderBy(c => c.GetType().GetProperty ...

  10. javascript无缝流畅动画轮播,终于让我给搞出来了。

    自己一直想写一个真正能用的轮播图,以前是写过一个,但是不是无缝的轮播,感觉体验很差,这个轮播之前也搞了很多实例,看了很多代码,但是脑子总转不过弯,为什么在运动到一定距离后可以突然转回到原始位置,而没有 ...