API Capture Screen

Source: Internet
Author: User

Need to invoke API functions

You need to introduce namespaces using System.Runtime.InteropServices at the beginning;

Get current Window handle: GetForegroundWindow ()

[DllImport ("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] public static extern IntPtr GetForegroundWindow () ;

The return value type is IntPtr, which is the handle of the currently acquired focus window

Method of Use: IntPtr Myptr=getforegroundwindow ();

After you get to the window handle, you can manipulate the window. For example, close the window or hide it in the window so that it appears

[DllImport ("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] public static extern int ShowWindow (INTPTR hwnd, I NT nCmdShow);

Wherein ShowWindow (INTPTR hwnd, int ncmdshow);

The meaning of nCmdShow

0 closing the window

1 Normal Size display window

2 Minimizing windows

3 Maximize Window

Use example: ShowWindow (myptr, 0);

To get the window size and position: Call method GetWindowRect (IntPtr hWnd, ref RECT LpRect)

[DllImport ("User32.dll")] [Return:marshalas (Unmanagedtype.bool)] static extern Bool GetWindowRect (IntPtr hWnd, ref RECT lpRect);

[StructLayout (layoutkind.sequential)] public struct RECT {public int left;//leftmost coordinate public int Top;//top coordinate public int right ; Right-most coordinate public int Bottom; Bottom-most coordinates}

Example:

Inptr Awin = GetForegroundWindow (); Gets the current window handle of the rect rect = new rect (); GetWindowRect (Awin, ref rect); int width = rc. RIGHT-RC. Left; The width of the window int height = rc. BOTTOM-RC. Top; The height of the window is int x = RC. Left; int y = rc. Top;

API Capture Screen

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.