【C#】我通过一个Process对象开启了一个系统计算器窗口

来源:百度知道 编辑:UC知道 时间:2024/05/29 04:07:23
我现在想调用SendMessage API直接发送消息给这个计算器窗口,我怎么样才可以拿到窗口句柄啊?
如果有人能给出全部代码最好不过了

查找窗口:
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using Microsoft.Win32;

namespace xqwg
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern int FindWindow(
string lpClassName,
string lpWindowName
);

private void button1_Click(object sender, EventArgs e)
{

int k = FindWindow(null,"计算器");
MessageBox.Show(k.ToString());
//K为窗口句柄