代码之家  ›  专栏  ›  技术社区  ›  Adi

在C中获取窗口手柄#

  •  24
  • Adi  · 技术社区  · 17 年前

    我声明了以下类:

    public partial class MainWindow : Window
    

    我该怎么做,应该把查询函数放在哪里。

    到目前为止,我尝试的是:

    IntPtr hwnd = new WindowInteropHelper(this).Handle;
    

    而且,是的,它是通过WPF连接的,谢谢你指出!

    谢谢

    3 回复  |  直到 14 年前
        1
  •  26
  •   SliverNinja - MSFT    13 年前

    OnInitialized 处理 尚未创建。但你正走在正确的道路上。如果你把你的电话放在 Loaded 事件 处理 将已创建,并应返回正确的 处理 .

        2
  •  6
  •   Nir    17 年前

    您最早可以获得句柄的位置是OnSourceInitialized

        3
  •  0
  •   Mez    17 年前
     [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
            public static extern int FindWindowEx(int hwndParent, int hwndEnfant, int lpClasse, string lpTitre);
    
    
    int hwnd = FindWindowEx(0, 0, 0, title);//where title is the windowtitle
    
                    //verification of the window
                    if (hwnd == 0)
                    {
                        throw new Exception("Window not found");
                    }