unit Unit1;

如何暂停网页中的Flash?原理很简单,就是屏蔽Flash的消息即可。屏蔽右键也可以通过此方法

unit Main;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, ExtCtrls, StdCtrls,Comobj;type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Label1: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Panel1Resize(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
FComApp:OleVariant;
gWaveHwnd:Hwnd;
public
{ Public declarations }
procedure SetParentWindow(pParent: TWinControl);
end;var
Form1: TForm1;implementation{$R *.dfm}{ TForm1 }procedure
TForm1.Button1Click(Sender: TObject);
var
Word : Variant;
begin
FComApp := CreateOLEObject(‘Word.Application’);
FComApp.Documents.Open(extractfilepath(Application.ExeName)+’\test.doc’,false);
FComApp.Visible := True;
Label1.Caption := FComApp.ActiveWindow.Caption;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
SetParentWindow(Panel1);
end;procedure TForm1.Panel1Resize(Sender: TObject);
begin
if gWaveHwnd<>0 then
begin
FComApp.ActiveWindow.Height := Panel1.Height;
FComApp.ActiveWindow.Width := Panel1.Width;
Windows.MoveWindow(gWaveHwnd,0,0,Panel1.Width,Panel1.Height,false);
end;
end;procedure TForm1.SetParentWindow(pParent: TWinControl);
var
lWaveHwnd : Hwnd;
lWidth, lHeight: Integer;
lWindowCaption: String;
begin
//lwaveHwnd := FindWindow(nil,’Microsoft Word’);//窗口标题
lWindowCaption := FComApp.ActiveWindow.Caption;
lwaveHwnd := FindWindow(nil,pAnsiChar(lWindowCaption+’ – Microsoft
Word’));//窗口标题
//lwaveHwnd :=
FindWindowW(nil,pWideChar(String(FComApp.ActiveWindow.Caption)));//窗口标题
Windows.SetWindowLong(lWaveHwnd,GWL_STYLE,GetWindowLong(lWaveHwnd,
GWL_STYLE)
and not (WS_CAPTION or WS_SYSMENU));
Windows.SetParent(lWaveHwnd,pParent.Handle);
gWaveHwnd:=lWaveHwnd;
lWidth := pParent.Width;
lHeight := pParent.Height;
Windows.MoveWindow(lWaveHwnd,0,0,lWidth,lHeight,false);
//mParent := pParent;
end;end.

interface

直接贴代码吧,加了注释,很容易就能懂了

出处

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

 

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

新建工程,加一个WebBrowser,再加两个按钮。Flash 11.7.700.169 测试通过

var
Form1: TForm1;
implementation

[delphi]
unit Unit1; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms, 
  Dialogs, OleCtrls, SHDocVw, StdCtrls; 
 
type 
  TForm1 = class(TForm) 
    Button1: TButton; 
    Button2: TButton; 
    WebBrowser1: TWebBrowser; 
    Button3: TButton; 
    procedure FormCreate(Sender: TObject); 
    procedure WebBrowser1DocumentComplete(ASender: TObject; 
      const pDisp: IDispatch; var URL: OleVariant); 
    procedure Button1Click(Sender: TObject); 
    procedure Button2Click(Sender: TObject); 
  private 
    procedure AppMessage(var Msg: TMsg; var Handled: Boolean); 
    function GetFlashHwnd: HWND; 
  public 
 
  end; 
 
var 
  Form1: TForm1; 
  // Flash组件窗口句柄  
  FlashHwnd: HWND = 0; 
  // 控制“暂停”的开关变量  
  FlashPause: Boolean = False; 
 
implementation 
 
{$R *.dfm} 
 
procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean); 
begin 
  // 处理Flash窗口消息  
  if (FlashHwnd <> 0) and (Msg.hwnd = FlashHwnd) then 
  begin 
    if FlashPause then 
    begin 
      // 仅仅保留窗口重绘相关消息,其余的消息全部过滤掉  
      if not(Msg.message in [WM_PAINT, WM_WINDOWPOSCHANGED]) then 
      begin 
        Handled := True; 
        Exit; 
      end; 
    end; 
  end; 
end; 
 
procedure TForm1.Button1Click(Sender: TObject); 
begin 
  FlashPause := True; 
end; 
 
procedure TForm1.Button2Click(Sender: TObject); 
begin 
  FlashPause := False; 
end; 
 
procedure TForm1.FormCreate(Sender: TObject); 
begin 
  // 设置进程消息处理过程  
  Application.OnMessage := AppMessage; 
  WebBrowser1.Navigate(”); 
end; 
 
function TForm1.GetFlashHwnd: HWND; 
begin 
  Result := FindWindowEx(WebBrowser1.Handle, 0, ‘Shell DocObject View’,
nil); 
  if Result = 0 then 
    Exit; 
 
  Result := FindWindowEx(Result, 0, ‘Internet Explorer_Server’,
nil); 
  if Result = 0 then 
    Exit; 
 
  Result := FindWindowEx(Result, 0, ‘MacromediaFlashPlayerActiveX’,
nil); 
end; 
 
procedure TForm1.WebBrowser1DocumentComplete(ASender: TObject; 
  const pDisp: IDispatch; var URL: OleVariant); 
begin 
  // 等页面加载完毕再取得其中的Flash窗口句柄  
  if pDisp = WebBrowser1.Application then 
    FlashHwnd := GetFlashHwnd; 
end; 
 
end. 

{$R *.dfm}
//方法一 可调整窗口 uses里加入comobj
procedure TForm1.Button1Click(Sender: TObject);
procedure OpenInIe(URL:string);
var
Ie:Variant;
begin
Ie:=CreateOleObject(‘InternetExplorer.Application’);
Ie.visible:=True;
Ie.left:=300; //与左边相隔距离
Ie.top:=200; //与顶部相隔距离
Ie.height:=400; //高度
Ie.width:=600; //宽度
Ie.menubar:=0; //隐藏菜单栏
Ie.toolbar:=0; //隐藏工具栏
Ie.addressbar:=0; //隐藏地址栏
//Ie.statubar:=0; //不可调整大小
Ie.resizable:=0;
Ie.navigate(URL);
end;
begin
OpenInIe(‘www.hi.baidu.com/yncg2046’);
end;

unit Unit1;

//方法二 正常窗口打开 uses里加入shellapi
procedure TForm1.Button2Click(Sender: TObject);
begin
ShellExecute(Handle,’open’,’www.hi.baidu.com/yncg2046′,nil,nil,SW_SHOWNORMAL)
end;

interface

end.

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

Author

发表评论

电子邮件地址不会被公开。 必填项已用*标注