API for calling WIN32 in C #

Source: Internet
Author: User

Recently in the GDI part of C #, I tried to write a subtitle control (in fact, it is more appropriate to use a label), but found that the control with GDI to paint the entire control seems not good (should be my level), so I went to the next WIN32 DLL, Discovering the API is really a happy thing (said on the WIN32 platform only). Back in C #, in C # to be in a form (the control is also a form), just use the
Graphics g= control name. CreateGraphics ();//So you can use G to draw something on this control.
But if I want to open the range, draw on the whole screen, then. NET is powerless. Fortunately, we have WIN32, we can use GETDC or CreateDC to get the entire screen of the device drive handle. Don't forget to release it with ReleaseDC or DELETEDC when you're done.
The following are the declaration methods for GetDC () and ReleaseDC () in C #

 [System.Runtime.InteropServices.DllImport (   )]  static  extern  IntPtr GetDC (IntPtr Hwnd); //         [System.Runtime.InteropServices.DllImport ( "   )]  static  extern  int  ReleaseDC ( IntPtr hWnd, IntPtr HDC); 

    Then we get the device drive handle for the entire screen
    HDC = GetDC ( IntPtr.Zero); A device drive handle that returns the entire screen when the incoming pointer is empty
     Hey, we can use this device driver handle to scribble things, but before we do this, we'll start with this C # Uncommon things translate into familiar graphics. We just use the
    graphics   g = GRAPHICS.FROMHDC (HDC);//This is obtained from the device driver handle. NET only graphics class.
     Get these things, the rest will not need me to say more, these people can be on this screen love how to draw on how to draw. But remember to call ReleaseDC () to release the handle after the drawing is finished (it doesn't matter if you finish drawing the program).
    releasedc (IntPtr.Zero, HDC);  //the device driver handle on this screen is released.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.