Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to call the API function of Win32_ in C #

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how C # calls the API function of Win32_. It is very detailed and has certain reference value. Friends who are interested must finish reading it.

C # calls the API function of Win32-User32.dll

The API function of Win32 is Microsoft's own thing and can be called directly in C #, which is very helpful when doing WinForm. Sometimes we call Win32's API directly to achieve the desired effect very efficiently.

Code

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

/ / /

/ / this function retrieves a handle to the client area of a specified window or the display device context of the entire screen, which can be used later in the GDI function to draw in the device context. HWnd: on Devic

The handle to the window to which the following environment is retrieved

/ / /

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

Public static extern IntPtr GetDC (IntPtr hWnd)

/ / /

/ / the function releases the device context (DC) for use by other applications.

/ / /

Public static extern int ReleaseDC (IntPtr hWnd, IntPtr hDC)

/ / /

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

/ / /

Static public extern IntPtr GetDesktopWindow ()

/ / /

/ / this function sets the display state of the specified window.

/ / /

Static public extern bool ShowWindow (IntPtr hWnd, short State)

/ / /

/ / updates the invalid area of the target form's client area by sending a redraw message WM_PAINT to the target form.

/ / /

Static public extern bool UpdateWindow (IntPtr hWnd)

/ / /

/ / this function sets the thread that created the specified window to the foreground and activates the window. Keyboard input goes to the window and changes various visual markings for the user. The permissions assigned by the system to the thread creating the foreground window are slightly

Higher than other threads.

/ / /

Static public extern bool SetForegroundWindow (IntPtr hWnd)

/ / /

/ / this function changes the size, position, and Z order of a child window, pop-up top-level window.

/ / /

Static public extern bool SetWindowPos (IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int Width, int Height, uint flags)

/ / /

/ Open the clipboard

/ / /

Static public extern bool OpenClipboard (IntPtr hWndNewOwner)

/ / /

/ / close the clipboard

/ / /

Static public extern bool CloseClipboard ()

/ / /

/ / Open and empty

Static public extern bool EmptyClipboard ()

/ / /

/ / put the memory blocks containing data into the resource management of the clipboard

/ / /

Static public extern IntPtr SetClipboardData (uint Format, IntPtr hData)

/ / /

/ / load the screen coordinate information of the specified menu entry in a rectangle

/ / /

Static public extern bool GetMenuItemRect (IntPtr hWnd, IntPtr hMenu, uint Item, ref RECT rc)

