简体   繁体   English

如何将消息框中的句柄信息值(或字符串)添加到 C# 的列表框中?

[英]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.

相关问题 我可以在C#MessageBox中添加控件吗? - Can I add controls to the C# MessageBox? 如何在 c# 中将值添加到组合框中? - How do I add values to a combo box from this in c#? 将消息框列表添加到C#中的资源文件中 - Add the list of messagebox to a resource file in c# C#字典如何从带有单个键的重复值的分隔字符串列表中添加数据到字典 - c# dictionary how to add data from a delimited list of strings with repeated values for a single keyinto a dictionary 如何将列表框中的项的值添加到C#中的局部变量中? - How can I add the value of an item in a list box to a local variable in C#? 如何在C#的列表框中为项目分配值? - How do I assign values to items in the list box in c#? 如何在 C# 代码的消息框中使字符串变量的字体颜色变为红色? - how can i make a string variable's font colour red in a messagebox from c# code? C#如何将字符串添加到列表,以便可以从DataSource访问它们 - c# how to add strings to a list so that they will be accessible from DataSource 我如何在 c# 列表中搜索其信息之一? - How can i search in c# list with one of its information? 如何将表示C#枚举值的字符串国际化? - How can I internationalize strings representing C# enum values?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM