zoukankan      html  css  js  c++  java
  • 暂停和屏蔽右键网页中的Flash

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

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

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

    [delphi] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. unit Unit1;  
    2.   
    3. interface  
    4.   
    5. uses  
    6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  
    7.   Dialogs, OleCtrls, SHDocVw, StdCtrls;  
    8.   
    9. type  
    10.   TForm1 = class(TForm)  
    11.     Button1: TButton;  
    12.     Button2: TButton;  
    13.     WebBrowser1: TWebBrowser;  
    14.     Button3: TButton;  
    15.     procedure FormCreate(Sender: TObject);  
    16.     procedure WebBrowser1DocumentComplete(ASender: TObject;  
    17.       const pDisp: IDispatch; var URL: OleVariant);  
    18.     procedure Button1Click(Sender: TObject);  
    19.     procedure Button2Click(Sender: TObject);  
    20.   private  
    21.     procedure AppMessage(var Msg: TMsg; var Handled: Boolean);  
    22.     function GetFlashHwnd: HWND;  
    23.   public  
    24.   
    25.   end;  
    26.   
    27. var  
    28.   Form1: TForm1;  
    29.   // Flash组件窗口句柄  
    30.   FlashHwnd: HWND = 0;  
    31.   // 控制“暂停”的开关变量  
    32.   FlashPause: Boolean = False;  
    33.   
    34. implementation  
    35.   
    36. {$R *.dfm}  
    37.   
    38. procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);  
    39. begin  
    40.   // 处理Flash窗口消息  
    41.   if (FlashHwnd <> 0) and (Msg.hwnd = FlashHwnd) then  
    42.   begin  
    43.     if FlashPause then  
    44.     begin  
    45.       // 仅仅保留窗口重绘相关消息,其余的消息全部过滤掉  
    46.       if not(Msg.message in [WM_PAINT, WM_WINDOWPOSCHANGED]) then  
    47.       begin  
    48.         Handled := True;  
    49.         Exit;  
    50.       end;  
    51.     end;  
    52.   end;  
    53. end;  
    54.   
    55. procedure TForm1.Button1Click(Sender: TObject);  
    56. begin  
    57.   FlashPause := True;  
    58. end;  
    59.   
    60. procedure TForm1.Button2Click(Sender: TObject);  
    61. begin  
    62.   FlashPause := False;  
    63. end;  
    64.   
    65. procedure TForm1.FormCreate(Sender: TObject);  
    66. begin  
    67.   // 设置进程消息处理过程  
    68.   Application.OnMessage := AppMessage;  
    69.   WebBrowser1.Navigate('http://www.4399.com/flash/90302_3.htm');  
    70. end;  
    71.   
    72. function TForm1.GetFlashHwnd: HWND;  
    73. begin  
    74.   Result := FindWindowEx(WebBrowser1.Handle, 0, 'Shell DocObject View', nil);  
    75.   if Result = then  
    76.     Exit;  
    77.   
    78.   Result := FindWindowEx(Result, 0, 'Internet Explorer_Server', nil);  
    79.   if Result = then  
    80.     Exit;  
    81.   
    82.   Result := FindWindowEx(Result, 0, 'MacromediaFlashPlayerActiveX', nil);  
    83. end;  
    84.   
    85. procedure TForm1.WebBrowser1DocumentComplete(ASender: TObject;  
    86.   const pDisp: IDispatch; var URL: OleVariant);  
    87. begin  
    88.   // 等页面加载完毕再取得其中的Flash窗口句柄  
    89.   if pDisp = WebBrowser1.Application then  
    90.     FlashHwnd := GetFlashHwnd;  
    91. end;  
    92.   
    93. end.  

    http://blog.csdn.net/aqtata/article/details/8788962

  • 相关阅读:
    jquery模拟刮刮乐
    jq默认选中每项第一个
    让一个div水平且垂直居中
    ES6模块的import和export用法总结
    linux 标准目录
    spring 注解配置
    多线程下的两种单例写法
    java版二叉树算法实现
    JAVA版A星算法实现
    对于宫格地图寻最短路径的一个广度搜索算法
  • 原文地址:https://www.cnblogs.com/findumars/p/5277407.html
Copyright © 2011-2022 走看看