C # API function calls Win32_ --User32.dll

Mori from the Science and Technology official blog
http://www.cnsendblog.com/index.php/?p=230
the GPS platform, site construction, software development, system operation and maintenance, to find a large forest network technology!
http://cnsendnet.taobao.com

C # call the Win32 API function --User32.dll

Win32 API functions that Microsoft's own thing, can be directly invoked directly in C #, in doing WinForm or helpful. Sometimes we directly call the Win32 API, where it is efficient to achieve the desired effect.

代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

WindowsAPI namespace
{
class CSharp_Win32Api
{
#region the User32.dll function
/// <summary>
handles the display device context /// This function retrieves a specified window client area or the entire screen, the handle can be used later in the GDI functions in the device for drawing context. hWnd: the device

Hereinafter retrieved environment handle window
/// </ Summary>
[the DllImport ( "User32.dll", the CharSet = CharSet.Auto)]
public static extern IntPtr the GetDC (IntPtr the hWnd);
/// <Summary>
/// function to release the device context (DC) for use by other applications.
/// </ Summary>
public static extern int the ReleaseDC (IntPtr the hWnd, IntPtr the hDC);
/// <Summary>
/// This function returns a handle to the desktop window. The desktop window covers the entire screen.
/// </ Summary>
static public extern IntPtr the GetDesktopWindow ();
/// <Summary>
/// This function sets the specified window display state.
/// </ Summary>
static public extern BOOL the ShowWindow (IntPtr the hWnd, Short State);
/// <Summary>
/// WM_PAINT message by transmitting to the target redraw form to update the target window's client area invalid region.
/// </ summary>


/// This function creates a thread sets the specified window to the foreground and activate the window. Steering the keyboard input window, and for the user to change various visual mark. Foreground window system to create a thread assigned permissions slightly

Higher than other threads.
/// </ Summary>
static public extern BOOL the SetForegroundWindow (IntPtr the hWnd);
/// <Summary>
/// This function changes a child window, the size of top-level window pop-up window type, position and Z order.
/// </ Summary>
static public extern BOOL the SetWindowPos (IntPtr the hWnd, IntPtr hWndInsertAfter, X int, int Y, the Width int, int the Height, uint the flags);
/// <Summary>
/// open clipboard
// / </ Summary>
static public extern BOOL OpenClipboard (IntPtr hWndNewOwner);
/// <Summary>
/// Close clipboard
/// </ Summary>
static public extern BOOL CloseClipboard ();
/// <Summary>
/ // open empty </ Summary>
static public extern BOOL the EmptyClipboard ();
/// <Summary>


extern IntPtr the SetClipboardData public static (uint the Format, IntPtr hData);
/// <Summary>
/// specified menu item loaded in a rectangle in screen coordinates information
/// </ Summary>
static public extern BOOL GetMenuItemRect (IntPtr the hWnd, IntPtr hMenu, uint Item, ref RECT rc);

    [DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
    /// <summary>
    /// 该函数获得一个指定子窗口的父窗口句柄。
    /// </summary>
    public static extern IntPtr GetParent(IntPtr hWnd);
    /// <summary>
    /// 该函数将指定的消息发送到一个或多个窗口。此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回。 
    /// </summary>
    /// <param name="hWnd">其窗口程序将接收消息的窗口的句柄</param>
    /// <param name="msg">指定被发送的消息</param>
    /// <param name="wParam">指定附加的消息指定信息</param>
    /// <param name="lParam">指定附加的消息指定信息</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>
    /// 该函数将一个消息放入(寄送)到与指定窗口创建的线程相联系消息队列里
    /// </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>
    /// 该函数对指定的窗口设置键盘焦点。
    /// </summary>
    public static extern IntPtr SetFocus(IntPtr hWnd);
    /// <summary>
    /// 该函数在指定的矩形里写入格式化文本,根据指定的方法对文本格式化(扩展的制表符,字符对齐、折行等)。
    /// </summary>
    public extern static int DrawText(IntPtr hdc, string lpString, int nCount, ref RECT lpRect, int uFormat);
    /// <summary>
    /// 该函数改变指定子窗口的父窗口。
    /// </summary>
    public extern static IntPtr SetParent(IntPtr hChild, IntPtr hParent);
    /// <summary>
    /// 获取对话框中子窗口控件的句柄
    /// </summary>
    public extern static IntPtr GetDlgItem(IntPtr hDlg, int nControlID);
    /// <summary>
    /// 该函数获取窗口客户区的坐标。
    /// </summary>
    public extern static int GetClientRect(IntPtr hWnd, ref RECT rc);
    /// <summary>
    /// 该函数向指定的窗体添加一个矩形,然后窗口客户区域的这一部分将被重新绘制。
    /// </summary>
    public extern static int InvalidateRect(IntPtr hWnd, IntPtr rect, int bErase);
    /// <summary>
    /// 该函数产生对其他线程的控制,如果一个线程没有其他消息在其消息队列里。
    /// </summary>
    public static extern bool WaitMessage();
    /// <summary>
    /// 该函数为一个消息检查线程消息队列,并将该消息(如果存在)放于指定的结构。
    /// </summary>
    public static extern bool PeekMessage(ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax, uint wFlag);
    /// <summary>
    /// 该函数从调用线程的消息队列里取得一个消息并将其放于指定的结构。此函数可取得与指定窗口联系的消息和由PostThreadMesssge寄送的线程消息。此函

A range of number of messages received value.
/// </ Summary>
public static extern BOOL the GetMessage (REF MSG the MSG, the hWnd int, uint wFilterMin, uint wFilterMax);
/// <Summary>
/// This function virtual key messages into character messages.
/// </ Summary>
public static extern BOOL TranslateMessage (REF the MSG MSG);
/// <Summary>
/// This function dispatch a message to the window procedure.
/// </ Summary>
public static extern BOOL the DispatchMessage (REF the MSG MSG);
/// <Summary>
/// This function executable file (EXE file) from a load associated with the application instance specified cursor resource .
/// </ Summary>
public static extern IntPtr the LoadCursor (IntPtr hInstance, uint cursor);
/// <Summary>
/// this function determines the shape of the cursor.
/// </ Summary>
public static extern IntPtr SetCursor (IntPtr hCursor);
/// <Summary>
/// determine the current focus is on which control.
/// </ Summary>
public static extern IntPtr the GetFocus ();
/// <Summary>
/// This function releases the mouse capture window from the current thread, and the process returns to the normal mouse input. Capturing the mouse a window receives all mouse input (regardless of where the cursor position), unless the click of a mouse button

When the cursor hotspot in another thread in the window.
/// </ Summary>
public static extern BOOL the ReleaseCapture ();
/// <Summary>
/// specified window redraw preparation and painting related information into a PAINTSTRUCT structure.
/// </ Summary>
public static extern IntPtr BeginPaint (IntPtr the hWnd, the PAINTSTRUCT REF PS);
/// <Summary>
end tag /// the specified window painting process, after each function call is requested BeginPaint
/// < / Summary>
public static extern BOOL of EndPaint (IntPtr the hWnd, the PAINTSTRUCT REF PS);
/// <Summary>
/// translucent form
/// </ Summary>
public static extern UpdateLayeredWindow is BOOL (HWND IntPtr, IntPtr hdcDst, REF POINT pptDst, ref SIZE psize, IntPtr hdcSrc, ref POINT pprSrc,

CrKey int32, REF BLENDFUNCTION pblend, the dwFlags int32);
/// <Summary>
/// This function returns the size of the window frame rectangle. The relative size of the screen coordinates of the upper left corner of the given coordinates.
/// </ Summary>
public static extern BOOL the GetWindowRect (IntPtr the hWnd, the RECT RECT REF);
/// <Summary>
/// This function specifies a user point coordinate transformation into a screen coordinate.
/// </ Summary>
public static extern BOOL ClientToScreen (IntPtr the hWnd, the POINT Pt REF);
/// <Summary>
/// when hovering the mouse pointer leaves or on a window within the specified time, the function Send messages.
/// </ Summary>
public static extern BOOL TrackMouseEvent (REF TRACKMOUSEEVENTS TME);
/// <Summary>
///
/// </ Summary>
public static extern BOOL the SetWindowRgn (IntPtr the hWnd, IntPtr hRgn, the redraw BOOL);
/// <summary>
/// The specified function seized state of the virtual keys.
/// </ summary>
ushort the GetKeyState extern static public (int VIRTKEY);
/// <Summary>
/// This function changes the position and size of the specified window. For top-level window position and size are relative to the upper-left corner of the screen: For the child window position and size are relative to the upper left corner of the parent window client area coordinates

.
/// </ Summary>
public static extern BOOL the MoveWindow (IntPtr the hWnd, int X, Y int, int width, int height, BOOL the repaint);
/// <Summary>
/// This function gets the window belongs to the class designated class name.
/// </ Summary>
public static extern int the GetClassName (IntPtr the hWnd, StringBuffer ClassName OUT, int nMaxCount);
/// <Summary>
/// This function changes the properties of the specified window
/// </ Summary>
public static extern the SetWindowLong int (IntPtr the hWnd, int nIndex, int dwNewLong);
/// <Summary>
handle /// this function retrieves the specified window client area or the entire screen of the display device context, in subsequent GDI functions can use the handle in the drawing the device context.
/// </ Summary>
public static extern IntPtr to GetDCEx (IntPtr the hWnd, IntPtr HRegion, the flags uint);
/// <Summary>
/// get the entire window (including borders, scroll bars, title bars, menus, etc.) of the device context return value Long.
/// </ summary>
extern IntPtr GetWindowDC static public (IntPtr the hWnd);
/// <Summary>
/// This function fill the rectangle with the specified brush painting, this function comprising a rectangular upper left boundary, but does not include a lower right rectangular boundary.
/// </ Summary>
public static extern int FillRect (IntPtr the hDC, the RECT RECT REF, IntPtr hBrush);
/// <Summary>
/// This function returns the window, and the specified display state is restored, and maximizing minimized window position.
/// </ Summary>
public static extern int the GetWindowPlacement (IntPtr the hWnd, REF WINDOWPLACEMENT WP);
/// <Summary>
text /// This function changes the specified window title bar
/// </ Summary>
public static int the SetWindowText extern (IntPtr the hWnd, String text);
/// <Summary>
/// this function specified provision of this window's title (if present) are copied to a buffer zone. If the specified window is a control, a control text is copied.
/// </ Summary>
public static extern int the GetWindowText (IntPtr the hWnd, OUT StringBuffer text,
/// <Summary>
/// for system data or system configuration information is defined.
/// </ Summary>
static public extern int the GetSystemMetrics (int nIndex);
/// <Summary>
/// This function set the scroll bar parameters, including maximum and minimum position of the scroll position, the page size, the scroll button.
/// </ Summary>
static public extern int the SetScrollInfo (IntPtr HWND, int bar, the SCROLLINFO REF Si, int fRedraw);
/// <Summary>
/// show or hide the function specified in the scroll bar.
/// </ Summary>
public static extern int ShowScrollBar (IntPtr the hWnd, bar int, int Show);
/// <Summary>
/// This function may activate one or both of the scroll bar arrows or rendered ineffective.
/// </ Summary>
public static extern int EnableScrollBar (IntPtr the hWnd, the flags uint, uint ARROWS);
/// <Summary>
/// This function will set the specified window to the top of the Z order.
/// </ summary>
extern int BringWindowToTop static public (IntPtr the hWnd);
/// <Summary>
/// the specified directory scrolling function of the window's client area.
/// </ Summary>
static public extern int ScrollWindowEx (IntPtr the hWnd, DX int, int Dy, the RECT rcScroll REF, REF rcClip the RECT, IntPtr UpdateRegion, the RECT REF

rcInvalidated, the flags uint);
/// <Summary>
/// This function determines whether the window handle given an existing window identification.
/// </ Summary>
public static extern int the IsWindow (IntPtr the hWnd);
/// <Summary>
/// The function keys 256 the state of the virtual copy to the specified buffer.
/// </ Summary>
public static extern int the GetKeyboardState (byte [] pbKeyState);
/// <Summary>
/// This function specified virtual key and the keyboard state or translated into the corresponding character string. This function uses the physical keyboard layout and input language by a given keyboard layout handle identified by the translated code.
/// </ Summary>
public static extern int ToASCII (uVirtKey int, int uScanCode, byte [] lpbKeyState, byte [] lpwTransKey, int fuState);
#endregion

}

Mori from the Science and Technology official blog
http://www.cnsendblog.com/index.php/?p=230
the GPS platform, site construction, software development, system operation and maintenance, to find a large forest network technology!
http://cnsendnet.taobao.com

Guess you like

Origin blog.51cto.com/14036626/2462733