获取当前窗口句柄:GetForegroundWindow()
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetForegroundWindow();

使用方法   IntPtr myPtr=GetForegroundWindow();
  [DllImport("kernel32.dll")]
static extern IntPtr LoadLibrary(string lpFileName); [DllImport("kernel32.dll", SetLastError = true)]
static extern bool FreeLibrary(IntPtr hModule);
// <summary>
        /// Loadlibrary 返回的函数库模块的句柄
        /// </summary>
        private IntPtr hModule = IntPtr.Zero;
     /// <summary>
        /// 装载 Dll
        /// </summary>
        /// <param name="lpFileName">DLL 文件名 </param>
        public void LoadDll(string lpFileName)
        {
            hModule = LoadLibrary(lpFileName);
            if (hModule == IntPtr.Zero)
            {
                throw (new Exception(" 没有找到 :" + lpFileName + "."));
            }
        }
        /// <summary>
        /// 卸载 Dll
        /// </summary>
        public void UnLoadDll()
        {
            FreeLibrary(hModule);
            hModule = IntPtr.Zero;
        }
    

c# 调用User32.dll的更多相关文章

  1. Python 调用 user32.dll

    import ctypes h = ctypes.windll.LoadLibrary("C:\\Windows\\System32\\user32.dll") h.Message ...

  2. 调用user32.dll显示其他窗口

    /// 该函数设置由不同线程产生的窗口的显示状态 /// </summary> /// <param name="hWnd">窗口句柄</param& ...

  3. C#中调用user32.dll库的keybd_Event函数,操作键盘

    keybd_event()的函数原型是: void keybd_event( byte bVk,          //虚拟键码 byte bScan,       //该键的硬件扫描码 dword ...

  4. C#中可直接调用WIN32的API函数--USER32.DLL

    Win32的API函数可以直接在C#中直接调用,在做WinForm时还是很有帮助的.有时候直接调用Win32的API,可以很高效的实现想要的效果. using System; using System ...

  5. 【转】c# 调用windows API(user32.dll)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...

  6. 【整理】c# 调用windows API(user32.dll)

    User32.dll提供了很多可供调用的接口,大致如下(转自http://blog.csdn.net/zhang399401/article/details/6978803) using System ...

  7. C#调用Win32 的API函数--User32.dll ----转载

    Win32的API函数是微软自己的东西,可以直接在C#中直接调用,在做WinForm时还是很有帮助的.有时候我们之直接调用Win32 的API,可以很高效的实现想要的效果. using System; ...

  8. Winform API "user32.dll"中的函数

    命名空间:System.Runtime.InteropServices /// <summary> /// 该函数检索一指定窗口的客户区域或整个屏幕的显示设备上下文环境的句柄,以后可以在G ...

  9. 整理分享C#通过user32.dll模拟物理按键操作的代码

    对系统模拟按键方面的知识和按键映射代码做了一下梳理,在这里分享出来,适用于开发自动操作工具和游戏外挂. 主代码: public const int KEYEVENTF_EXTENDEDKEY = 0x ...

  10. user32.dll

    user32.dll中的所有函数 using System; using System.Collections.Generic; using System.Linq; using System.Tex ...

随机推荐

  1. 今天试试NuxtJS

    nuxt可以大幅缩短首屏加载时间 Progressive Web App (PWA) Support 渐进式web应用 简单说 就是让你的web应用表现的就像本地应用一样,可以添加快捷方式 打开的时候 ...

  2. Angular8中共享模块,共享组件的写法(anular其他模块组件引用方法)

    Angular8中共享模块,共享组件的写法(anular其他模块组件引用方法) 第一步:全局创建一个共享的module 这里示例创建一个模块common-share 创建完成后,会生成两个文件 文件1 ...

  3. TS不能将类型“any[]”分配给类型“never[]”

    一.问题 在处理接口返回的数据,赋值给store中的数组时,报类型错误 data:{ cateList: [] } const getCateList = async () => { const ...

  4. C语言中的快排函数——qsort

    函数名 qsort(); 头文件 include<stdlib,h> 功能 对数组内的元素进行默认升序的快速排序 函数声明 void qsort( void *buf, size_t nu ...

  5. Eureka、Consul、Zookeeper注册中心总结

    组件名 编写语言 CAP 服务健康检查 对外暴露接口 Springcloud集成 Eureka Java AP 可配支持(安全机制) Http √ Consul Go CP 支持 Http/DNS √ ...

  6. Jpbc哈希函数如何实现

    1.(0,1)→Element元素 在Jpbc库中存在两个方法 Element A=G1.newRandomElement();A.setFromBytes(arr,0,arr.length);//A ...

  7. ROS入门:话题

    1.listener.cpp #include "ros/ros.h" #include "std_msgs/String.h" //回调函数,接收到话题后进入 ...

  8. 一篇文章让你了解这个基于树莓派而设计的工业计算机-CM4 Industrial

    CM4 Industrial是一款基于 Raspberry Pi / 树莓派 Compute Module 4,由EDATEC面向工业应用设计的嵌入式计算机设计的工业嵌入式计算机.系统可以根据不同的应 ...

  9. JZOJ 【2021.11.10NOIP提高组联考】

    简要题解 这套题比较 \(H_2O\) 建议题目背景美文共赏 \(\text{T1}\) 显然一个 \(O(n^3)\) 不能过的 \(dp\) 然而过了?! 用心在该卡时间的地方卡一卡 \(\tex ...

  10. 题解 [ZJOI2010]排列计数

    好题. % 你赛考到了不会摆烂,后来发现原来有向下取整,题面没有...( 就算有我也做不出来啦 qAq 首先我们会发现这个长得就是小根堆,答案就变成了小根堆的计数. 首先最小的数字肯定放在根的位置.我 ...