Drawing on computer screen

xiaoxiao2021-03-06  59

Some software on Window can draw on the computer screen. How did this do it? I checked some relevant information, found that in fact, I can't output it directly to the computer's display screen on the Window system. Painted maps, those practices that are interrupted in the DOS Times in the DOS time is not good !!! So how do those software painting, in fact, there are many software adopted a practice here. If you are interested, you can try it. Yo:)

Using system; using system.collections; using system.componentmodel; using system.windows.form;

Namespace Bitbltscreen {///

/// showScreen's summary description. /// public class showscreen: system.windows.forms.form {private const Int srcopy = 0xcc0020;

[System.Runtime.InteropServices.dllimportattribute ("user32.dll")] private static extern INTPTR getDesktopWindow ();

[System.Runtime.InteropServices.DllImport ( "gdi32.dll")] public static extern long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);

[System.Runtime.InteropServices.dllimportattribute ("User32.dll")] Private static extern INTPTR GETDC (INTPTR HWND);

[System.Runtime.InteropServices.dllimportattribute ("User32.dll")] Private static extern int ReleDc (INTPTR HWND, INTPTR HDC);

Private bitmap m_image; // Temporary bitmap private point m_spoint; // Picture of the starting point private point m_epoint; // The end point of the line PRIVATE graphics m_graphics; // Picture of graphic objects for Picture Private Color M_LineColor; Private System.windows.Forms.ContextMenu ContextMenu1; Private System.Windows.Forms.MenuItem Menuitem1; Private System.Windows.Forms.Menuitem Menuitem2;

///

/// The required designer variable. /// private system.componentmodel.container components = null;

Public showScreen () {// // Windows Form Designer Support for // InitializeComponent (); this.location = new point (0); this.size = new size (Screen.PrimaryScreen.Bounds.Width , Screen.PrimaryScreen.Bounds.Height);

M_LineColor = color.fromargb (255, 0); // Initialized red} #Region Windows Form Designer Generated code ///

/// Clean all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = Null) {components.dispose ();}} Base.Dispose

///

/// Designer supports the required method - do not use the code editor to modify the // / this method. /// private void InitializeComponent () {this.contextMenu1 = new System.Windows.Forms.ContextMenu (); this.menuItem1 = new System.Windows.Forms.MenuItem (); this.menuItem2 = new System. Windows.Forms.MenuItem (); /// contextMenu1 // this.contextMenu1.Menuitems.addrange (new system.windows.forms.Menuitem [] {this.Menuitem1, this.Menuitem2}; // // Menuitem1 / / This.Menuitem1.index = 0; this.Menuitem1.text = "COPYSCREEN (& C)"; this.Menuitem1.click = new system.EventHandler (this.Menuitem1_click); /// Menuitem2 // this.Menuitem2. Index = 1; this.Menuitem2.text = "EXIT (& E)"; this.Menuitem2.click = new system.eventhandler (this.Menuitem2_click); // // showScreen // this.AutoscaleBaseSize = new system.drawing. Size (6, 14); this.clientsize = new system.drawing.size (292, 270); this.contextMenu = this.contextMenu1; this.formolderstyle = system.windows.Forms.FormBorderstyle.none; THIS.NAME = "Showscreen";

} #Endregion

Private void menuitem1_click (Object sender, system.eventargs e) {loadingScreen ();

Private void Menuitem2_Click (Object Sender, System.EventArgs E) {this.close ();

Public void loadscreen () {INTPTR Desk = getDesktopWindow (); // Get the top-level window INTPTR screen of the computer INTPTR ScreenDC = GetDC (Desk); // Get the window's drawing device handle / / Generate a bitmap m_Image = New Bitmap (Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.bounds.Height); Graphics g = graphics.fromimage (m_image); // Create a draw object from this bitmap INTPTR THEDC = g.GETHDC (); // Get the drawing object device handle of this picture // put the copy of the top-level window into the bitmap to prepare long tmp = bitblt (THEDC, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen. Bounds.height, ScreenDC, 0, 0, Srccopy;

g.releaseHDC (THEDC); // Remove Bit Drawing Map Equipment Handle ReleaseDC (this.Handle, ScreenDC); // Delete Top Window Draw Equipment Handle}

Protected Override Void OnPaint (Painteventargs E) {base.onpaint (e) Draw bitmap if (m_image! = null) {E.Graphics.drawImage (m_image, 0, 0);}}

Protected Override Void OnMouseDown (MouseEventArgs E) {base.Onmousedown (e); // Mark down the starting point m_spoint = new point (ex, EY); // Establish the object IF for drawing (m_graphics == NULL) {m_graphics = this.creategraphics ();}} protected override void onmousemove (mouseEventArgs e) {base.onmousemove (e); if (e.button == mousebuttons.left) {// If the left mouse button is pressed Draw, here is a red straight line m_graphics.drawimage (m_image, 0); // This call is to clear the original line, I don't know how to do better, so ... Point Tmpoint = New Point (EX , EY); M_Graphics.drawline (New Pen (M_LineColor), M_Spoint, TMPPoint); // draw a new line.

M_EPoint = Tmpoint; // Remember the new point}} protected override void onmouseup (mouseEventArgs e) {base.onmouseup (e); // Remember to the bit map when the mouse button is lifted into the bit map to graphics TMPGRAPHICS = graphics.FromImage m_image); TMPGRAPHICS.DRAWLINE (new pen (m_linecolor), m_spoint, m_epoint);}}} You can copy the code to copy the code, Ha ~ Ha ~

转载请注明原文地址:https://www.9cbs.com/read-84087.html

New Post(0)