[2025-04-05 04:44:07 最后更新]
[win10api]delphi 版 ChangeWindowMessageFilter
动态装载版本,函数不存在的 xp 系统下也不会出错,来自网友,修改了些参数同支持 32位(delphi7)/64位(开源la...)
unit send_message_win10;
////来自 la 64 位代码//{$mode objfpc}{$H+}
interface
uses
windows,
Classes, SysUtils;
function AllowMeesageForVistaAbove(uMessageID: THandle; bAllow: Boolean): Boolean;
implementation
type
TChangeWindowMessageFilter = function(msg: UINT; dwFlag: DWORD): BOOL; stdcall;
var
//ChangeWindowMessageFilter:function(msg: UINT; dwFlag: DWORD): BOOL; stdcall;
ChangeWindowMessageFilter:TChangeWindowMessageFilter;
//高权限用户要接收低权限用户的消息,在 vista 后必须加上 ChangeWindowMessageFilter 调用
//register global messages for vista win7.
function AllowMeesageForVistaAbove(uMessageID: THandle; bAllow: Boolean): Boolean;
const
NULL = 0;
var
bResult:Boolean;
hUserMod:HMODULE;
begin
bResult:=False;
hUserMod:=Null;
//vista and later
hUserMod := LoadLibrary(PChar('user32.dll'));
if( NULL=hUserMod ) then
begin
Result:=FALSE;
Exit;
end;
ChangeWindowMessageFilter := TChangeWindowMessageFilter(GetProcAddress(hUserMod,'ChangeWindowMessageFilter'));
if not Assigned(ChangeWindowMessageFilter) then
begin
Result:= FALSE;
Exit;
end;
if bAllow then
bResult:= ChangeWindowMessageFilter(uMessageID, 1 )
else
bResult:=ChangeWindowMessageFilter(uMessageID, 2);//MSGFLT_ADD: 1, MSGFLT_REMOVE: 2
if( NULL <> hUserMod ) then
begin
FreeLibrary( hUserMod );
end;
result:= bResult;
end;
end.