tangrf
路人甲
路人甲
  • 注册日期2004-04-10
  • 发帖数45
  • QQ
  • 铜币285枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1923回复:1

关于在AE的TOC控件中拖动图层时TOC闪动的问题

楼主#
更多 发布于:2006-06-09 15:25
<P>在本版上看到有用VB(或VB.NET)实现的在AE的TOC控件中拖动图层功能,我改成C#(.net2003)的,出现的问题是:在拖动一个图层之后,TOC刷新之后,带来的闪动,让人感觉很不舒服。VB.NET版的哪个,用到了SendMessage(...)这个函数,但在C#里面,这个函数是受保护的,不让访问;那么该如何控制TOC的刷新的,实现象在ARCMAP里面拖动图层一样的功能呢??请给予指导,谢谢。</P>
喜欢0 评分0
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
1楼#
发布于:2006-06-09 15:35
<P>在C#中使用SendMessage </P>
<P>主要描述在调用API函数SendMessage时数据类型的转换。 <BR><BR>-------------------------------------------------------------------------------- <BR><BR>SendMessage是一个在user32.dll中声明的API函数,在C#中导入如下: <BR><BR>using System.Runtime.InteropServices; <BR>[DllImport("user32.dll", EntryPoint="SendMessageA")] <BR>public static extern int SendMessage (IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam); <BR>本文描述其参数 lParam 的用法,主要是数据类型之间的转化。 <BR><BR>● 一种最简单的处理方式是声明多个SendMessage函数(overload),用所需的数据类型直接替换IntPtr。例如: <BR><BR>//声明: <BR>[DllImport("user32.dll", EntryPoint="SendMessageA")] <BR>private static extern int SendMessage (IntPtr hwnd, int wMsg, IntPtr wParam, string lParam); <BR>[DllImport("user32.dll", EntryPoint="SendMessageA")] <BR>private static extern int SendMessage (IntPtr hwnd, int wMsg, IntPtr wParam, ref Rectangle lParam); <BR>//调用: <BR>string s = "hello, floodzhu"; <BR>SendMessage(this.textBox1.Handle, WM_SETTEXT, IntPtr.Zero, s); <BR><BR>Rectangle rect = new Rectangle(); <BR>SendMessage(this.richTextBox1.Handle, EM_GETRECT, (IntPtr)0, ref rect); <BR>● 对要求返回字符串的类型(out string)可以用 StringBuilder 代替,此时不需要 out/ref。例如: <BR><BR>[DllImport("user32.dll", EntryPoint="SendMessageA")] <BR>private static extern int SendMessage (IntPtr hwnd, int wMsg, int wParam, StringBuilder lParam); <BR>private void button1_Click(object sender, System.EventArgs e) <BR>{ <BR>const int buffer_size = 1024; <BR>StringBuilder buffer = new StringBuilder(buffer_size); <BR>SendMessage(this.textBox1.Handle, WM_GETTEXT, buffer_size, buffer); <BR>//MessageBox.Show(buffer.ToString()); <BR>} <BR>● 如果想用 InPtr 类型统一处理的话,可以借助于 Marshal 或者 GCHandle 的相关方法。例如: <BR><BR>[DllImport("user32.dll", EntryPoint="SendMessageA")] <BR>private static extern int SendMessage (IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam); <BR><BR>private void button2_Click(object sender, System.EventArgs e) <BR>{ <BR>Rectangle rect = new Rectangle(); <BR>IntPtr buffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Rectangle))); <BR>Marshal.StructureToPtr(rect, buffer ,true); <BR><BR>SendMessage(this.richTextBox1.Handle, EM_GETRECT, (IntPtr)0, buffer); <BR><BR>rect = (Rectangle)Marshal.PtrToStructure(buffer, typeof(Rectangle)); <BR><BR>Marshal.FreeHGlobal(buffer); <BR>} <BR>或者 <BR><BR>private void button2_Click(object sender, System.EventArgs e) <BR>{ <BR>Rectangle rect = new Rectangle(); <BR>GCHandle gch = GCHandle.Alloc(rect); <BR><BR>SendMessage(this.richTextBox1.Handle, EM_GETRECT, (IntPtr)0, (IntPtr)gch); <BR>rect = (Rectangle)Marshal.PtrToStructure((IntPtr)gch, typeof(Rectangle)); <BR><BR>gch.Free(); <BR>} <BR></P>
举报 回复(0) 喜欢(0)     评分
游客

返回顶部