user32.dll 中的 DragDetect (IntPtr, Point) 相当于单声道吗?

发布于 2024-10-18 05:23:32 字数 90 浏览 3 评论 0原文

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

Does anybody know managed code for the mentioned p/invoke call to use it with mono?
Is there a linux lib that provides similar functionality as the user32.dll on windows does?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走野 2024-10-25 05:23:32

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

下面是一个小例子:

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);
        }
    }
}

MainWindow 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 中鼠标指针处理的更多详细信息,请参见:鼠标指针

希望这有帮助,问候

I'm not sure if there is a direct equivalent for DragDirect call for x11\GTK, but you can have the same functionality with Gdk.Pointer.Grab and Gdk.Pointer.Ungrab methods. Capture the mouse pointer whenever you need then track mouse movement and release once user hits Escape or releases the mouse or mouse is out of the drag rectangle.

Below is a small example:

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);
        }
    }
}

MainWindow UI declaration:

  <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>

more details on mouse pointer handling in GTK here: The Mouse Pointer

hope this helps, regards

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文