c# 怎么得到窗口中控件的句柄
c# 如何得到窗口中控件的句柄
[img=http://][/img]我本人是搞C++的,C#的有些不太熟,
下面是一个简单的对话框的XAML,里面有个canvas和button1变量,我想得到这两个的句柄(HWND)
类的代码如下,
[img=http://][/img]我本人是搞C++的,C#的有些不太熟,
下面是一个简单的对话框的XAML,里面有个canvas和button1变量,我想得到这两个的句柄(HWND)
<Window x:Class="Traffic.AP.FocusSet"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="调焦设置" FontSize="16" Height="500" Width="500" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize" Closing="Window_Closing" Loaded="Window_Loaded">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="370*" />
<RowDefinition Height="91*" />
</Grid.RowDefinitions>
<Canvas Name="canvas" Grid.Row="0">
</Canvas>
<Button Content="抓拍" Grid.Row="1" Height="28" HorizontalAlignment="Left" Margin="147,22,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
</Grid>
</Window>
类的代码如下,
namespace Traffic.AP
{
/// <summary>
/// Interaction logic for FocusSet.xaml
/// </summary>
public partial class FocusSet : Window
{
public FocusSet(delegateRecordFocus recordFocus,delegateGrabImg grabImg)
{
InitializeComponent();
this.m_recordFocus = recordFocus;
this.m_grabImg = grabImg;
}
public delegate void delegateRecordFocus(IntPtr hWndScreen, string tempDir, bool bStop);
private delegateRecordFocus m_recordFocus;
public delegate void delegateGrabImg();
private delegateGrabImg m_grabImg;
private void button1_Click(object sender, RoutedEventArgs e)
{
m_grabImg();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//var helper = new System.Windows.Interop.WindowInteropHelper(this);
//IntPtr hWnd = helper.Handle;
// 这里想获取canvs和button1的变量,不知道怎么获取,求指点