日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

.Net遍历窗口

發布時間:2025/3/20 asp.net 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 .Net遍历窗口 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

'需要導入3個命名空間導入方法為,在文件最前面寫以下內容
'VB.NET code
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Threading

'以下方法測試通過。有效。獲得文本框內容。
'VB.NET code
??? <DllImport("user32.dll", EntryPoint:="FindWindowEx")> _
??? Public Shared Function FindWindowEx(ByVal hWnd1 As IntPtr,_
??? ?ByVal hWnd2 As Integer, ByVal lpsz1 As String, _
??? ?ByVal lpsz2 As String) As Integer
??? End Function
??? <DllImport("User32 ")>
??? Public Shared Function SendMessage(ByVal hWnd As Integer, _
??? ?ByVal Msg As Integer, ByVal wParam As Integer, _
??? ?ByVal lParam As IntPtr) As Boolean
??? End Function

??? Public Const WM_GETTEXT As Integer = &HD
??? Private Shared Sub Test04()
??????? Dim running As Boolean = True
??????? Dim process_array As Process() = Process.GetProcesses()
??????? For Each p As Process In process_array
??????????? If p.MainWindowTitle.IndexOf("記事本") <> -1 Then
??????????????? Dim hEdit As Integer = FindWindowEx(p.MainWindowHandle, 0, "Edit", "")
??????????????? Dim w As String = " "
??????????????? Dim ptr As IntPtr = Marshal.StringToHGlobalAnsi(w)
??????????????? If SendMessage(hEdit, WM_GETTEXT, 100, ptr) Then
??????????????????? MessageBox.Show(Marshal.PtrToStringAnsi(ptr))
??????????????? End If
??????????? End If
??????? Next
??? End Sub


using System.Runtime.InteropServices;
using System.Text;
using System.Threading;

?
[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
public static extern int FindWindowEx(IntPtr hWnd1,
????????????????????????????????????? int hWnd2, string lpsz1,
????????????????????????????????????? string lpsz2);
[DllImport("user32.dll", EntryPoint = "GetWindowText")]
public static extern int GetWindowText(int hwnd, StringBuilder
?????????????????????????????????????? lpString, int cch);
[DllImport("User32 ")]
public static extern bool SendMessage(int hWnd,
????????????????????????????????????? int Msg, int wParam,
????????????????????????????????????? IntPtr lParam);

public const int WM_GETTEXT = 0xD;
private static void Test04()
{
??? bool running = true;
??? new Thread(() =>
??? {
??????? while (running)
??????? {
??????????? Process[] process_array = Process.GetProcesses();
??????????? foreach (Process p in process_array)
??????????? {
??????????????? if (p.MainWindowTitle.IndexOf("記事本") != -1)//找到了
??????????????? {
??????????????????? int hEdit = FindWindowEx(p.MainWindowHandle, 0, "Edit", "");
??????????????????? string w = " ";
??????????????????? IntPtr ptr = Marshal.StringToHGlobalAnsi(w);
??????????????????? if (SendMessage(hEdit, WM_GETTEXT, 100, ptr))

??????????????????????? Console.WriteLine(Marshal.PtrToStringAnsi(ptr));
??????????????? }
??????????? }
??????????? int tick = Environment.TickCount;
??????????? while (running && Environment.TickCount - tick < 10000)
??????????? {
??????????????? Thread.Sleep(10);
??????????? }
??????? }
??????? Console.WriteLine("run over");
??? }).Start();
??? while (Console.ReadLine().ToLower() != "quit") ;
??? running = false;
}

總結

以上是生活随笔為你收集整理的.Net遍历窗口的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。