gpt4 book ai didi

c# - 来自 user32.dll 的 DragDetect (IntPtr, Point) 在单声道中是否等效?

转载 作者:行者123 更新时间:2023-11-30 18:05:56 29 4
gpt4 key购买 nike

有人知道上述 p/invoke 调用的托管代码以将其与单声道一起使用吗?是否有提供与 Windows 上的 user32.dll 类似功能的 linux 库?

最佳答案

我不确定是否有直接等效的 DragDirect 调用 x11\GTK,但您可以使用 Gdk.Pointer.GrabGdk.Pointer 获得相同的功能。 Ungrab 方法。在需要时捕获鼠标指针,然后跟踪鼠标移动并在用户点击 Escape 或释放鼠标或鼠标超出拖动矩形后释放。

下面是一个小例子:

public partial class MainWindow : Gtk.Window
{
public MainWindow () : base(Gtk.WindowType.Toplevel)
{
Build ();
}

protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}

protected virtual void OnWidgetEvent (object o, Gtk.WidgetEventArgs args)
{
if (args.Event is Gdk.EventMotion && args.Event.Type==Gdk.EventType.MotionNotify)
{
Gdk.EventMotion eventMotion = (Gdk.EventMotion)args.Event;
Console.WriteLine("mouse move {0} {1}", eventMotion.X, eventMotion.Y);
}
else if (args.Event is Gdk.EventKey && args.Event.Type==Gdk.EventType.KeyPress)
{
Gdk.EventKey eventKey = (Gdk.EventKey)args.Event;
if (eventKey.Key==Gdk.Key.Escape)
{
Console.WriteLine("mouse pointer ungrab");
Gtk.Grab.Remove(this);
Gdk.Pointer.Ungrab(Gtk.Global.CurrentEventTime);
}
}
}

protected virtual void OnButton1WidgetEvent (object o, Gtk.WidgetEventArgs args)
{
if (args.Event is Gdk.EventButton && args.Event.Type==Gdk.EventType.ButtonPress)
{
Console.WriteLine("mouse pointer grab");
Gdk.Pointer.Grab(this.GdkWindow, true,
Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.PointerMotionMask | Gdk.EventMask.EnterNotifyMask | Gdk.EventMask.LeaveNotifyMask,
null, null, Gtk.Global.CurrentEventTime);
Gtk.Grab.Add (this);
}
}
}

主窗口 UI 声明:

  <widget class="Gtk.Window" id="MainWindow" design-size="400 300">
<property name="MemberName" />
<property name="Title" translatable="yes">MainWindow</property>
<property name="WindowPosition">CenterOnParent</property>
<signal name="DeleteEvent" handler="OnDeleteEvent" />
<signal name="WidgetEvent" handler="OnWidgetEvent" />
<child>
<widget class="Gtk.Fixed" id="fixed1">
<property name="MemberName" />
<property name="HasWindow">False</property>
<child>
<widget class="Gtk.Button" id="button1">
<property name="MemberName" />
<property name="CanFocus">True</property>
<property name="Type">TextOnly</property>
<property name="Label" translatable="yes">GtkButton</property>
<property name="UseUnderline">True</property>
<signal name="WidgetEvent" handler="OnButton1WidgetEvent" />
</widget>
<packing>
<property name="X">165</property>
<property name="Y">125</property>
</packing>
</child>
</widget>
</child>
</widget>

这里有更多关于 GTK 中鼠标指针处理的细节:The Mouse Pointer

希望这对你有帮助,问候

关于c# - 来自 user32.dll 的 DragDetect (IntPtr, Point) 在单声道中是否等效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5069420/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com