user32.dll的源码_user32.dll 源代码-程序员宅基地

技术标签: .NET Framework+CLR+C#知识  

user32.dll的源码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
 
namespace WindowsAPI
{
    
    class CSharp_Win32Api
    {
    
        #region User32.dll 函数
        /// <summary>
        /// 该函数检索一指定窗口的客户区域或整个屏幕的显示设备上下文环境的句柄,以后可以在GDI函数中使用该句柄来在设备上下文环境中绘图。hWnd:设备上下文环境被检索的窗口的句柄
        /// </summary>
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr GetDC(IntPtr hWnd);
        /// <summary>
        /// 函数释放设备上下文环境(DC)供其他应用程序使用。
        /// </summary>
        public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
        /// <summary>
        /// 该函数返回桌面窗口的句柄。桌面窗口覆盖整个屏幕。
        /// </summary>
        static public extern IntPtr GetDesktopWindow();
        /// <summary>
        /// 该函数设置指定窗口的显示状态。
        /// </summary>
        static public extern bool ShowWindow(IntPtr hWnd, short State);
        /// <summary>
        /// 通过发送重绘消息 WM_PAINT 给目标窗体来更新目标窗体客户区的无效区域。
        /// </summary>
        static public extern bool UpdateWindow(IntPtr hWnd);
        /// <summary>
        /// 该函数将创建指定窗口的线程设置到前台,并且激活该窗口。键盘输入转向该窗口,并为用户改各种可视的记号。系统给创建前台窗口的线程分配的权限稍高于其他线程。
        /// </summary>
        static public extern bool SetForegroundWindow(IntPtr hWnd);
        /// <summary>
        /// 该函数改变一个子窗口,弹出式窗口式顶层窗口的尺寸,位置和Z序。
        /// </summary>
        static public extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int Width, int Height, uint flags);
        /// <summary>
        /// 打开剪切板
        /// </summary>
        static public extern bool OpenClipboard(IntPtr hWndNewOwner);
 
 
        /// <summary>
        /// 关闭剪切板
        /// </summary>
        static public extern bool CloseClipboard();
        /// <summary>
        /// 打开清空</summary>
        static public extern bool EmptyClipboard();
        /// <summary>
        /// 将存放有数据的内存块放入剪切板的资源管理中
        /// </summary>
        static public extern IntPtr SetClipboardData(uint Format, IntPtr hData);
        /// <summary>
        /// 在一个矩形中装载指定菜单条目的屏幕坐标信息 
        /// </summary>
        static public extern bool GetMenuItemRect(IntPtr 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寄送的线程消息。此函数接收一定范围的消息值。
        /// </summary>
        public static extern bool GetMessage(ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax);
        /// <summary>
        /// 该函数将虚拟键消息转换为字符消息。
        /// </summary>
        public static extern bool TranslateMessage(ref MSG msg);
        /// <summary>
        /// 该函数调度一个消息给窗口程序。
        /// </summary>
        public static extern bool DispatchMessage(ref MSG msg);
        /// <summary>
        /// 该函数从一个与应用事例相关的可执行文件(EXE文件)中载入指定的光标资源.
        /// </summary>
        public static extern IntPtr LoadCursor(IntPtr hInstance, uint cursor);
        /// <summary>
        /// 该函数确定光标的形状。
        /// </summary>
        public static extern IntPtr SetCursor(IntPtr hCursor);
        /// <summary>
        /// 确定当前焦点位于哪个控件上。
        /// </summary>
        public static extern IntPtr GetFocus();
        /// <summary>
        /// 该函数从当前线程中的窗口释放鼠标捕获,并恢复通常的鼠标输入处理。捕获鼠标的窗口接收所有的鼠标输入(无论光标的位置在哪里),除非点击鼠标键时,光标热点在另一个线程的窗口中。
        /// </summary>
        public static extern bool ReleaseCapture();
        /// <summary>
        /// 准备指定的窗口来重绘并将绘画相关的信息放到一个PAINTSTRUCT结构中。
        /// </summary>
        public static extern IntPtr BeginPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
        /// <summary>
        /// 标记指定窗口的绘画过程结束,每次调用BeginPaint函数之后被请求
        /// </summary>
        public static extern bool EndPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
        /// <summary>
        /// 半透明窗体
        /// </summary>
        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);
        /// <summary>
        /// 该函数返回指定窗口的边框矩形的尺寸。该尺寸以相对于屏幕坐标左上角的屏幕坐标给出。
        /// </summary>
        public static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect);
        /// <summary>
        /// 该函数将指定点的用户坐标转换成屏幕坐标。
        /// </summary>
        public static extern bool ClientToScreen(IntPtr hWnd, ref POINT pt);
        /// <summary>
        /// 当在指定时间内鼠标指针离开或盘旋在一个窗口上时,此函数寄送消息。
        /// </summary>
        public static extern bool TrackMouseEvent(ref TRACKMOUSEEVENTS tme);
        /// <summary>
        /// 
        /// </summary>
        public static extern bool SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool redraw);
        /// <summary>
        /// 该函数检取指定虚拟键的状态。
        /// </summary>
        public static extern ushort GetKeyState(int virtKey);
        /// <summary>
        /// 该函数改变指定窗口的位置和尺寸。对于顶层窗口,位置和尺寸是相对于屏幕的左上角的:对于子窗口,位置和尺寸是相对于父窗口客户区的左上角坐标的。
        /// </summary>
        public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
        /// <summary>
        /// 该函数获得指定窗口所属的类的类名。
        /// </summary>
        public static extern int GetClassName(IntPtr hWnd, out STRINGBUFFER ClassName, int nMaxCount);
        /// <summary>
        /// 该函数改变指定窗口的属性
        /// </summary>
        public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
        /// <summary>
        /// 该函数检索指定窗口客户区域或整个屏幕的显示设备上下文环境的句柄,在随后的GDI函数中可以使用该句柄在设备上下文环境中绘图。
        /// </summary>
        public static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hRegion, uint flags);
        /// <summary>
        /// 获取整个窗口(包括边框、滚动条、标题栏、菜单等)的设备场景 返回值 Long。
        /// </summary>
        public static extern IntPtr GetWindowDC(IntPtr hWnd);
        /// <summary>
        /// 该函数用指定的画刷填充矩形,此函数包括矩形的左上边界,但不包括矩形的右下边界。
        /// </summary>
        public static extern int FillRect(IntPtr hDC, ref RECT rect, IntPtr hBrush);
        /// <summary>
        /// 该函数返回指定窗口的显示状态以及被恢复的、最大化的和最小化的窗口位置。
        /// </summary>
        public static extern int GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT wp);
        /// <summary>
        /// 该函数改变指定窗口的标题栏的文本内容
        /// </summary>
        public static extern int SetWindowText(IntPtr hWnd, string text);
        /// <summary>
        /// 该函数将指定窗口的标题条文本(如果存在)拷贝到一个缓存区内。如果指定的窗口是一个控制,则拷贝控制的文本。
        /// </summary>
        public static extern int GetWindowText(IntPtr hWnd, out STRINGBUFFER text, int maxCount);
        /// <summary>
        /// 用于得到被定义的系统数据或者系统配置信息.
        /// </summary>
        static public extern int GetSystemMetrics(int nIndex);
        /// <summary>
        /// 该函数设置滚动条参数,包括滚动位置的最大值和最小值,页面大小,滚动按钮的位置。
        /// </summary>
        static public extern int SetScrollInfo(IntPtr hwnd, int bar, ref SCROLLINFO si, int fRedraw);
        /// <summary>
        /// 该函数显示或隐藏所指定的滚动条。
        /// </summary>
        public static extern int ShowScrollBar(IntPtr hWnd, int bar, int show);
        /// <summary>
        /// 该函数可以激活一个或两个滚动条箭头或是使其失效。
        /// </summary>
        public static extern int EnableScrollBar(IntPtr hWnd, uint flags, uint arrows);
        /// <summary>
        /// 该函数将指定的窗口设置到Z序的顶部。
        /// </summary>
        public static extern int BringWindowToTop(IntPtr hWnd);
        /// <summary>
        /// 该函数滚动指定窗体客户区域的目录。
        /// </summary>
        static public extern int ScrollWindowEx(IntPtr hWnd, int dx, int dy,ref RECT rcScroll, ref RECT rcClip, IntPtr UpdateRegion, ref RECT rcInvalidated, uint flags);
        /// <summary>
        /// 该函数确定给定的窗口句柄是否识别一个已存在的窗口。
        /// </summary>
        public static extern int IsWindow(IntPtr hWnd);
        /// <summary>
        /// 该函数将256个虚拟键的状态拷贝到指定的缓冲区中。
        /// </summary>
        public static extern int GetKeyboardState(byte[] pbKeyState);
        /// <summary>
        /// 该函数将指定的虚拟键码和键盘状态翻译为相应的字符或字符串。该函数使用由给定的键盘布局句柄标识的物理键盘布局和输入语言来翻译代码。
        /// </summary>
        public static extern int ToAscii(int uVirtKey,int uScanCode, byte[] lpbKeyState, byte[] lpwTransKey,int fuState);
        #endregion
 
    }
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/WuLex/article/details/108877655

