首页 > 其他分享 >AutoCAD 剪贴板格式的 .net 声明

AutoCAD 剪贴板格式的 .net 声明

时间:2022-09-23 09:13:05浏览次数:41  
标签:IntPtr 剪贴板 AutoCAD string int static NativeMethods net public

结构体声明

[StructLayout(LayoutKind.Sequential)] struct Rect { public int left; public int top; public int right; public int bottom; }; [StructLayout(LayoutKind.Sequential, Pack=8)] struct Point3D { public double x; public double y; public double z; }; [StructLayout(LayoutKind.Sequential, Pack=8, CharSet = CharSet.Unicode)] struct ClipboardInfo { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string szTempFile; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string szSourceFile; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)] public string szSignature; public int nFlags; public Point3D dptInsert; public Rect rectGDI; public IntPtr mpView; public int dwThreadId; public int nLen; public int nType; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)] public string chData; };

  class NativeMethods
  {
    [DllImport("user32.dll")]
    public static extern bool OpenClipboard(IntPtr hWndNewOwner);
    [DllImport("user32.dll")]
    public static extern bool CloseClipboard();
    [DllImport("user32.dll")]
    public static extern IntPtr GetClipboardData(uint uFormat);
    [DllImport("user32.dll")]
    public static extern uint RegisterClipboardFormat(string lpszFormat);
    [DllImport("kernel32.dll")]
    public static extern IntPtr GlobalLock(IntPtr hMem);
    [DllImport("kernel32.dll")]
    public static extern bool GlobalUnlock(IntPtr hMem);
  };

 


使用:
    static void showClipboard(StringBuilder sb)
    {
    	uint cf = NativeMethods.RegisterClipboardFormat("AutoCAD.r22");
			if (NativeMethods.OpenClipboard(IntPtr.Zero)) {
			  IntPtr data = NativeMethods.GetClipboardData(cf);
			  IntPtr ptr = NativeMethods.GlobalLock(data);
			  ClipboardInfo ci = (ClipboardInfo)Marshal.PtrToStructure(ptr,
			    typeof(ClipboardInfo));
			  sb.AppendLine();
			  sb.AppendLine(string.Format("szTempFile={0}", ci.szTempFile));
			  sb.AppendLine(string.Format("dptInsert: {0}, {1}, {2}", ci.dptInsert.x, ci.dptInsert.y, ci.dptInsert.z));
			  NativeMethods.GlobalUnlock(data);
			  NativeMethods.CloseClipboard();
		  }
		}

 

 

标签:IntPtr,剪贴板,AutoCAD,string,int,static,NativeMethods,net,public
From: https://www.cnblogs.com/Exaybachay/p/16721519.html

相关文章

  • .NET Core Web APi类库如何内嵌运行?
    话题我们知道在.NETFramework中可以嵌入运行WebAPi,那么在.NETCore(.NET6+称之为.NET)中如何内嵌运行WebApi呢,在实际项目中这种场景非常常见,那么我们本节以.NET6.0作为......
  • .NET 部署Https(SSL)通过代码方式
    在上一个文章中,传送门,给大家介绍了怎么在配置文件中使用 Kestrel部署Https,正好今天有小伙伴稳问到:可以通过代码的方式实现 Kestrel的Https的部署吗?答案是肯定的......
  • 【2022】【Reinforcement learning in urban network traffic signal control: A syst
    本篇综述主要介绍两个或多个路口路网的基于强化学习的交通信号灯控制,覆盖了1994年至2022年来自20个国家的160多篇文章。具体内容有:AreviewonReinforcementLearning......
  • Linux下.NET Core进程守护设置,解决SSH关闭后.NET Core服务无法访问的问题
    Linux下.NETCore进程守护设置,解决SSH关闭后.NETCore服务无法访问的问题 通过dotnet命令启动的程序,会在控制台关闭时结束进程,因此需要设置守护进程。这样可以让应用程......
  • 聊聊asp.net core 授权流程
    在上一篇聊聊asp.netcore认证和授权中我们提到了认证和授权的基本概念,以及认证和授权的关系及他们之间的协同工作流程,在这篇文章中,我将通过分析asp.netcore3.1授权......
  • Netty 的应用场景
    ●Netty的应用场景互联网行业1)互联网行业:在分布式系统中,各个节点之间需要远程服务调用,高性能的RPC框架必不可少,Netty作为异步高性能的通信框架,往往作为基础通信组件被......
  • 无法从命令行或调试器启动服务,必须首先安装Windows服务(使用installutil.exe),然后用S
    window服务调试报错:无法从命令行或调试器启动服务,必须首先安装Windows服务(使用installutil.exe),然后用ServerExplorer、Windows服务器管理工具或NETSTART命令启动它 ......
  • 【asp.net】background属性
    一、更改元素背景色可以为所有元素设置背景色,这包括body一直到em和a等行内元素。1、元素背景色p{background-color:gray;}2、背景色从元素中的文本向外延伸......
  • asp.net core Razor Page 分页
    1.使用Nuget下载LazZiya.TagHelpers2._ViewImports.cshtml中添加@addTagHelper*,LazZiya.TagHelpers3.前台页面使用<tableclass="tabletable-bordered">......
  • 将微服务容器部署到 Kubernetes
    将Docker映像推送到DockerHub,使映像可供Kubernetes实例下载,然后创建了部署文件,以声明方式描述了Kubernetes应对每个微服务执行的操作。你还了解到,使用Kubernetes......