티스토리 뷰

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication6
{
    public partial class Form1 : Form
    {
        [DllImport("user32")]
        public static extern IntPtr GetWindow(IntPtr hwnd, int wCmd);
        [DllImport("user32")]
        public static extern bool IsWindowVisible(IntPtr hwnd);
        [DllImport("user32")]
        public static extern int GetWindowTextLength(IntPtr hwnd);
        [DllImport("user32")]
        public static extern int GetWindowText(IntPtr hwnd, StringBuilder lpString, int cch);
        public const int GW_HWNDFIRST = 0;
        public const int GW_HWNDNEXT = 2;
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {

        }
        private void button1_Click(object sender, EventArgs e)
        {
            IntPtr hWnd = GetWindow((IntPtr)this.Handle, GW_HWNDFIRST);
            while (hWnd != IntPtr.Zero)
            {
                int Length = GetWindowTextLength(hWnd);
                if (IsWindowVisible(hWnd) && Length > 0)
                {
                    StringBuilder sb = new StringBuilder(Length+1);
                    GetWindowText(hWnd, sb, sb.Capacity);
                    Console.WriteLine(sb.ToString());
                }
                hWnd = GetWindow(hWnd, GW_HWNDNEXT);
            }
        }
    }
}

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함