[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern IntPtr FindWindow(string strclassName, string strWindowName); private void button1_Click(object sender, System.EventArgs e)
{
IntPtr o = FindWindow(null, this.Text);
}
public static extern IntPtr FindWindow(string strclassName, string strWindowName); private void button1_Click(object sender, System.EventArgs e)
{
IntPtr o = FindWindow(null, this.Text);
}
解决方案 »
- 急急急
- winform如何做个登陆后能在服务端xml文件中记录用户登陆信息的?(在客户端中打开后在服务端记录信息以便查看)这个怎么做?
- 如何截取以换行符(转行符)作为划分的字符串?
- socket接收数据一定要写在一个死循环里吗?这样占用CPU太高了.有不有其他的什么方法?
- C#中如何打印对话框(上面有一个list,和一个button)
- dataset 增加数据问题?
- 如何用jQuery改变页面显示效果
- Console.WriteLine();装箱问题
- 请各位帮帮出主意,在线等
- button空间没有"鼠标双击"这个事件?
- Hashtable ClassMaps{get;} 这句什么意思??
- 能不能用程序自动找到windows运行的某个程序,并向这个程序发送一些键盘事件。
看看这个!
=================================
怎么知道我的程序已经找到了 这个记事本窗口了呢?
=====================================================
if(oo==null)运算符“==”无法应用于“System.IntPtr”和“<null>”类型的操作数
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); //Open Up blank Notepad First !
string lpszParentClass = "Notepad";
string lpszParentWindow = "Untitled - Notepad";
string lpszClass = "Edit";
IntPtr ParenthWnd = new IntPtr(0);
IntPtr hWnd = new IntPtr(0);
ParenthWnd = FindWindow(lpszParentClass,lpszParentWindow);
if (ParenthWnd.Equals(IntPtr.Zero))
Console.WriteLine("Notepad Not Running");
else
{
hWnd = FindWindowEx(ParenthWnd,hWnd,lpszClass,"");
if (hWnd.Equals(IntPtr.Zero))
Console.WriteLine("What the F??? Notepad doesn't have an edit component ?");
else
{
Console.WriteLine("Notepad Window: " + ParenthWnd.ToString());
Console.WriteLine("Edit Control: " + hWnd.ToString());
}
}
string lpszParentWindow = "Untitled - Notepad";中文斑的是:string lpszParentWindow = "无标题 - 记事本";测试前先开一个空的记事本!!!
比如SendMessage, SetWindowText, GetWindowText, DestroyWindow, SetWindowExt, SetWindowPos等等有好.
声明:
[DllImport("user32.dll", EntryPoint="FindWindow")]
public static extern int FindWindow (
string lpClassName,
string lpWindowName
);
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); //Open Up blank Notepad First !
string lpszParentClass = "Notepad";
string lpszParentWindow = "Untitled - Notepad";
string lpszClass = "Edit";
IntPtr ParenthWnd = new IntPtr(0);
IntPtr hWnd = new IntPtr(0);
ParenthWnd = FindWindow(lpszParentClass,lpszParentWindow);
if (ParenthWnd.Equals(IntPtr.Zero))
Console.WriteLine("Notepad Not Running");
else
{
hWnd = FindWindowEx(ParenthWnd,hWnd,lpszClass,"");
if (hWnd.Equals(IntPtr.Zero))
Console.WriteLine("What the F??? Notepad doesn't have an edit component ?");
else
{
Console.WriteLine("Notepad Window: " + ParenthWnd.ToString());
Console.WriteLine("Edit Control: " + hWnd.ToString());
}
}
是我想要的答案。但是上面的程序需要事先 声明FindWindowEx函数。
谢谢 BearRui(我有点笨,但我很特别,所以我特别笨!) 。。
-----------------------------------------------
在C#中使用任何API都是要先声明,不然无法使用。