使用发布/发送消息拖放 [英] Drag and drop using post/sendmessage

查看:66
本文介绍了使用发布/发送消息拖放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我试图找到一种使用API​​函数SendMessage()或PostMessage()进行拖放的方法,但我使用的是以下代码,但无法正常工作:

Hi All,

I am trying to find a way to preform drag and drop using API function SendMessage() or PostMessage(), I am using the following code but its not working:

 API.Click(controlHandleStart, false, (ushort)RelativePointStart.X, (ushort)RelativePointStart.Y);//mouse down

 System.Threading.Thread.Sleep(200);

API.Click(controlHandleEnd, true, (ushort)RelativePointEnd.X, (ushort)RelativePointEnd.Y);//mouse up


基本上,我想做的是在Outlook中对电子邮件执行拖放操作,我想将电子邮件拖放到文件夹中,但是我需要使用post/sendmessage.

我只是将鼠标向下拖动到拖动位置,然后再将鼠标向上拖动到放置位置,所以找不到发送鼠标移动消息的方法.

任何人都可以帮忙.


Basically what I am trying to do is to preform a drag and drop for an email in outlook I want to drag an email and drop it into a folder but I need to use post/sendmessage.

I just sending the mouse down on the drag location and then I send the mouse up on the drop location, I am not able to find way to send the mouse move message.

Can anyone help please.

推荐答案

在这种情况下,您不应使用PInvoke访问本机Windows API.
System.Windows.Forms和WPF都将药物和药丸作为所有控件和容器控件的标准功能来提供.在两个系统中,这都很容易.请搜索MS帮助-样本和帮助就足够了.

同样,您的代码可能无法工作,因为它基于一些立即常量,该常量定义了200毫秒的睡眠时间.这个价值没有道理,没有动机.基于某些任意延迟,任何事情都可能无法正常工作.如果您的功能需要一定的延迟,则会创建竞赛条件,如果不是这样-除了性能下降之外,这没有任何意义-在任何情况下都永远无法工作.

有关System.Windows.Forms的正确解决方案,请阅读 Windows窗体中的拖放功能] .

对于WPF,请阅读
http://msdn.microsoft.com/en-us/library/ms742859.aspx> ; [拖放概述] .

对于CodeProject答案"中的简短答案来说,这是太多的知识,但是从本质上讲,基本技术很容易实现.

谢谢.
You should not use PInvoke to accesss native Windows API in this case.
Both System.Windows.Forms and WPF provide drug and drop as a standard feature of all controls and container controls. In both systems this is easy enough. Please search MS Help -- the samples and help are good enough.

Also, you code cannot possibly work because it is based on some immediate constant defining sleep time of 200 milliseconds. This value makes no sense, no motivation. Nothing can possibly work based on some arbitrary delay. If your functionality depends on some delay it creates race condition, if not -- it makes no sense except performance degradation -- will never work in any case.

For correct solution for System.Windows.Forms, please read Drag-and-Drop Functionality in Windows Forms].

For WPF, please read http://msdn.microsoft.com/en-us/library/ms742859.aspx>[Drag and Drop Overview].

This is too much knowledge for a short answer in CodeProject "answers", but in essence the basic techniques are easy enough to implement.

Thank you.


这篇关于使用发布/发送消息拖放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