Application.HookMainWindow完全替代了原来的窗口过程(但是好像也会继续传递)
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完全替代了原来的窗口过程(但是好像也会继续传递)的更多相关文章
- Delphi自定义窗口过程WinProc
unit ScWndProc; interface uses Forms, Messages; const DDGM_FOOMSG = WM_USER; //自定义消息 implementation ...
- 窗口过程 Wndproc
操作系统向应用程序发送一系列消息,如左键按下和左键抬起,应用程序将通过GetMessage等方法 Wndproc应用例子最终将消息提交到窗口过程(WndProc)指向一个应用程序定义的窗口过程的指针. ...
- win32程序通过LPCREATESTRUCT中的lpCreateParams传递参数给窗口过程函数
win32窗口程序中如果需要给窗口过程函数传递自定义参数,可以通过LPCREATESTRUCT结构体中的lpCreateParams进行传递. 创建窗口实例函数: m_hWnd = CreateWin ...
- ATL中窗口句柄与窗口过程的关联方法
ATL中采用了一种动态生成机器指令的方式进行窗口句柄与窗口对象进行关联,以是详细分析: CWindowImpl会在第一次调用Create时注册窗口类,该窗口类是的信息是在CWindowImpl的子类中 ...
- C#调用WinAPI及窗口过程
C#调用WINAPI及Windows窗口消息的发与送 最近在做一个餐饮项目(C#Winform),其中有一块是做点菜宝接口的对接,点菜宝的厂商提供了一个WX.exe的驱动程序,这个驱动程序无直接打开, ...
- 窗口过程 - Windows程序设计(SDK)006
窗口过程 让编程改变世界 Change the world by program 内容节选: Windows 把这样一个窗口分为了客户区和非客户区,这里边白色的这一大片就是客户区,而这些标题栏.菜单栏 ...
- win32编程中消息循环和WndProc()窗口过程函数
原文地址:https://blog.csdn.net/zxxSsdsd/article/details/45504383 在win32程序的消息循环函数中 while (GetMessage (&a ...
- MSG结构体和WndProc窗口过程详解
MSG结构体和WndProc窗口过程对于Windows编程非常重要,如果不了解它们,可以说就没有学会Windows编程. MSG结构体 MSG 结构体用来表示一条消息,各个字段的含义如下: typed ...
- 从普通函数到对象方法 ------Windows窗口过程的面向对象封装
原文地址:http://blog.csdn.net/linzhengqun/article/details/1451088 从普通函数到对象方法 ------Windows窗口过程的面向对象封装 开始 ...
随机推荐
- poj2505-A multplication game
题意:两个人轮流用2~9来乘n,使n不断扩大,n开始为1.当给一个固定值k,谁先使n超过k谁赢. 分析:能到达必败态的状态为必胜态,只能到达必胜态的状态为必败态.对于给定的k,n>=k时为必败态 ...
- grep详解
一.简介 Global Regular Expression Print,是一种强大的文本搜索工具,能使用正则表达式. 二.语法 grep [OPTIONS] PATTERN [FILE...]gre ...
- oracle client server那点事
oracle网络配置三个配置文件 listener.ora.sqlnet.ora.tnsnames.ora ,都是放在$ORACLE_HOME\network\admin目录下. 1. sqlnet ...
- 初识lucene
lucene的介绍网上有好多,再写一遍可能有点多余了. 使用lucene之前,有一系列的疑问 为什么lucene就比数据库快? 倒排索引是什么,他是怎么做到的 lucene的数据结构是什么样的,cpu ...
- Remove Invalid Parentheses 解答
Question Remove the minimum number of invalid parentheses in order to make the input string valid. R ...
- Hdu3498-whosyourdaddy(精确覆盖模板题)
Problem Description sevenzero liked Warcraft very much, but he haven't practiced it for several year ...
- Linux SD/MMC/SDIO驱动分析
一.SD/MMC/SDIO概念区分 SD(SecureDigital)与 MMC(MultimediaCard) SD 是一种 flash memory card 的标准,也就是一般常见的 SD 记忆 ...
- python高级编程之(类级):子类内建类型
# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' #类级 #在2.2中,提出了类型(type0与类(class)统一( ...
- springMVC+mybatis用户登录实例
1.整体结构 2.准备工作 数据库: --Mysql 5.6 创建数据库 wolf 1 CREATE DATABASE wolf; 创建用户表 user 1 2 3 4 5 6 create tabl ...
- swift中的传值
光阴似箭,日月如梭,转眼间学习的旅途已经过了一大半了,忘着自己所敲过的成批的代码,看着自己付出和努力,默默地为自己这几个月的奋斗感到欣慰,不论学习的路途再怎么的艰辛,但是自己还是坚持过来了,回想着以往 ...