[DllImport ("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)] / this function gets a handle to the parent window that specifies the child window. / public static extern IntPtr GetParent (IntPtr hWnd); / this function sends the specified message to one or more windows. This function calls the window program for the specified window until the window program has finished processing the message before returning. / the window program whose window program will receive the message handle / specify the message to be sent / specify additional message specification information / specify additional message specification information / 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) / this function places (sends) a message into the message queue associated with the thread created by the specified window / 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); / this function sets the keyboard focus on the specified window. / public static extern IntPtr SetFocus (IntPtr hWnd); / this function writes formatted text in the specified rectangle and formats the text according to the specified method (extended tabs, character alignment, line breaks, etc.). / / public extern static int DrawText (IntPtr hdc, string lpString, int nCount, ref RECT lpRect, int uFormat); / this function changes the parent window of the specified child window. / public extern static IntPtr SetParent (IntPtr hChild, IntPtr hParent); / public extern static IntPtr GetDlgItem (IntPtr hDlg, int nControlID) of the sub-window control in the dialog box; / this function gets the coordinates of the client area of the window. / public extern static int GetClientRect (IntPtr hWnd, ref RECT rc); / this function adds a rectangle to the specified form, and then this part of the client area of the window will be redrawn. / public extern static int InvalidateRect (IntPtr hWnd, IntPtr rect, int bErase); / this function produces control over other threads if one thread has no other messages in its message queue. / public static extern bool WaitMessage (); / this function checks the thread message queue for a message and places the message (if it exists) in the specified structure. / / public static extern bool PeekMessage (ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax, uint wFlag); / this function takes a message from the calling thread's message queue and places it in the specified structure. This function gets the messages contacted with the specified window and the thread messages sent by PostThreadMesssge. This letter

Number receives a certain range of message values.

/ / /

Public static extern bool GetMessage (ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax)

/ / /

/ / this function converts a virtual key message into a character message.

/ / /

Public static extern bool TranslateMessage (ref MSG msg)

/ / /

/ / this function dispatches a message to the window program.

/ / /

Public static extern bool DispatchMessage (ref MSG msg)

/ / /

/ / this function loads the specified cursor resource from an executable file (EXE file) associated with the application case.

/ / /

Public static extern IntPtr LoadCursor (IntPtr hInstance, uint cursor)

/ / /

/ / this function determines the shape of the cursor.

/ / /

Public static extern IntPtr SetCursor (IntPtr hCursor)

/ / /

/ / determines which control the current focus is on.

/ / /

Public static extern IntPtr GetFocus ()

/ / /

/ / this function releases the mouse capture from the window in the current thread and resumes the normal mouse input processing. The window that captures the mouse receives all mouse input (no matter where the cursor is located) unless the mouse button is clicked

The cursor hotspot is in the window of another thread.

/ / /

Public static extern bool ReleaseCapture ()

/ / /

/ / prepare the specified window to redraw and put the painting-related information into a PAINTSTRUCT structure.

/ / /

Public static extern IntPtr BeginPaint (IntPtr hWnd, ref PAINTSTRUCT ps)

/ / /

/ / Mark the end of the drawing process of the specified window, which is requested after each call to the BeginPaint function

/ / /

Public static extern bool EndPaint (IntPtr hWnd, ref PAINTSTRUCT ps)

/ / /

/ / translucent form

/ / /

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)

/ / /

/ / this function returns the size of the border rectangle of the specified window. The size is given relative to the screen coordinates in the upper-left corner of the screen coordinates.

/ / /

Public static extern bool GetWindowRect (IntPtr hWnd, ref RECT rect)

/ / /

/ / this function converts the user coordinates of the specified point into screen coordinates.

/ / /

Public static extern bool ClientToScreen (IntPtr hWnd, ref POINT pt)

/ / /

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

/ / /

Public static extern bool TrackMouseEvent (ref TRACKMOUSEEVENTS tme)

/ / /

/ / /

/ / /

Public static extern bool SetWindowRgn (IntPtr hWnd, IntPtr hRgn, bool redraw)

/ / /

/ / this function picks up the state of the specified virtual key.

/ / /

Public static extern ushort GetKeyState (int virtKey)

/ / /

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

.

/ / /

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

/ / /

/ / this function gets the class name of the class to which the specified window belongs.

/ / /

Public static extern int GetClassName (IntPtr hWnd, out STRINGBUFFER ClassName, int nMaxCount)

/ / /

/ / this function changes the properties of the specified window

/ / /

Public static extern int SetWindowLong (IntPtr hWnd, int nIndex, int dwNewLong)

/ / /

/ / this function retrieves the handle to the display device context of the specified window client area or the entire screen, which can be used in subsequent GDI functions to draw in the device context.

/ / /

Public static extern IntPtr GetDCEx (IntPtr hWnd, IntPtr hRegion, uint flags)

/ / /

/ / get the device scene return value Long of the entire window (including borders, scroll bars, title bars, menus, etc.).

/ / /

Public static extern IntPtr GetWindowDC (IntPtr hWnd)

/ / /

/ / this function fills the rectangle with the specified brush, which includes the upper left boundary of the rectangle, but does not include the lower right boundary of the rectangle.

/ / /

Public static extern int FillRect (IntPtr hDC, ref RECT rect, IntPtr hBrush)

/ / /

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

/ / /

Public static extern int GetWindowPlacement (IntPtr hWnd, ref WINDOWPLACEMENT wp)

/ / /

/ / this function changes the text content of the title bar of the specified window

/ / /

Public static extern int SetWindowText (IntPtr hWnd, string text)

/ / /

/ / this function copies the title bar text (if any) of the specified window into a cache. If the specified window is a control, the text of the control is copied.

/ / /

Public static extern int GetWindowText (IntPtr hWnd, out STRINGBUFFER text, int maxCount)

/ / /

/ / used to get defined system data or system configuration information.

/ / /

Static public extern int GetSystemMetrics (int nIndex)

/ / /

/ / this function sets scroll bar parameters, including the maximum and minimum values of the scroll position, the page size, and the position of the scroll button.

/ / /

Static public extern int SetScrollInfo (IntPtr hwnd, int bar, ref SCROLLINFO si, int fRedraw)

/ / /

/ / this function shows or hides the specified scroll bar.

/ / /

Public static extern int ShowScrollBar (IntPtr hWnd, int bar, int show)

/ / /

/ / this function can activate one or two scroll bar arrows or disable them.

/ / /

Public static extern int EnableScrollBar (IntPtr hWnd, uint flags, uint arrows)

/ / /

/ / this function sets the specified window to the top of the Z order.

/ / /

Public static extern int BringWindowToTop (IntPtr hWnd)

/ / /

/ / this function scrolls the directory that specifies the client area of the form.

/ / /

Static public extern int ScrollWindowEx (IntPtr hWnd, int dx, int dy,ref RECT rcScroll, ref RECT rcClip, IntPtr UpdateRegion, ref RECT

RcInvalidated, uint flags)

/ / /

/ / this function determines whether a given window handle recognizes an existing window.

/ / /

Public static extern int IsWindow (IntPtr hWnd)

/ / /

/ / this function copies the status of 256 virtual keys to the specified buffer.

/ / /

Public static extern int GetKeyboardState (byte [] pbKeyState)

/ / /

/ / this function translates the specified virtual key code and keyboard status into the corresponding character or string. This function translates code using the physical keyboard layout and input language identified by the given keyboard layout handle.

/ / /

Public static extern int ToAscii (int uVirtKey,int uScanCode, byte [] lpbKeyState, byte [] lpwTransKey,int fuState)

# endregion

} these are all the contents of the article "how to call Win32_ 's API function in C #". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report