C# 调用API问题.
发布网友
发布时间:2024-09-29 04:05
我来回答
共2个回答
热心网友
时间:2024-09-30 00:01
using System;
using System.Runtime.InteropServices;//这里应该是这个命名空间,你在VS里面看看提示
[DllImport("user32.dll", EntryPoint = "FindWindow")]//这里是从user32里面导入FindWindow函数,下同
public static extern IntPtr FindWindow(string IpClassName, string IpWindowName);
[DllImport("user32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
//比如下面是你的main函数体
//直接调用那个函数就好了
class Program
{
public static void Main(string[] args)
{
IntPtr hwnd = FindWindow(0,"要找的程序窗口");
SendMessage(...);//同样的
}
}
//其实和用普通的函数一样的
热心网友
时间:2024-09-30 00:01
[DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern IntPtr FindWindow(string IpClassName, string IpWindowName);
[DllImport("User32.dll", EntryPoint = "SendMessage")]//用于发送信息给窗体
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);