2024年3月29日发(作者:)
Win32的API函数是微软自己的东西,可以直接在C#中直接调用,在做WinForm
时还是很有帮助的。有时候我们之直接调用Win32 的API,可以很高效的实现想
要的效果。
代码
using System;
using c;
using ;
using ;
using pServices;
namespace WindowsAPI
{
class CSharp_Win32Api
{
#region 函数
///
/// 该函数检索一指定窗口的客户区域或整个屏幕的显示设备上下文
环境的句柄,以后可以在GDI函数中使用该句柄来在设备上下文环境中绘图。
hWnd:设备上下文环境被检索的窗口的句柄
///
[DllImport("", CharSet = )]
public static extern IntPtr GetDC(IntPtr hWnd);
///
/// 函数释放设备上下文环境(DC)供其他应用程序使用。
///
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
///
/// 该函数返回桌面窗口的句柄。桌面窗口覆盖整个屏幕。
///
static public extern IntPtr GetDesktopWindow();
///
/// 该函数设置指定窗口的显示状态。
///
static public extern bool ShowWindow(IntPtr hWnd, short State
);
///
/// 通过发送重绘消息 WM_PAINT 给目标窗体来更新目标窗体客户区
的无效区域。
///
static public extern bool UpdateWindow(IntPtr hWnd);
///
/// 该函数将创建指定窗口的线程设置到前台,并且激活该窗口。键盘
输入转向该窗口,并为用户改各种可视的记号。系统给创建前台窗口的线程分配
的权限稍高于其他线程。
///
static public extern bool SetForegroundWindow(IntPtr hWnd);
///
/// 该函数改变一个子窗口,弹出式窗口式顶层窗口的尺寸,位置和Z
序。
///
static public extern bool SetWindowPos(IntPtr hWnd, IntPtr hW
ndInsertAfter, int x, int y, int Width, int Height, uint flags);
///
/// 打开剪切板
///
static public extern bool OpenClipboard(IntPtr hWndNewOwner);
///
/// 关闭剪切板
///
static public extern bool CloseClipboard();
///
/// 打开清空
static public extern bool EmptyClipboard();
///
/// 将存放有数据的内存块放入剪切板的资源管理中
///
static public extern IntPtr SetClipboardData(uint Format, Int
Ptr hData);
///
/// 在一个矩形中装载指定菜单条目的屏幕坐标信息
///
static public extern bool GetMenuItemRect(IntPtr hWnd, IntPtr
hMenu, uint Item, ref RECT rc);
[DllImport("", ExactSpelling = true, CharSet = Char
)]
///
/// 该函数获得一个指定子窗口的父窗口句柄。
///
public static extern IntPtr GetParent(IntPtr hWnd);
///
/// 该函数将指定的消息发送到一个或多个窗口。此函数为指定的窗口
调用窗口程序,直到窗口程序处理完消息再返回。
///
/// 其窗口程序将接收消息的窗口的句柄


发布评论