智能推荐

稀疏编码的数学基础与理论分析-程序员宅基地

文章浏览阅读290次,点赞8次,收藏10次。1.背景介绍稀疏编码是一种用于处理稀疏数据的编码技术,其主要应用于信息传输、存储和处理等领域。稀疏数据是指数据中大部分元素为零或近似于零的数据,例如文本、图像、音频、视频等。稀疏编码的核心思想是将稀疏数据表示为非零元素和它们对应的位置信息,从而减少存储空间和计算复杂度。稀疏编码的研究起源于1990年代,随着大数据时代的到来,稀疏编码技术的应用范围和影响力不断扩大。目前,稀疏编码已经成为计算...

EasyGBS国标流媒体服务器GB28181国标方案安装使用文档-程序员宅基地

文章浏览阅读217次。EasyGBS - GB28181 国标方案安装使用文档下载安装包下载,正式使用需商业授权, 功能一致在线演示在线API架构图EasySIPCMSSIP 中心信令服务, 单节点, 自带一个 Redis Server, 随 EasySIPCMS 自启动, 不需要手动运行EasySIPSMSSIP 流媒体服务, 根..._easygbs-windows-2.6.0-23042316使用文档

【Web】记录巅峰极客2023 BabyURL题目复现——Jackson原生链_原生jackson 反序列化链子-程序员宅基地

