第二个窗口代码 using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Drawing.Imaging; using System.Runtime.InteropServices; using System.Data; using System.IO;
namespace QQ_Magic { /// <summary> /// Form2 的摘要说明。 /// </summary> public class Form2 : System.Windows.Forms.Form {
private System.ComponentModel.IContainer components; private AxSHDocVw.AxWebBrowser webbrw; private System.Windows.Forms.TextBox textBox2; private string flashpath;
public Form2(string path) { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); flashpath=path;
// // TOD 在 InitializeComponent 调用后添加任何构造函数代码 // }
/// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); }
#region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form2)); this.webbrw = new AxSHDocVw.AxWebBrowser(); this.textBox2 = new System.Windows.Forms.TextBox(); ((System.ComponentModel.ISupportInitialize)(this.webbrw)).BeginInit(); this.SuspendLayout(); // // webbrw // this.webbrw.Enabled = true; this.webbrw.Location = new System.Drawing.Point(12, 14); this.webbrw.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("webbrw.OcxState"))); this.webbrw.Size = new System.Drawing.Size(256, 196); this.webbrw.TabIndex = 0; // // textBox2 // this.textBox2.Location = new System.Drawing.Point(278, 198); this.textBox2.Multiline = true; this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(178, 136); this.textBox2.TabIndex = 4; this.textBox2.Text = ""; this.textBox2.Visible = false; // // Form2 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(476, 386); this.Controls.Add(this.textBox2); this.Controls.Add(this.webbrw); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Name = "Form2"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Form2"; this.Load += new System.EventHandler(this.Form2_Load); ((System.ComponentModel.ISupportInitialize)(this.webbrw)).EndInit(); this.ResumeLayout(false);
} #endregion // //以下是调用API函数;在调用API函数时,在引明System.Runtime.InteropServices这个名字空间, //程序开头处已经引用了。 // [DllImport("gdi32.dll", EntryPoint="BitBlt")] //这句是必要的 public static extern int BitBlt ( IntPtr hDestDC,//IntPtr我查过MSDN中说是转换句柄的。在BitBlt这个API函数中这个成员是一个int类,如果用int类型好像出错。 int x, int y, int nWidth, int nHeight, IntPtr hSrcDC, int xSrc, int ySrc, int dwRop );
private void Form2_Load(object sender, System.EventArgs e) {
//获得当前屏幕的大小 Rectangle rect = new Rectangle() ; rect = Screen.GetWorkingArea (this) ; //创建一个以当前屏幕为模板的图象 Graphics g1 = this.CreateGraphics() ; //创建以屏幕大小为标准的位图 Image MyImage = new Bitmap (this.Width,this.Height , g1 ) ; Graphics g2 = Graphics.FromImage ( MyImage ) ; //得到屏幕的DC IntPtr dc1 = g1.GetHdc() ; //得到Bitmap的DC IntPtr dc2 = g2.GetHdc() ; //调用此API函数,实现屏幕捕获 BitBlt ( dc2 , 0 , 0 ,this.Width,this.Height, dc1 ,0 ,0 , 13369376 ) ; //释放掉屏幕的DC g1.ReleaseHdc ( dc1 ) ; //释放掉Bitmap的DC g2.ReleaseHdc ( dc2 ) ; //以JPG文件格式来保存 MyImage.Save ( @Application.StartupPath+"\\bg.jpg" , ImageFormat.Jpeg ); //MessageBox.Show ( "当前屏幕已经保存为C盘的capture.jpg文件!" ) ; this.show_flash();//调用show_flash方法
//以下是设置webbr(WEBBorwer)控件 webbrw.Top=-2; webbrw.Left=-2; webbrw.Width=this.Width+20; webbrw.Height=this.Height+20 ; System.Object obj=null; webbrw.Navigate(@Application.StartupPath+"\\temp.html",ref obj,ref obj,ref obj,ref obj);
}
public void show_flash() { //读取Hhml文件 // try { //FileStream fs1=new FileStream(@Application.StartupPath+"\\temp.html",FileMode.Open,FileAccess.Read); //StreamReader fsreader=new StreamReader(fs1); StreamReader fsreader=new StreamReader(@Application.StartupPath+"\\temp.html"); textBox2.Text=fsreader.ReadToEnd(); fsreader.Close(); StreamWriter fswrite=new StreamWriter(@Application.StartupPath+"\\temp.html"); int i; //MessageBox.Show("lines:"+textBox2.Lines.Length); for(i=0;i<textBox2.Lines.Length;i++) { if(textBox2.Lines[i].IndexOf("swf")>0) { //MessageBox.Show(swfname); string temp="<param name=\"movie\" value=\"" +flashpath+ "\"/>"; fswrite.WriteLine(temp); continue; } fswrite.WriteLine(textBox2.Lines[i]); } fswrite.Close(); } catch(Exception ex) { MessageBox.Show("操作Temp.html文件出错!"+ex.Message); } }
} }