图片 1

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

图片 2

演示了PostMessage, SendMessage, WM_CHAR发送汉字。

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

unit Unit1;

源代码:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  p rivate
    { P rivate declarations }
  public
    constructor Create(AOwner: TComponent); override;

    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
{$APPTYPE CONSOLE}
var
  hNotePad:HWND;
  hedit:HWND;

constructor TForm1.Create(AOwner: TComponent);
begin
  inherited;
  Memo1.Text:=’这是猪悟能的postmessage测试’;
end;

procedure TForm1.Button1Click(Sender: TObject);

begin
    hNotePad:=FindWindow(‘Notepad’,’无标题 – 记事本’);
    if hNotePad<>0 then
    begin
      hedit:=FindWindowEx(hNotePad,0,’edit’,nil);
      PostMessage(hedit,WM_CHAR,Wparam(‘B’),0);
      Writeln(‘send’);
    end;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
{ TODO -o猪悟能 : 发送串必须用sendMessage }
   hNotePad:=FindWindow(nil,’无标题 – 记事本’);
   if hNotePad<>0 then
   begin
    hedit:=FindWindowEx(hNotePad,0,’edit’,nil);
    SendMessage(hedit,WM_SETTEXT,Length(Memo1.Text),
      Integer(PChar(Memo1.Text)));
    Writeln(‘send’);
   end;

end;

procedure TForm1.Button3Click(Sender: TObject);
begin
 hNotePad:=FindWindow(‘Notepad’,’无标题 – 记事本’);
  if hNotePad<>0 then
  begin
    hedit:=FindWindowEx(hNotePad,0,’edit’,nil);
    PostMessage(hedit,WM_CHAR,Wparam($bd),0);
    PostMessage(hedit,WM_CHAR,Wparam($f1),0);
    Writeln(‘send’);
  end;
end;

end.

 

interface

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

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
  Dialogs, StdCtrls, ComCtrls, IdBaseComponent, IdComponent,
IdTCPConnection,
  IdTCPClient, IdHTTP,PerlRegEx,StrUtils;

[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. 

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    ProgressBar1: TProgressBar;
    Button1: TButton;
    IdHTTP1: TIdHTTP;
    Button2: TButton;
    OpenDialog1: TOpenDialog;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  *******
    { Private declarations }
  public
    { Public declarations }
  end;

unit Unit1;

var
  Form1: TForm1;
  hHand1:THandle;
  threadID1:DWORD;
  strList1:TStringList;
  function downpic(p:Pointer):integer;stdcall;

interface

implementation

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

{$R *.dfm}
//{$APPTYPE  CONSOLE}

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

function downpic(p:Pointer):integer;stdcall;
var
myStream1:TMemoryStream;
I: Integer;
picname:string;
filepath:string;
pi1:Integer;
begin
  //down image
  filepath:=ExtractFilePath(Application.ExeName);

  end;

  //初始化idhttp
  form1.IdHTTP1:=TIdHTTP.Create(nil);
  form1.IdHTTP1.ReadTimeout:=24000;
  form1.IdHTTP1.ConnectTimeout:=24000;
  form1.IdHTTP1.Request.UserAgent:=’Mozilla/4.0 ‘+
  ‘(compatible;MSIE 6.0; Windows NT 5.0; ‘+
  ‘.NET CLR 1.1.4322)’;
  //初始化进度条
  Form1.ProgressBar1.Max:=strList1.Count;

Author

发表评论

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