C # calls Win32 's API function--user32.dll

Source: Internet
Author: User
Tags message queue

Using System;

Using System.Collections.Generic;

Using System.Linq;

Using System.Text;

Using System.Runtime.InteropServices;

Namespace WindowsAPI

{

Class Csharp_win32api

{

#region User32.dll function

<summary>

This function retrieves a handle to the display device context environment for a specified window's customer area or the entire screen, which can be used later in the GDI function to draw in the device context. HWnd: The handle of the window retrieved by the device context environment

</summary>

[DllImport ("user32.dll", CharSet = CharSet.Auto)]

public static extern IntPtr GetDC (IntPtr hWnd);

<summary>

The function frees the device context (DC) for use by other applications.

</summary>

public static extern int ReleaseDC (IntPtr hWnd, IntPtr HDC);

<summary>

The function returns a handle to the desktop window. The desktop window covers the entire screen.

</summary>

static public extern IntPtr GetDesktopWindow ();

<summary>

This function sets the display state of the specified window.

</summary>

static public extern bool ShowWindow (INTPTR hWnd, short state);

<summary>

Updates the invalid area of the target form client area by sending a redraw message wm_paint to the target form.

</summary>

static public extern bool UpdateWindow (IntPtr hWnd);

<summary>

The function creates a thread setting for the specified window to the foreground and activates the window. The keyboard input turns to the window and changes the various visual marks for the user. The system assigns a slightly higher permission to the thread that creates the foreground window than the other threads.

</summary>

static public extern bool SetForegroundWindow (IntPtr hWnd);

<summary>

This function changes the size, position, and Z-order of a subwindow, pop-up window top-level window.

</summary>

static public extern bool SetWindowPos (IntPtr hWnd, IntPtr hwndinsertafter, int x, int y, int Width, int Height, UINT flag s);

<summary>

Open the Clipboard

</summary>

static public extern bool OpenClipboard (IntPtr Hwndnewowner);

<summary>

Close the Clipboard

</summary>

static public extern bool CloseClipboard ();

<summary>

Open Empty </summary>

static public extern bool EmptyClipboard ();

<summary>

Place memory blocks with data into the resource management of the Clipboard

</summary>

static public extern IntPtr SetClipboardData (uint Format, IntPtr hdata);

<summary>

Loads the screen coordinate information of a specified menu item in a rectangle

</summary>

static public extern bool Getmenuitemrect (IntPtr hWnd, IntPtr hMenu, uint Item, ref RECT RC);

[DllImport ("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]

<summary>

The function obtains a handle to the parent window of a specified child window.

</summary>

public static extern IntPtr GetParent (IntPtr hWnd);

<summary>

The function sends the specified message to one or more windows. This function invokes the window program for the specified window until the window program finishes processing the message and returns.

</summary>

<param name= "HWnd" > The handle of the window whose window program will receive the message </param>

<param name= "MSG" > Specify message to be sent </param>

<param name= "WParam" > Specify additional messages to specify information </param>

<param name= "LParam" > Specify additional messages to specify information </param>

<returns></returns>

public static extern int SendMessage (IntPtr hWnd, int msg, int wParam, int lParam);

public static extern IntPtr SendMessage (IntPtr hWnd, int msg, int wParam, IntPtr lParam);

public static extern void SendMessage (IntPtr hWnd, int msg, int wParam, ref RECT LParam);

public static extern int SendMessage (IntPtr hWnd, int. msg, int wParam, ref point LParam);

public static extern void SendMessage (IntPtr hWnd, int msg, int wParam, ref Tbbutton LParam);

public static extern void SendMessage (IntPtr hWnd, int msg, int wParam, ref tbbuttoninfo LParam);

public static extern int SendMessage (IntPtr hWnd, int msg, int wParam, ref rebarbandinfo LParam);

public static extern void SendMessage (IntPtr hWnd, int msg, int wParam, ref tvitem LParam);

public static extern void SendMessage (IntPtr hWnd, int msg, int wParam, ref lvitem LParam);

public static extern void SendMessage (IntPtr hWnd, int msg, int wParam, ref hditem LParam);

public static extern void SendMessage (IntPtr hWnd, int msg, int wParam, ref hd_hittestinfo hti);

<summary>

This function places a message in a message queue to the thread created by the specified window.

</summary>

public static extern IntPtr PostMessage (IntPtr hWnd, int msg, int wParam, int lParam);

public static extern IntPtr SetWindowsHookEx (int hookid, HookProc pfnhook, IntPtr hinst, int threadid);

[DllImport ("user32.dll", CharSet = CharSet.Auto, ExactSpelling = True)]

public static extern bool UnhookWindowsHookEx (IntPtr hhook);

[DllImport ("user32.dll", CharSet = CharSet.Auto, ExactSpelling = True)]

public static extern IntPtr CallNextHookEx (IntPtr hhook, int code, INTPTR wparam, INTPTR lparam);

<summary>

The function sets the keyboard focus on the specified window.

</summary>

public static extern IntPtr SetFocus (IntPtr hWnd);

<summary>

The function writes formatted text in the specified rectangle, formatting the text according to the specified method (extended tabs, character alignment, wrapping, and so on).

</summary>

public extern static int DrawText (INTPTR hdc, string lpstring, int ncount, ref RECT lpRect, int uformat);

<summary>

The function changes the parent window of the specified child window.

</summary>

public extern static IntPtr SetParent (IntPtr hchild, IntPtr hparent);

<summary>

Gets the handle of a child window control in a dialog box

</summary>

public extern static IntPtr GetDlgItem (IntPtr hdlg, int ncontrolid);

<summary>

This function gets the coordinates of the client area of the window.

</summary>

public extern static int GetClientRect (INTPTR hWnd, ref RECT RC);

<summary>

The function adds a rectangle to the specified form, and then this part of the client area of the window is redrawn.

</summary>

public extern static int InvalidateRect (INTPTR hWnd, IntPtr rect, int bErase);

<summary>

This function generates control over other threads if one thread has no other message in its message queue.

</summary>

public static extern bool WaitMessage ();

<summary>

The function checks the thread message queue for a message and places the message (if it exists) in the specified structure.

</summary>

public static extern bool PeekMessage (ref msg msg, int hWnd, uint wfiltermin, uint wfiltermax, uint wflag);

<summary>

The function obtains a message from the message queue of the calling thread and places it in the specified structure. This function gets the message that is contacted by the specified window and the thread message sent by Postthreadmesssge. This function receives a certain range of message values.

</summary>

public static extern bool GetMessage (ref msg msg, int hWnd, uint wfiltermin, uint wfiltermax);

<summary>

The function converts the virtual key message to a character message.

</summary>

public static extern bool TranslateMessage (ref msg msg);

<summary>

The function dispatches a message to the window program.

</summary>

public static extern bool DispatchMessage (ref msg msg);

<summary>

The function loads the specified cursor resource from an executable file (EXE file) that is related to the application case.

</summary>

public static extern IntPtr LoadCursor (IntPtr hinstance, uint cursor);

<summary>

This function determines the shape of the cursor.

</summary>

public static extern IntPtr SetCursor (IntPtr hcursor);

<summary>

Determines which control the current focus is on.

</summary>

public static extern IntPtr GetFocus ();

<summary>

This function releases the mouse capture from the window in the current thread and restores the usual mouse input processing. The window that captures the mouse receives all mouse input (regardless of where the cursor is located), unless the mouse button is clicked, and the cursor hotspot is in the window of another thread.

</summary>

public static extern bool ReleaseCapture ();

<summary>

Prepares the specified window to redraw and place paint-related information into a paintstruct structure.

</summary>

public static extern IntPtr BeginPaint (IntPtr hWnd, ref paintstruct PS);

<summary>

Marks the end of the painting process for the specified window, which is requested after each call to the BeginPaint function

</summary>

public static extern bool EndPaint (IntPtr hWnd, ref paintstruct PS);

<summary>

Translucent Forms

</summary>

public static extern bool Updatelayeredwindow (INTPTR hwnd, INTPTR HDCDST, ref point PPTDST, ref SIZE psize, IntPtr hdcsrc, Ref point PPRSRC, Int32 Crkey, ref blendfunction Pblend, Int32 dwFlags);

<summary>

The function returns the dimensions of the bounding rectangle for the specified window. The dimension is given in screen coordinates relative to the upper-left corner of the screen coordinates.

</summary>

public static extern bool GetWindowRect (IntPtr hWnd, ref rect rect);

<summary>

This function converts the user coordinates of the specified point to screen coordinates.

</summary>

public static extern bool ClientToScreen (IntPtr hWnd, ref point PT);

<summary>

This function sends a message when the mouse pointer leaves or hovers over a window within a specified time.

</summary>

public static extern bool TrackMouseEvent (ref trackmouseevents TME);

<summary>

///

</summary>

public static extern bool SetWindowRgn (IntPtr hWnd, IntPtr hRgn, bool redraw);

<summary>

This function checks the state of the specified virtual key.

</summary>

public static extern ushort getkeystate (int virtkey);

<summary>

This function changes the position and size of the specified window. For the top-level window, the position and dimensions are relative to the upper-left corner of the screen: for child windows, the position and dimensions are relative to the upper-left coordinates of the parent window's client area.

</summary>

public static extern bool MoveWindow (IntPtr hWnd, int x, int y, int width, int height, bool repaint);

<summary>

This function obtains the class name of the class to which the specified window belongs.

</summary>

public static extern int GetClassName (IntPtr hWnd, out stringbuffer ClassName, int nmaxcount);

<summary>

This function changes the properties of the specified window

</summary>

public static extern int SetWindowLong (IntPtr hWnd, int nIndex, int dwnewlong);

<summary>

This function retrieves a handle to the display device context environment for the specified window client area or the entire screen, which can be used in the device context to draw in subsequent GDI functions.

</summary>

public static extern IntPtr GetDCEx (IntPtr hWnd, IntPtr hregion, uint flags);

<summary>

Gets the device scene return value Long for the entire window (including borders, scroll bars, title bars, menus, and so on).

</summary>

public static extern IntPtr GETWINDOWDC (IntPtr hWnd);

<summary>

The function fills the rectangle with the specified brush, which includes the upper-left edge of the rectangle, but does not include the lower-right edge of the rectangle.

</summary>

public static extern int FillRect (IntPtr HDC, ref rect rect, IntPtr hbrush);

<summary>

The function returns the display state of the specified window and the restored, maximized, and minimized window position.

</summary>

public static extern int GetWindowPlacement (IntPtr hWnd, ref windowplacement WP);

<summary>

This function changes the text content of the title bar of the specified window

</summary>

public static extern int SetWindowText (IntPtr hWnd, string text);

<summary>

This function copies the title clause of the specified window (if present) to a buffer. If the specified window is a control, copy the controlled text.

</summary>

public static extern int GetWindowText (IntPtr hWnd, out stringbuffer text, int maxCount);

<summary>

Used to get the defined system data or system configuration information.

</summary>

static public extern int GetSystemMetrics (int nIndex);

<summary>

The function sets the scroll bar parameters, including the maximum and minimum scrolling position, the page size, and the position of the scroll button.

</summary>

static public extern int Setscrollinfo (INTPTR hwnd, int bar, ref SCROLLINFO si, int fredraw);

<summary>

The function shows or hides the specified scroll bar.

</summary>

public static extern int Showscrollbar (IntPtr hWnd, int bar, int show);

<summary>

The function can activate one or two scroll bar arrows or invalidate them.

</summary>

public static extern int Enablescrollbar (INTPTR hWnd, UINT flags, uint arrows);

<summary>

This function sets the specified window to the top of the z-order.

</summary>

public static extern int BringWindowToTop (IntPtr hWnd);

<summary>

The function scrolls the directory for the specified form client area.

</summary>

static public extern int Scrollwindowex (IntPtr hWnd, int dx, int dy,ref rect rcscroll, ref RECT Rcclip, IntPtr Updateregio N, ref RECT rcinvalidated, UINT flags);

<summary>

The function determines whether the given window handle recognizes an existing window.

</summary>

public static extern int IsWindow (IntPtr hWnd);

<summary>

This function copies the state of the 256 virtual keys into the specified buffer.

</summary>

public static extern int getkeyboardstate (byte[] pbkeystate);

<summary>

The function translates the specified virtual key code and keyboard state to the corresponding character or string. The function uses the physical keyboard layout and input language identified by the given keyboard layout handle to translate the code.

</summary>

public static extern int toascii (int uvirtkey,int uscancode, byte[] lpbkeystate, byte[] lpwtranskey,int fustate);

#endregion

}

}

C # calls Win32 's API function--user32.dll

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.