通过 Application.OnMessage 响应消息

本文介绍了一个使用Delphi实现的消息处理示例,通过自定义过程来响应除WM_MOUSEMOVE外的各种消息,并将消息类型记录到Memo组件中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
    {这个自定义过程要复合 Application.OnMessage 的参数格式}
    procedure MyMessage(var Msg: tagMSG; var Handled: Boolean);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Memo1.Clear;
  Application.OnMessage := MyMessage; {让 Application.OnMessage 执行自定义过程}
end;

{响应 WM_MOUSEMOVE 以外的所有消息}
procedure TForm1.MyMessage(var Msg: tagMSG; var Handled: Boolean);
begin
  if Msg.message <> WM_MOUSEMOVE then
    Memo1.Lines.Add('$' + IntToHex(Msg.message, 4));
end;

end.

转载于:https://www.cnblogs.com/hackpig/archive/2010/02/14/1668220.html

// 存储配置 let config = {}; // 加载配置 async function loadConfig() { const response = await fetch(chrome.runtime.getURL('config.json')); config = await response.json(); console.log('配置加载完成:', config); } // 与Python后端通信 async function sendToBackend(data) { try { const response = await fetch('http://localhost:5000/process', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Encoder': config.encoder || 'UTF8' }, body: JSON.stringify(data) }); if (!response.ok) throw new Error(`后端错误: ${response.status}`); return await response.json(); } catch (error) { console.error('后端通信失败:', error); if (config.WarningWindow) { chrome.notifications.create({ type: 'basic', iconUrl: 'icon.png', title: '请求拦截器警告', message: `后端连接失败: ${error.message}` }); } return data; // 出错时返回原始数据 } } // 初始化 loadConfig(); // 监听内容脚本消息 chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { if (request.type === 'interceptRequest') { (async () => { const modified = await sendToBackend({ type: 'request', data: request.data, url: request.url }); sendResponse(modified); })(); return true; // 异步响应 } if (request.type === 'interceptResponse') { (async () => { const modified = await sendToBackend({ type: 'response', data: request.data, url: request.url }); sendResponse(modified); })(); return true; } }); // 配置更新监听 chrome.storage.onChanged.addListener((changes) => { if (changes.config) { config = changes.config.newValue; console.log('配置已更新:', config); } }); 讲解这一段代码-js
最新发布
06-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值