zoukankan      html  css  js  c++  java
  • 怎样获得.net控件的windows句柄(PPC)

    问题:怎样获得.net控件的windows句柄
           我们想调用windows API函数并且需要获得控件的句柄。怎样才能获得.net控件的windows句柄呢?

    解决办法:

         有一个简单的获得控件的句柄的窍门。你将窗体设置为鼠标可捕获,那么你的窗口句柄可以通过使用Windows API捕获。 这个想法在以下的GetHWnd函数中实现:

    class WinAPI
    {
      [DllImport("coredll.dll")]
      private static extern IntPtr SetCapture(IntPtr hWnd);

      [DllImport("coredll.dll")]
      private static extern IntPtr GetCapture();

      public static IntPtr GetHWnd(Control ctrl)
      {
        IntPtr hOldWnd = GetCapture();

        ctrl.Capture = true;

        IntPtr hWnd = GetCapture();

        ctrl.Capture = false;

        SetCapture(hOldWnd);

        return hWnd;
      }
    }


    这是GetHWnd函数的简单用法:

      IntPtr hWndButton = WinAPI.GetHWnd(button1);

  • 相关阅读:
    A bon chat, bon rat
    获取信息mysql
    Lua笔记3 表达式
    libevent2编译
    opencv环境搭建
    bash console
    Unix Notes.
    ubuntu vsftpd
    axis2客户端代码生成
    IDEA 快捷键
  • 原文地址:https://www.cnblogs.com/kkenn/p/1665755.html
Copyright © 2011-2022 走看看