zoukankan      html  css  js  c++  java
  • 获取WPF窗体/控件的句柄/当前进程的句柄

    1、在WPF中,获取当前窗体的句柄与WINFORM中不一样:

    WINFORM直接获取:this.Handle----------this是窗体的类名,handle就是句柄。

    2、WPF中先引用命名空间:System.Windows.Interop;

    IntPtr hwnd = new WindowInteropHelper(this).Handle;----this就是要获取句柄的窗体的类名;

    3、控件句柄,同样引用 :System.Windows.Interop:
    IntPtr hwnd = ((HwndSource)PresentationSource.FromVisual(uielement)).Handle;----uielement就是要获取句柄的控件,该控件必须继承自UIElement。

    4、进程模块句柄

    引用 System.Runtime.InteropServices、System.Diagnostics 命名空间

    [DllImport("kernel32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
    public static extern IntPtr GetModuleHandle(string lpModuleName);

    调用获得进程模块的句柄:

     IntPtr hwnd = GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName);

    原文地址:https://www.cnblogs.com/xiesong/p/6676774.html

    System.Runtime.InteropServices

    System.Runtime.IteropServices

  • 相关阅读:
    路径
    JSTL-3
    JSTL-2
    JSTL-1
    EL和JSTL的关系
    Mybatis控制台打印SQL语句的两种方式
    centOS7安装JDK
    centOS7下安装GUI图形界面
    centOS7配置IP地址
    Office2016专业增强版永久激活
  • 原文地址:https://www.cnblogs.com/xiesong/p/6676774.html
Copyright © 2011-2022 走看看