文章浏览阅读1.2k次,点赞27次,收藏7次。2023巅峰极客 BabyURL之前AliyunCTF Bypassit I这题考查了这样一条链子:其实就是Jackson的原生反序列化利用今天复现的这题也是大同小异,一起来整一下。_原生jackson 反序列化链子

一文搞懂SpringCloud,详解干货,做好笔记_spring cloud-程序员宅基地

文章浏览阅读734次,点赞9次,收藏7次。微服务架构简单的说就是将单体应用进一步拆分,拆分成更小的服务,每个服务都是一个可以独立运行的项目。这么多小服务,如何管理他们?(服务治理 注册中心[服务注册 发现 剔除])这么多小服务,他们之间如何通讯?这么多小服务,客户端怎么访问他们?(网关)这么多小服务,一旦出现问题了,应该如何自处理?(容错)这么多小服务,一旦出现问题了,应该如何排错?(链路追踪)对于上面的问题,是任何一个微服务设计者都不能绕过去的,因此大部分的微服务产品都针对每一个问题提供了相应的组件来解决它们。_spring cloud

Js实现图片点击切换与轮播-程序员宅基地

文章浏览阅读5.9k次,点赞6次,收藏20次。Js实现图片点击切换与轮播图片点击切换<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script type="text/ja..._点击图片进行轮播图切换

