function FindWindowEx2(hParent: HWND; ChildClassName: string; ChildNr: Word): HWND;
var
i: Word;
hChild: HWND;
begin
hChild := 0;
Result := 0;
Dec(ChildNr);
for i := 0 to ChildNr do
begin
hChild := FindWindowEx(hParent, hChild, PChar(ChildClassName), nil);
if hChild = 0 then
Break;
Result := hChild;
end;
end;
procedure TfrmMain.TimerRestarterTimer(Sender: TObject);
var
wndMain, wndChild: HWND;
begin
WriteLog('Periodic Check! Next check in ' + IntToStr((TimerRestarter.Interval div 1000)) + ' Seconds ...' );
wndMain := FindWindow('#32770','Microsoft Windows');
if wndMain <> 0 then
begin
wndChild := FindWindowEx(wndMain, 0, 'DirectUIHWND', nil);
wndChild := FindWindowEx2(wndChild,'CtrlNotifySink', 7);
wndChild := FindWindowEx(wndChild, 0, 'Button', nil);
if wndChild <> 0 then
begin
WriteLog('DEBUG: ' + 'Found Window
Handle: ' + IntToStr(wndChild) + ' Force close Window!');
SendMessage(wndChild, BM_CLICK, 0, 0); //2x sonst gehts nich zu!
SendMessage(wndChild, BM_CLICK, 0, 0);
end;
end;
end;