请教:在ActiveForm和IE ToolBand中把窗体ShowModal后,还能点IE的缺陷
这个问题我在网上搜索了一下,发现有一段delphi代码:
type PWindowList = ^TWindowList; TWindowList = record Next: PWindowList; Window: HWnd; end; PDisableProcessWindows = ^TDisableProcessWindows; TDisableProcessWindows = record ActiveWindow : hWnd; ProcessId : DWORD; WindowList: pWindowList; end;function DoDisableWindow(Window: HWnd; Data: Longint): Bool; stdcall;var P: PWindowList; WinProcessId : DWORD;begin with pDisableProcessWindows(Data)^ do begin GetWindowThreadProcessId(Window,@WinProcessId); if (ProcessId=WinProcessId) and (Window <> ActiveWindow) and IsWindowVisible(Window) and IsWindowEnabled(Window) then begin New(P); P^.Next := WindowList; P^.Window := Window; WindowList := P; EnableWindow(Window, False); end; end; Result := True;end;function DisableProcessWindows(ActiveWindow: HWnd): Pointer;var Rec: TDisableProcessWindows;begin Rec.ActiveWindow := ActiveWindow; Rec.WindowList := nil; Rec.ProcessId := GetCurrentProcessId; try try EnumWindows(@DoDisableWindow, integer(@Rec)); Result := Rec.WindowList; except EnableTaskWindows(Rec.WindowList); Result := nil; raise; end; finally end;end;//写上面的函数,然后把自己需要模态显示的窗口新写一个ShowModalfunction TMyForm.ShowModal: Integer;var WindowList: Pointer;begin // 修正IE7下把窗体ShowModal后,还能点IE的缺陷 WindowList := nil; try WindowList := DisableProcessWindows(0); Result := inherited ShowModal; finally EnableTaskWindows(WindowList); end;end;
BOOL __stdcall DoDisableWindow(HWND Window, int Data){ PWindowList P; DWORD WinProcessId; GetWindowThreadProcessId(Window,&WinProcessId); if ( ((TDisableProcessWindows *)Data)->ProcessId == WinProcessId && Window != ((TDisableProcessWindows *)Data)->ActiveWindow && IsWindowVisible(Window) && IsWindowEnabled(Window) ) { P = new TWindowList; P->Next = ((TDisableProcessWindows *)Data)->WindowList; P->Window = Window; ((TDisableProcessWindows *)Data)->WindowList = P; EnableWindow(Window, false); } return true;}void * __fastcall DisableProcessWindows(HWND ActiveWindow){ TDisableProcessWindows Rec; Rec.ActiveWindow = ActiveWindow; Rec.WindowList = NULL; //Rec.ProcessId = GetCurrentProcessId(); GetWindowThreadProcessId(GetForegroundWindow(), (unsigned long *)&Rec.ProcessId); void *Result; try { try { EnumWindows( (FARPROC)DoDisableWindow, (long)&Rec ); Result = Rec.WindowList; } catch (...) { EnableTaskWindows(Rec.WindowList); Result = NULL; } } __finally { } return Result;}int __fastcall TMyForm::ShowModal(){ void *WindowList; int Result; // 修正IE7下把窗体ShowModal后,还能点IE的缺陷 WindowList = NULL; try { WindowList = DisableProcessWindows(0); Result = ShowModal(); } __finally { EnableTaskWindows(WindowList); } return Result;}