tensorflow-gpu版本安装教程(过程详细)_tensorflow gpu版本安装-程序员宅基地

文章浏览阅读10w+次,点赞245次,收藏1.5k次。在开始安装前,如果你的电脑装过tensorflow,请先把他们卸载干净,包括依赖的包(tensorflow-estimator、tensorboard、tensorflow、keras-applications、keras-preprocessing),不然后续安装了tensorflow-gpu可能会出现找不到cuda的问题。cuda、cudnn。..._tensorflow gpu版本安装

随便推点

物联网时代 权限滥用漏洞的攻击及防御-程序员宅基地

文章浏览阅读243次。0x00 简介权限滥用漏洞一般归类于逻辑问题,是指服务端功能开放过多或权限限制不严格,导致攻击者可以通过直接或间接调用的方式达到攻击效果。随着物联网时代的到来,这种漏洞已经屡见不鲜,各种漏洞组合利用也是千奇百怪、五花八门,这里总结漏洞是为了更好地应对和预防,如有不妥之处还请业内人士多多指教。0x01 背景2014年4月,在比特币飞涨的时代某网站曾经..._使用物联网漏洞的使用者

Visual Odometry and Depth Calculation--Epipolar Geometry--Direct Method--PnP_normalized plane coordinates-程序员宅基地

文章浏览阅读786次。A. Epipolar geometry and triangulationThe epipolar geometry mainly adopts the feature point method, such as SIFT, SURF and ORB, etc. to obtain the feature points corresponding to two frames of images. As shown in Figure 1, let the first image be ​ and th_normalized plane coordinates

开放信息抽取(OIE)系统(三)-- 第二代开放信息抽取系统(人工规则, rule-based, 先抽取关系)_语义角色增强的关系抽取-程序员宅基地

文章浏览阅读708次,点赞2次,收藏3次。开放信息抽取(OIE)系统(三)-- 第二代开放信息抽取系统(人工规则, rule-based, 先关系再实体)一.第二代开放信息抽取系统背景​ 第一代开放信息抽取系统(Open Information Extraction, OIE, learning-based, 自学习, 先抽取实体)通常抽取大量冗余信息,为了消除这些冗余信息,诞生了第二代开放信息抽取系统。二.第二代开放信息抽取系统历史第二代开放信息抽取系统着眼于解决第一代系统的三大问题: 大量非信息性提取(即省略关键信息的提取)、_语义角色增强的关系抽取

10个顶尖响应式HTML5网页_html欢迎页面-程序员宅基地

文章浏览阅读1.1w次,点赞6次,收藏51次。快速完成网页设计,10个顶尖响应式HTML5网页模板助你一臂之力为了寻找一个优质的网页模板,网页设计师和开发者往往可能会花上大半天的时间。不过幸运的是,现在的网页设计师和开发人员已经开始共享HTML5,Bootstrap和CSS3中的免费网页模板资源。鉴于网站模板的灵活性和强大的功能,现在广大设计师和开发者对html5网站的实际需求日益增长。为了造福大众,Mockplus的小伙伴整理了2018年最..._html欢迎页面

计算机二级 考试科目,2018全国计算机等级考试调整,一、二级都增加了考试科目...-程序员宅基地

文章浏览阅读282次。原标题:2018全国计算机等级考试调整,一、二级都增加了考试科目全国计算机等级考试将于9月15-17日举行。在备考的最后冲刺阶段,小编为大家整理了今年新公布的全国计算机等级考试调整方案,希望对备考的小伙伴有所帮助,快随小编往下看吧!从2018年3月开始,全国计算机等级考试实施2018版考试大纲,并按新体系开考各个考试级别。具体调整内容如下:一、考试级别及科目1.一级新增“网络安全素质教育”科目(代..._计算机二级增报科目什么意思

conan简单使用_apt install conan-程序员宅基地

文章浏览阅读240次。conan简单使用。_apt install conan