- C# code
-
using System; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Drawing; class SourceForm:Form { RichTextBox txtBox; public Control SourceControl{ get{return txtBox;} } public DestForm DestForm{ get; set; } public SourceForm() { txtBox =new RichTextBox(); txtBox.Dock = DockStyle.Fill; this.FullScreen(); Left =0; FormBorderStyle = FormBorderStyle.None; txtBox.KeyUp += (s,e)=>{ switch (e.KeyCode) { case Keys.Escape: DestForm.Close(); break; case Keys.F4: DestForm.MirrorState =!DestForm.MirrorState ; Left = DestForm.MirrorState?4000:0; break; } }; Text ="Source"; Controls.Add (txtBox); } } class DestForm:Form { [DllImport("user32.dll")] staticextern IntPtr GetDC(IntPtr wnd); [DllImport("user32.dll")] staticexternbool ReleaseDC(IntPtr wnd,IntPtr hdc); [DllImport("gdi32.dll")] staticexternbool StretchBlt(IntPtr hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest, IntPtr hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, uint dwRop); constuint SRCCOPY =0x00CC0020; Timer timer; void SetDock (Control ctrl){ ctrl.Height = Height -60; ctrl.Width = Width; ctrl.Anchor = AnchorStyles.Top|AnchorStyles.Bottom|AnchorStyles.Left|AnchorStyles.Right; } SourceForm srcForm; public DestForm(SourceForm srcForm) { this.srcForm = srcForm; srcForm.DestForm =this; srcForm.Show (); this.FullScreen(); TopMost =false; timer =new Timer(); Text ="Mirror"; GotFocus += (s,e)=> srcForm.SourceControl.Focus(); timer.Interval =1; timer.Enabled =true; timer.Tick += (s, e) =>CapSrcFormAndMirror(); } publicbool MirrorState { get; set; } void CapSrcFormAndMirror() { var width = srcForm.SourceControl.Width; var height = srcForm.SourceControl.Height; srcForm.SourceControl.Invalidate (); using (var g = CreateGraphics()) { var srcDc = GetDC(srcForm.SourceControl.Handle); var dstDc = g.GetHdc(); if (MirrorState) StretchBlt(dstDc, 0, 0, width , height, srcDc, width -1, 0, -width , height, SRCCOPY); else StretchBlt(dstDc, 0, 0, width, height, srcDc, 0, 0, width , height, SRCCOPY); g.ReleaseHdc(); ReleaseDC(srcForm.SourceControl.Handle, srcDc); } } } staticclass program { publicstaticvoid FullScreen (this Form frm){ frm.StartPosition = FormStartPosition.Manual; frm.FormBorderStyle = FormBorderStyle.None; frm.Size = Screen.PrimaryScreen.Bounds .Size; frm.Location =new Point (0,0); } staticvoid Main() { Application.Run(new DestForm(new SourceForm())); } }
仍然是截图;运行初始无镜像全屏,F4切换镜像,可以输
|