最好是关闭它,而不是让他不可见。阻止弹出是不行的,最好的办法是写个线程,检测到就关闭它。我写过类似的代码,给你参考一下。
type
TAutoCloseInfoWindow = class(TThread)
procedure Execute(); override;
end;
var
l_hWnd:THandle;//要关闭的那个窗口的父窗口
//--------------------实现部分-----------------
function EnumChildWindowsProc(hwnd: THandle; lParam:LPARAM): Boolean;stdcall;
var
Buff: array[0..255] of Char;
nID:Integer;
begin
GetWindowText(hwnd,buff,255);
nID := GetDlgCtrlID(hwnd);
if Pos('否',buff) > 0 then//系统设置改变,问你是否重启,要枚举到“否”按钮,点下它
begin
SendMessage(l_hWnd,WM_COMMAND,MAKEWPARAM(nID,BN_CLICKED),hwnd);
Result := FALSE;
Exit;
end;
Result := TRUE;
end;
function EnumWindowProc(hWnd :THandle;value
WORD):BOOL;stdcall;
var
szClassName:array[0..99] of char;
szWinTitleName:array[0..256]of char;
begin
GetClassName(hWnd,szClassName,100);
GetWindowText(hWnd,szWinTitleName,256);
if (Pos('#32770',szClassName) > 0) and (
(Pos('不安全的移除裝置',szWinTitleName) > 0) or
(Pos('不安全的设备删除',szWinTitleName) > 0) or
(Pos('Unsafe Removal of Device',szWinTitleName) > 0)) then
begin
SendMessage(hWnd,WM_CLOSE,0,0);
Result := False;
Exit;
end;
if Pos('系统设置改变',szWinTitleName) > 0 then
begin
l_hWnd := hwnd;
EnumChildWindows(hwnd,@EnumChildWindowsProc,0);//这个窗口很特殊,发送关闭消息没用的,要找到窗口里面的按钮,模拟按下它
Result := FALSE;
Exit;
end;
Result := True;
end;
procedure TAutoCloseInfoWindow.Execute();
begin
while True do
begin
Sleep(20);
EnumWindows(@EnumWindowProc,0);
end;
end;