[英]How can I add information values(or strings)of handle from Messagebox to List box in C#?
my program follows;我的程序如下;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
namespace WindowsFormsApplication9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
abc();
}
[DllImport("user32.dll", SetLastError = true)]static extern IntPtr
FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]public static extern int
EnumChildWindows(IntPtr hwnd, EnumChildCallback Proc, int lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
public delegate bool EnumChildCallback(IntPtr hwnd, ref IntPtr lParam);
public static void abc ()
{
IntPtr pHndl = FindWindow("notepad", null);
EnumChildWindows(pHndl, EnumChildProc, 0);
}
public static bool EnumChildProc(IntPtr hwndChild, ref IntPtr lParam)
{
try
{
const int nChar = 256;
StringBuilder ss = new StringBuilder(nChar);
string veri = "Handle: " + hwndChild.ToString() + "::" + GetWindowText(FindWindow("notepad", null), ss, 256);
MessageBox.Show(veri);
}
catch (Exception ex)
{
MessageBox.Show("Hata Olustu: " + ex.Message);
}
return true;
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
Are you looking for this line of code?你在找这行代码吗?
//MessageBox.Show(veri);
listBox1.Items.Add(veri);
[Edit] More info: [编辑] 更多信息:
IntPtr WindowHandle = FindWindow("WordPadClass", null);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.