c# 窗体常用的dll

1.查找窗口

[DllImport("user32.dll", EntryPoint = "FindWindow")]
        private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);

lpClassName:要找的窗口类,一般null

lpWindowName:要找的窗口标题

2.发送消息到一个或多个窗口

[DllImport("User32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]
        private static extern int SendMessage(IntPtr hwnd, uint wMsg, int wParam, int lParam);

hwnd:窗口句柄(类似FindWindow返回值)

wMsg:区别于其他消息的常量值,16进制数

wParam:通常是一个与消息有关的常量值,也可能是窗口或控件的句柄  0

lParam:一个指向内存中数据的指针  0

3.查找子窗体

[DllImport("User32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
        private static extern IntPtr FindWindowEx(IntPtr hwndParent, uint hwndChildAfter, string lpszClass, string lpszWindow);

hwndParent:查找子窗体的父窗体句柄,若为null则以桌面为父窗体

hwndChildAfter:子窗体句柄

lpszClass:只想一个指定了类名的空结束字符串,或标识一个类名字符串成员的指针

lpszWindow:指向一个指定了窗体名(窗体标题)的空结束字符串

4.获取进程接口ID

[DllImport("User32.dll", CharSet = CharSet.Auto)]
        public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);

hwnd:窗口句柄,由FindWindow获取

ID:存放进程ID的变量

5.减少内存占用

[DllImport("KERNEL32.DLL", EntryPoint = "SetProcessWorkingSetSize", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
        internal static extern bool SetProcessWorkingSetSize(IntPtr pProcess, int dwMinimumWorkingSetSize, int dwMaximumWorkingSetSize);
        [DllImport("KERNEL32.DLL", EntryPoint = "GetCurrentProcess", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
        internal static extern IntPtr GetCurrentProcess();

调用:IntPtr pHandle = GetCurrentProcess();

           SetProcessWorkingSetSize(pHandle,-1,-1);

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值